You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sa...@apache.org on 2017/08/17 22:16:45 UTC

atlas git commit: ATLAS-2050: Add helper method in relationship store to check if entity has relationships associated

Repository: atlas
Updated Branches:
  refs/heads/master b23dc8584 -> a9514d4b1


ATLAS-2050: Add helper method in relationship store to check if entity has relationships associated


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

Branch: refs/heads/master
Commit: a9514d4b1c22b653b8d3fa1d83204ab91dbefedd
Parents: b23dc85
Author: Sarath Subramanian <ss...@hortonworks.com>
Authored: Thu Aug 17 15:16:31 2017 -0700
Committer: Sarath Subramanian <ss...@hortonworks.com>
Committed: Thu Aug 17 15:16:31 2017 -0700

----------------------------------------------------------------------
 .../graph/v1/AtlasRelationshipStoreV1.java      | 38 ++++++++++++++++++++
 1 file changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/a9514d4b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
index 4e8c148..9b27319 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
@@ -45,12 +45,16 @@ import org.springframework.stereotype.Component;
 import javax.inject.Inject;
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
 
+import static org.apache.atlas.repository.graphdb.AtlasEdgeDirection.BOTH;
+import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getTypeName;
+
 @Component
 public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
     private static final Logger LOG = LoggerFactory.getLogger(AtlasRelationshipStoreV1.class);
@@ -411,4 +415,38 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
 
         return typeName;
     }
+
+    /**
+     * Check whether this vertex has a relationship associated with this relationship type.
+     * @param vertex
+     * @param relationshipTypeName
+     * @return true if found an edge with this relationship type in.
+     */
+    private boolean vertexHasRelationshipWithType(AtlasVertex vertex, String relationshipTypeName) {
+        String relationshipEdgeLabel = getRelationshipEdgeLabel(getTypeName(vertex), relationshipTypeName);
+        Iterator<AtlasEdge> iter     = graphHelper.getAdjacentEdgesByLabel(vertex, BOTH, relationshipEdgeLabel);
+
+        return (iter != null) ? iter.hasNext() : false;
+    }
+
+    private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) {
+        AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName);
+        AtlasRelationshipDef  relationshipDef  = relationshipType.getRelationshipDef();
+        AtlasEntityType       end1Type         = relationshipType.getEnd1Type();
+        AtlasEntityType       end2Type         = relationshipType.getEnd2Type();
+        Set<String>           vertexTypes      = getTypeAndAllSuperTypes(typeName);
+        AtlasAttribute        attribute        = null;
+
+        if (vertexTypes.contains(end1Type.getTypeName())) {
+            String attributeName = relationshipDef.getEndDef1().getName();
+
+            attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null;
+        } else if (vertexTypes.contains(end2Type.getTypeName())) {
+            String attributeName = relationshipDef.getEndDef2().getName();
+
+            attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null;
+        }
+
+        return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null;
+    }
 }
\ No newline at end of file