Search in sources :

Example 41 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge 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 42 with AtlasEdge

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

the class EntityGraphMapper method deleteClassifications.

public void deleteClassifications(String guid, List<String> classificationNames) throws AtlasBaseException {
    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);
    validateClassificationExists(traitNames, classificationNames);
    for (String classificationName : classificationNames) {
        try {
            final String entityTypeName = getTypeName(instanceVertex);
            String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, classificationName);
            AtlasEdge edge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
            if (edge != null) {
                deleteHandler.deleteEdgeReference(edge, TypeCategory.CLASSIFICATION, false, true);
                // update the traits in entity once trait removal is successful
                traitNames.remove(classificationName);
            }
        } catch (Exception e) {
            throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
        }
    }
    // remove the key
    instanceVertex.removeProperty(Constants.TRAIT_NAMES_PROPERTY_KEY);
    // add it back again
    for (String traitName : traitNames) {
        GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName);
    }
    updateModificationMetadata(instanceVertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException)

Example 43 with AtlasEdge

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

the class EntityGraphMapper method isRelationshipExists.

private boolean isRelationshipExists(AtlasVertex fromVertex, AtlasVertex toVertex, String edgeLabel) {
    boolean ret = false;
    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(fromVertex, edgeLabel);
    while (edges != null && edges.hasNext()) {
        AtlasEdge edge = edges.next();
        AtlasVertex inVertex = edge.getInVertex();
        if (inVertex != null && StringUtils.equals(getIdFromVertex(inVertex), getIdFromVertex(toVertex))) {
            ret = true;
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 44 with AtlasEdge

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

the class EntityGraphMapper method updateInConsistentOwnedMapVertices.

private void updateInConsistentOwnedMapVertices(AttributeMutationContext ctx, AtlasMapType mapType, Object val) {
    if (mapType.getValueType().getTypeCategory() == TypeCategory.OBJECT_ID_TYPE) {
        AtlasEdge edge = (AtlasEdge) val;
        if (ctx.getAttribute().isOwnedRef() && GraphHelper.getStatus(edge) == AtlasEntity.Status.DELETED && GraphHelper.getStatus(edge.getInVertex()) == AtlasEntity.Status.DELETED) {
            // Resurrect the vertex and edge to ACTIVE state
            GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name());
            GraphHelper.setProperty(edge.getInVertex(), STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name());
        }
    }
}
Also used : AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 45 with AtlasEdge

use of org.apache.atlas.repository.graphdb.AtlasEdge 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)

Aggregations

AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)138 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)60 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)28 AtlasType (org.apache.atlas.type.AtlasType)15 ArrayList (java.util.ArrayList)13 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)13 AtlasStructType (org.apache.atlas.type.AtlasStructType)12 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)12 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)11 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)8 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)8 AtlasMapType (org.apache.atlas.type.AtlasMapType)8 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)7 HashSet (java.util.HashSet)6 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)6 Id (org.apache.atlas.typesystem.persistence.Id)6 AtlasException (org.apache.atlas.AtlasException)5 Iterator (java.util.Iterator)4