@Override public PatchResult applyPatch(PatchData patchData){
  String typeName=patchData.getTypeName();
  String applyVersion=patchData.getApplyToVersion();
  TypesDef updatedTypeDef;
  PatchResult result;
  try {
    if (checkIfTypeExists(typeName,metadataService)) {
      TypesDef typesDef=getTypeDef(typeName);
      String currentVersion=getTypeVersion(typeName);
      if (currentVersion == null || currentVersion.equalsIgnoreCase(applyVersion) || currentVersion.startsWith(applyVersion + ".")) {
        updatedTypeDef=updateTypesDef(typesDef,patchData);
        if (updatedTypeDef != null) {
          metadataService.updateType(TypesSerialization.toJson(updatedTypeDef));
          LOG.info("updated " + patchData.getTypeName() + " type from version "+ patchData.getApplyToVersion()+ " to "+ patchData.getUpdateToVersion());
          result=new PatchResult("patch applied successfully!",PatchStatus.SUCCESS);
        }
 else {
          LOG.error("failed to create updated typedef for type=" + typeName + "; applyToVersion="+ applyVersion+ "; updateToVersion="+ patchData.getUpdateToVersion());
          result=new PatchResult("patch failed!",PatchStatus.FAILED);
        }
      }
 else {
        LOG.info("patch skipped for " + patchData.getTypeName());
        result=new PatchResult("patch skipped!",PatchStatus.SKIPPED);
      }
    }
 else {
      LOG.error("failed to apply patch (typeName=" + typeName + "; applyToVersion="+ applyVersion+ "; updateToVersion="+ patchData.getUpdateToVersion()+ "): type doesn't exist");
      result=new PatchResult("patch failed!",PatchStatus.FAILED);
    }
  }
 catch (  AtlasException e) {
    LOG.error("error in updating type for " + patchData.getTypeName());
    result=new PatchResult("unable to update type",PatchStatus.FAILED);
  }
catch (  JSONException e) {
    LOG.error("error in updating typedef for  " + patchData.getTypeName());
    result=new PatchResult("unable to update typedef",PatchStatus.FAILED);
  }
  return result;
}

@ Override public PatchResult applyPatch ( PatchData patchData ) { String typeName = patchData . getTypeName ( ) ; String applyVersion = patchData . getApplyToVersion ( ) ; TypesDef updatedTypeDef ; PatchResult result ; try { if ( checkIfTypeExists ( typeName , metadataService ) ) { TypesDef typesDef = getTypeDef ( typeName ) ; String currentVersion = getTypeVersion ( typeName ) ; if ( currentVersion == null || currentVersion . equalsIgnoreCase ( applyVersion ) || currentVersion . startsWith ( applyVersion + "." ) ) { updatedTypeDef = updateTypesDef ( typesDef , patchData ) ; if ( updatedTypeDef != null ) { metadataService . updateType ( TypesSerialization . toJson ( updatedTypeDef ) ) ; LOG . info ( "updated " + patchData . getTypeName ( ) + " type from version " + patchData . getApplyToVersion ( ) + " to " + patchData . getUpdateToVersion ( ) ) ; result = new PatchResult ( "patch applied successfully!" , PatchStatus . SUCCESS ) ; } else { LOG . error ( "failed to create updated typedef for type=" + typeName + "; applyToVersion=" + applyVersion + "; updateToVersion=" + patchData . getUpdateToVersion ( ) ) ; result = new PatchResult ( "patch failed!" , PatchStatus . FAILED ) ; } } else { LOG . info ( "patch skipped for " + patchData . getTypeName ( ) ) ; result = new PatchResult ( "patch skipped!" , PatchStatus . SKIPPED ) ; } } else { LOG . error ( "failed to apply patch (typeName=" + typeName + "; applyToVersion=" + applyVersion + "; updateToVersion=" + patchData . getUpdateToVersion ( ) + "): type doesn't exist" ) ; result = new PatchResult ( "patch failed!" , PatchStatus . FAILED ) ; } } catch ( AtlasException e ) { LOG . error ( "error in updating type for " + patchData . getTypeName ( ) ) ; result = new PatchResult ( "unable to update type" , PatchStatus . FAILED ) ; } catch ( JSONException e ) { LOG . error ( "error in updating typedef for  " + patchData . getTypeName ( ) ) ; result = new PatchResult ( "unable to update typedef" , PatchStatus . FAILED ) ; } return result ; }
sample patch data { " patches " : [ { " action " : " add_attribute " , " typename " : " hive_column " , " applytoversion " : " 1 . 0 " , " updatetoversion " : " 2 . 0 " , " params " : { " optionalparam1 " : " true " , " optionalparam2 " : " false " } , " attributedefinitions " : [ { " name " : " position " , " datatypename " : " string " , " multiplicity " : " optional " , " iscomposite " : false , " isunique " : false , " isindexable " : false , " reverseattributename " : null } ] } ] }
