Repository: atlas
Updated Branches:
  refs/heads/master 8129bade5 -> 36656ea75


http://git-wip-us.apache.org/repos/asf/atlas/blob/36656ea7/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
index e2b33bd..25dd81d 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
@@ -40,6 +40,7 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
 import org.apache.atlas.store.AtlasTypeDefStore;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
+import org.apache.atlas.type.AtlasTypeUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.configuration.Configuration;
@@ -404,8 +405,9 @@ public class AtlasTypeDefStoreInitializer implements 
ActiveStateChangeHandler {
 
             PatchHandler[] patchHandlers = new PatchHandler[] {
                     new AddAttributePatchHandler(atlasTypeDefStore, 
atlasTypeRegistry),
+                    new UpdateAttributePatchHandler(atlasTypeDefStore, 
atlasTypeRegistry),
                     new UpdateTypeDefOptionsPatchHandler(atlasTypeDefStore, 
atlasTypeRegistry),
-                    new UpdateAttributePatchHandler(atlasTypeDefStore, 
atlasTypeRegistry)
+                    new SetServiceTypePatchHandler(atlasTypeDefStore, 
atlasTypeRegistry)
             };
 
             Map<String, PatchHandler> patchHandlerRegistry = new HashMap<>();
@@ -471,6 +473,7 @@ public class AtlasTypeDefStoreInitializer implements 
ActiveStateChangeHandler {
         private Map<String, Object>     params;
         private List<AtlasAttributeDef> attributeDefs;
         private Map<String, String>     typeDefOptions;
+        private String                  serviceType;
 
         public String getAction() {
             return action;
@@ -527,6 +530,14 @@ public class AtlasTypeDefStoreInitializer implements 
ActiveStateChangeHandler {
         public void setTypeDefOptions(Map<String, String> typeDefOptions) {
             this.typeDefOptions = typeDefOptions;
         }
+
+        public String getServiceType() {
+            return serviceType;
+        }
+
+        public void setServiceType(String serviceType) {
+            this.serviceType = serviceType;
+        }
     }
 
     /**
@@ -709,57 +720,43 @@ public class AtlasTypeDefStoreInitializer implements 
ActiveStateChangeHandler {
             }
 
             if (isPatchApplicable(patch, typeDef)) {
-                if (typeDef.getClass().equals(AtlasEntityDef.class)) {
-                    AtlasEntityDef updatedDef = new 
AtlasEntityDef((AtlasEntityDef)typeDef);
-
-                    if (updatedDef.getOptions() == null) {
-                        updatedDef.setOptions(patch.getTypeDefOptions());
-                    } else {
-                        
updatedDef.getOptions().putAll(patch.getTypeDefOptions());
-                    }
-                    updatedDef.setTypeVersion(patch.getUpdateToVersion());
-
-                    typeDefStore.updateEntityDefByName(typeName, updatedDef);
-                } else if 
(typeDef.getClass().equals(AtlasClassificationDef.class)) {
-                    AtlasClassificationDef updatedDef = new 
AtlasClassificationDef((AtlasClassificationDef)typeDef);
+                if (typeDef.getOptions() == null) {
+                    typeDef.setOptions(patch.getTypeDefOptions());
+                } else {
+                    typeDef.getOptions().putAll(patch.getTypeDefOptions());
+                }
+                typeDef.setTypeVersion(patch.getUpdateToVersion());
 
-                    if (updatedDef.getOptions() == null) {
-                        updatedDef.setOptions(patch.getTypeDefOptions());
-                    } else {
-                        
updatedDef.getOptions().putAll(patch.getTypeDefOptions());
-                    }
-                    updatedDef.setTypeVersion(patch.getUpdateToVersion());
+                
typeDefStore.updateTypesDef(AtlasTypeUtil.getTypesDef(typeDef));
+            } else {
+                LOG.info("patch skipped: typeName={}; applyToVersion={}; 
updateToVersion={}",
+                         patch.getTypeName(), patch.getApplyToVersion(), 
patch.getUpdateToVersion());
+            }
+        }
+    }
 
-                    typeDefStore.updateClassificationDefByName(typeName, 
updatedDef);
-                } else if (typeDef.getClass().equals(AtlasStructDef.class)) {
-                    AtlasStructDef updatedDef = new 
AtlasStructDef((AtlasStructDef)typeDef);
+    class SetServiceTypePatchHandler extends PatchHandler {
+        public SetServiceTypePatchHandler(AtlasTypeDefStore typeDefStore, 
AtlasTypeRegistry typeRegistry) {
+            super(typeDefStore, typeRegistry, new String[] { 
"SET_SERVICE_TYPE" });
+        }
 
-                    if (updatedDef.getOptions() == null) {
-                        updatedDef.setOptions(patch.getTypeDefOptions());
-                    } else {
-                        
updatedDef.getOptions().putAll(patch.getTypeDefOptions());
-                    }
-                    updatedDef.setTypeVersion(patch.getUpdateToVersion());
+        @Override
+        public void applyPatch(TypeDefPatch patch) throws AtlasBaseException {
+            String           typeName = patch.getTypeName();
+            AtlasBaseTypeDef typeDef  = 
typeRegistry.getTypeDefByName(typeName);
 
-                    typeDefStore.updateStructDefByName(typeName, updatedDef);
-                } else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
-                    AtlasEnumDef updatedDef = new 
AtlasEnumDef((AtlasEnumDef)typeDef);
+            if (typeDef == null) {
+                throw new 
AtlasBaseException(AtlasErrorCode.PATCH_FOR_UNKNOWN_TYPE, patch.getAction(), 
typeName);
+            }
 
-                    if (updatedDef.getOptions() == null) {
-                        updatedDef.setOptions(patch.getTypeDefOptions());
-                    } else {
-                        
updatedDef.getOptions().putAll(patch.getTypeDefOptions());
-                    }
-                    updatedDef.setTypeVersion(patch.getUpdateToVersion());
+            if (isPatchApplicable(patch, typeDef)) {
+                typeDef.setServiceType(patch.getServiceType());
+                typeDef.setTypeVersion(patch.getUpdateToVersion());
 
-                    typeDefStore.updateEnumDefByName(typeName, updatedDef);
-                } else {
-                    throw new 
AtlasBaseException(AtlasErrorCode.PATCH_NOT_APPLICABLE_FOR_TYPE,
-                                                 patch.getAction(), 
typeDef.getClass().getSimpleName());
-                }
+                
typeDefStore.updateTypesDef(AtlasTypeUtil.getTypesDef(typeDef));
             } else {
                 LOG.info("patch skipped: typeName={}; applyToVersion={}; 
updateToVersion={}",
-                         patch.getTypeName(), patch.getApplyToVersion(), 
patch.getUpdateToVersion());
+                        patch.getTypeName(), patch.getApplyToVersion(), 
patch.getUpdateToVersion());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/atlas/blob/36656ea7/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
index 3421331..418ce49 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasTypeDefGraphStoreV2.java
@@ -184,6 +184,7 @@ public class AtlasTypeDefGraphStoreV2 extends 
AtlasTypeDefGraphStore {
         ret.setProperty(Constants.TYPENAME_PROPERTY_KEY, typeDef.getName());
         ret.setProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY,
                 StringUtils.isNotBlank(typeDef.getDescription()) ? 
typeDef.getDescription() : typeDef.getName());
+        ret.setProperty(Constants.TYPESERVICETYPE_PROPERTY_KEY, 
typeDef.getServiceType());
         ret.setProperty(Constants.TYPEVERSION_PROPERTY_KEY, 
typeDef.getTypeVersion());
         ret.setProperty(Constants.GUID_PROPERTY_KEY, typeDef.getGuid());
         ret.setProperty(Constants.CREATED_BY_KEY, getCurrentUser());
@@ -214,6 +215,10 @@ public class AtlasTypeDefGraphStoreV2 extends 
AtlasTypeDefGraphStore {
         updateVertexProperty(vertex, Constants.TYPEVERSION_PROPERTY_KEY, 
typeDef.getTypeVersion());
         updateVertexProperty(vertex, Constants.TYPEOPTIONS_PROPERTY_KEY, 
AtlasType.toJson(typeDef.getOptions()));
 
+        if (StringUtils.isNotEmpty(typeDef.getServiceType())) {
+            updateVertexProperty(vertex, 
Constants.TYPESERVICETYPE_PROPERTY_KEY, typeDef.getServiceType());
+        }
+
         markVertexUpdated(vertex);
     }
 
@@ -265,6 +270,7 @@ public class AtlasTypeDefGraphStoreV2 extends 
AtlasTypeDefGraphStore {
     void vertexToTypeDef(AtlasVertex vertex, AtlasBaseTypeDef typeDef) {
         String name        = 
vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
         String description = 
vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
+        String serviceType = 
vertex.getProperty(Constants.TYPESERVICETYPE_PROPERTY_KEY, String.class);
         String typeVersion = 
vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
         String guid        = vertex.getProperty(Constants.GUID_PROPERTY_KEY, 
String.class);
         String createdBy   = vertex.getProperty(Constants.CREATED_BY_KEY, 
String.class);
@@ -287,6 +293,7 @@ public class AtlasTypeDefGraphStoreV2 extends 
AtlasTypeDefGraphStore {
 
         typeDef.setName(name);
         typeDef.setDescription(description);
+        typeDef.setServiceType(serviceType);
         typeDef.setTypeVersion(typeVersion);
         typeDef.setGuid(guid);
         typeDef.setCreatedBy(createdBy);

Reply via email to