Search in sources :

Example 1 with AtlasRelationship

use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.

the class AtlasRelationshipStoreV1 method create.

@Override
@GraphTransaction
public AtlasRelationship create(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> create({})", relationship);
    }
    AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
    AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());
    validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes());
    AtlasEdge edge = createRelationship(end1Vertex, end2Vertex, relationship);
    AtlasRelationship ret = edge != null ? entityRetriever.mapEdgeToAtlasRelationship(edge) : null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== create({}): {}", relationship, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 2 with AtlasRelationship

use of org.apache.atlas.model.instance.AtlasRelationship 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 3 with AtlasRelationship

use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.

the class EntityGraphRetriever method mapEdgeToAtlasRelationship.

public AtlasRelationship mapEdgeToAtlasRelationship(AtlasEdge edge) throws AtlasBaseException {
    AtlasRelationship ret = new AtlasRelationship();
    mapSystemAttributes(edge, ret);
    mapAttributes(edge, ret);
    return ret;
}
Also used : AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Example 4 with AtlasRelationship

use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.

the class EntityGraphMapper method getOrCreateRelationship.

private AtlasEdge getOrCreateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, AtlasAttribute attribute) throws AtlasBaseException {
    AtlasEdge ret = null;
    AtlasObjectId end1 = new AtlasObjectId(getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getTypeName(end1Vertex));
    AtlasObjectId end2 = new AtlasObjectId(getIdFromVertex(end2Vertex), AtlasGraphUtilsV1.getTypeName(end2Vertex));
    AtlasRelationship relationship = relationshipStore.getOrCreate(new AtlasRelationship(relationshipName, end1, end2));
    // return newly created AtlasEdge
    // if multiple edges are returned, compare using guid to pick the right one
    Iterator<AtlasEdge> outEdges = graphHelper.getOutGoingEdgesByLabel(end1Vertex, relationship.getLabel());
    while (outEdges.hasNext()) {
        AtlasEdge edge = outEdges.next();
        if (getIdFromVertex(end2Vertex).equals(getIdFromVertex(edge.getInVertex()))) {
            ret = edge;
            break;
        }
    }
    return ret;
}
Also used : AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 5 with AtlasRelationship

use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.

the class AtlasRelationshipStoreV1 method mapEdgeToAtlasRelationship.

private AtlasRelationship mapEdgeToAtlasRelationship(AtlasEdge edge) throws AtlasBaseException {
    AtlasRelationship ret = new AtlasRelationship();
    mapSystemAttributes(edge, ret);
    mapAttributes(edge, ret);
    return ret;
}
Also used : AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship)

Aggregations

AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)13 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)4 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)2 ArrayList (java.util.ArrayList)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1 AtlasRelatedObjectId (org.apache.atlas.model.instance.AtlasRelatedObjectId)1 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)1 RepositoryException (org.apache.atlas.repository.RepositoryException)1 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)1 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)1