Search in sources :

Example 16 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.

the class GraphHelper method getRelationshipDef.

public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
    List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName);
    AtlasRelationshipDef ret = null;
    if (relationshipTypes.size() > 1) {
        Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator();
        while (iter.hasNext() && ret == null) {
            String edgeTypeName = AtlasGraphUtilsV1.getTypeName(iter.next());
            for (AtlasRelationshipType relationType : relationshipTypes) {
                AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef();
                if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) {
                    ret = relationshipDef;
                    break;
                }
            }
        }
        if (ret == null) {
            ret = relationshipTypes.get(0).getRelationshipDef();
        }
    } else {
        // relationshipTypes will have at least one relationshipDef
        ret = relationshipTypes.get(0).getRelationshipDef();
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)9 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)8 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)4 ArrayList (java.util.ArrayList)3 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)3 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)3 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2 AtlasType (org.apache.atlas.type.AtlasType)2 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)1 GraphHelper.getPropagateTags (org.apache.atlas.repository.graph.GraphHelper.getPropagateTags)1 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)1