Search in sources :

Example 6 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method createInverseReference.

// legacy method to create edges for inverse reference
private AtlasEdge createInverseReference(AtlasAttribute inverseAttribute, AtlasStructType inverseAttributeType, AtlasVertex inverseVertex, AtlasVertex vertex) throws AtlasBaseException {
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseAttributeType, inverseAttribute.getName());
    String inverseEdgeLabel = AtlasGraphUtilsV1.getEdgeLabel(propertyName);
    AtlasEdge ret;
    try {
        ret = graphHelper.getOrCreateEdge(inverseVertex, vertex, inverseEdgeLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 7 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method mapObjectIdValue.

private AtlasEdge mapObjectIdValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapObjectIdValue({})", ctx);
    }
    AtlasEdge ret = null;
    String guid = getGuid(ctx.getValue());
    AtlasVertex entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(guid);
    if (entityVertex == null) {
        AtlasObjectId objId = getObjectId(ctx.getValue());
        if (objId != null) {
            entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId);
        }
    }
    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString()));
    }
    if (ctx.getCurrentEdge() != null) {
        ret = updateEdge(ctx.getAttributeDef(), ctx.getValue(), ctx.getCurrentEdge(), entityVertex);
    } else if (ctx.getValue() != null) {
        String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty());
        try {
            ret = graphHelper.getOrCreateEdge(ctx.getReferringVertex(), entityVertex, edgeLabel);
        } catch (RepositoryException e) {
            throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapObjectIdValue({})", ctx);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 8 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method mapClassification.

private AtlasEdge mapClassification(EntityOperation operation, final EntityMutationContext context, AtlasClassification classification, AtlasEntityType entityType, AtlasVertex parentInstanceVertex, AtlasVertex traitInstanceVertex) throws AtlasBaseException {
    // map all the attributes to this newly created AtlasVertex
    mapAttributes(classification, traitInstanceVertex, operation, context);
    // add an edge to the newly created AtlasVertex from the parent
    String relationshipLabel = GraphHelper.getTraitLabel(entityType.getTypeName(), classification.getTypeName());
    try {
        return graphHelper.getOrCreateEdge(parentInstanceVertex, traitInstanceVertex, relationshipLabel);
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException)

Example 9 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class EntityGraphMapper method updateEdge.

private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException {
    LOG.debug("Updating entity reference {} for reference attribute {}", attributeDef.getName());
    // Update edge if it exists
    AtlasVertex currentVertex = currentEdge.getInVertex();
    String currentEntityId = getIdFromVertex(currentVertex);
    String newEntityId = getIdFromVertex(entityVertex);
    AtlasEdge newEdge = currentEdge;
    if (!currentEntityId.equals(newEntityId)) {
        // add an edge to the class vertex from the instance
        if (entityVertex != null) {
            try {
                newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel());
            } catch (RepositoryException e) {
                throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
            }
        }
    }
    return newEdge;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 10 with RepositoryException

use of org.apache.atlas.repository.RepositoryException in project incubator-atlas by apache.

the class AtlasRelationshipStoreV1 method createRelationship.

private AtlasRelationship createRelationship(AtlasRelationship relationship, AtlasVertex end1Vertex, AtlasVertex end2Vertex) throws AtlasBaseException {
    AtlasRelationship ret;
    try {
        AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship);
        if (relationshipEdge == null) {
            relationshipEdge = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
            AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
            if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
                for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
                    String attrName = attr.getName();
                    String attrVertexProperty = attr.getVertexPropertyName();
                    Object attrValue = relationship.getAttribute(attrName);
                    AtlasGraphUtilsV1.setProperty(relationshipEdge, attrVertexProperty, attrValue);
                }
            }
            ret = mapEdgeToAtlasRelationship(relationshipEdge);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), relationship.getEnd1().getGuid(), relationship.getEnd2().getGuid());
        }
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasRelationship(org.apache.atlas.model.instance.AtlasRelationship) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

RepositoryException (org.apache.atlas.repository.RepositoryException)31 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasException (org.apache.atlas.AtlasException)11 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)5 RequestContext (org.apache.atlas.RequestContext)4 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 GuidMapping (org.apache.atlas.model.instance.GuidMapping)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)2