Search in sources :

Example 1 with AtlasRelationshipType

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

the class AtlasRelationshipStoreV1 method updateRelationship.

private AtlasRelationship updateRelationship(AtlasEdge relationshipEdge, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
    updateTagPropagations(relationshipEdge, relationship.getPropagateTags());
    AtlasGraphUtilsV1.setProperty(relationshipEdge, Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationship.getPropagateTags().name());
    if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
        for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
            String attrName = attr.getName();
            String attrVertexProperty = attr.getVertexPropertyName();
            if (relationship.hasAttribute(attrName)) {
                AtlasGraphUtilsV1.setProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName));
            }
        }
    }
    return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute)

Example 2 with AtlasRelationshipType

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

the class AtlasRelationshipStoreV1 method getRelationshipTagPropagation.

private PropagateTags getRelationshipTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) {
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
    AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2();
    Set<String> fromVertexTypes = getTypeAndAllSuperTypes(getTypeName(fromVertex));
    Set<String> toVertexTypes = getTypeAndAllSuperTypes(getTypeName(toVertex));
    PropagateTags ret = relationshipType.getRelationshipDef().getPropagateTags();
    // swap the tagPropagation property for such cases.
    if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) {
        if (ret == ONE_TO_TWO) {
            ret = TWO_TO_ONE;
        } else if (ret == TWO_TO_ONE) {
            ret = ONE_TO_TWO;
        }
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) PropagateTags(org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags) GraphHelper.getPropagateTags(org.apache.atlas.repository.graph.GraphHelper.getPropagateTags) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 3 with AtlasRelationshipType

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

the class AtlasRelationshipStoreV1 method validateRelationship.

private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException {
    String end1TypeName = AtlasGraphUtilsV1.getTypeName(end1Vertex);
    String end2TypeName = AtlasGraphUtilsV1.getTypeName(end2Vertex);
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }
    boolean validEndTypes = false;
    if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName);
    } else if (relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
        validEndTypes = relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName);
    }
    if (!validEndTypes) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }
    List<String> messages = new ArrayList<>();
    AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes);
    relationshipType.validateValue(relationship, relationshipName, messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
    }
    relationshipType.getNormalizedValue(relationship);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Example 4 with AtlasRelationshipType

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

the class AtlasRelationshipStoreV1 method getRelationshipEdgeLabel.

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;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 5 with AtlasRelationshipType

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

the class AtlasRelationshipStoreV1 method getRelationshipEdgeLabel.

private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) {
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
    String ret = relationshipType.getRelationshipDef().getRelationshipLabel();
    AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2();
    Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV1.getTypeName(fromVertex));
    Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV1.getTypeName(toVertex));
    AtlasAttribute attribute = null;
    // e.g. [hive_process -> hive_table] -> [Process -> DataSet]
    if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) {
        String attributeName = endDef1.getName();
        attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName);
    } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) {
        String attributeName = endDef2.getName();
        attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName);
    }
    if (attribute != null) {
        ret = attribute.getRelationshipEdgeLabel();
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

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