Repository: atlas
Updated Branches:
  refs/heads/master 8ae61e0f5 -> 96a348a9a


ATLAS-2556: fixed classification-def update to handle removal of all 
entity-type restrictions


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/96a348a9
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/96a348a9
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/96a348a9

Branch: refs/heads/master
Commit: 96a348a9a0e43112ca90661baf4b29d5af335506
Parents: 8ae61e0
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Wed Apr 11 16:30:56 2018 -0700
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Thu Apr 12 10:00:40 2018 -0700

----------------------------------------------------------------------
 .../graph/v1/AtlasTypeDefGraphStoreV1.java      | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/96a348a9/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
index 9e22869..3c84e3c 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
@@ -384,6 +384,16 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
         return atlasGraph.addEdge(outVertex, inVertex, edgeLabel);
     }
 
+    void removeEdge(AtlasVertex outVertex, AtlasVertex inVertex, String 
edgeLabel) {
+        Iterable<AtlasEdge> edges = outVertex.getEdges(AtlasEdgeDirection.OUT, 
edgeLabel);
+
+        for (AtlasEdge edge : edges) {
+            if (edge.getInVertex().getId().equals(inVertex.getId())) {
+                atlasGraph.removeEdge(edge);
+            }
+        }
+    }
+
     void createSuperTypeEdges(AtlasVertex vertex, Set<String> superTypes, 
TypeCategory typeCategory)
             throws AtlasBaseException {
         Set<String> currentSuperTypes = getSuperTypeNames(vertex);
@@ -420,6 +430,18 @@ public class AtlasTypeDefGraphStoreV1 extends 
AtlasTypeDefGraphStore {
                 }
                 getOrCreateEdge(classificationVertex, entityTypeVertex, 
AtlasGraphUtilsV1.ENTITYTYPE_EDGE_LABEL);
             }
+        } else if (CollectionUtils.isNotEmpty(currentEntityTypes)) { // remove 
the restrictions, if present
+            for (String entityType : currentEntityTypes) {
+                AtlasVertex entityTypeVertex = 
findTypeVertexByNameAndCategory(entityType, TypeCategory.CLASS);
+
+                if (entityTypeVertex == null) {
+                    throw new 
AtlasBaseException(AtlasErrorCode.CLASSIFICATIONDEF_INVALID_ENTITYTYPES, 
classificationTypeName,entityType);
+
+                }
+
+                removeEdge(classificationVertex, entityTypeVertex, 
AtlasGraphUtilsV1.ENTITYTYPE_EDGE_LABEL);
+            }
+
         }
     }
 

Reply via email to