Search in sources :

Example 6 with AtlasEdge

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

the class AtlasRelationshipStoreV1 method getRelationshipEdge.

public AtlasEdge getRelationshipEdge(AtlasVertex fromVertex, AtlasVertex toVertex, String relationshipType) {
    String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationshipType);
    Iterator<AtlasEdge> edgesIterator = getOutGoingEdgesByLabel(fromVertex, relationshipLabel);
    AtlasEdge ret = null;
    while (edgesIterator != null && edgesIterator.hasNext()) {
        AtlasEdge edge = edgesIterator.next();
        if (edge != null) {
            Status status = graphHelper.getStatus(edge);
            if ((status == null || status == ACTIVE) && StringUtils.equals(getIdFromVertex(edge.getInVertex()), getIdFromVertex(toVertex))) {
                ret = edge;
                break;
            }
        }
    }
    return ret;
}
Also used : Status(org.apache.atlas.model.instance.AtlasEntity.Status) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 7 with AtlasEdge

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

the class EntityGraphMapper method addInverseReference.

private void addInverseReference(AtlasAttribute inverseAttribute, AtlasEdge edge, Map<String, Object> relationshipAttributes) throws AtlasBaseException {
    AtlasStructType inverseType = inverseAttribute.getDefinedInType();
    AtlasVertex inverseVertex = edge.getInVertex();
    String inverseEdgeLabel = inverseAttribute.getRelationshipEdgeLabel();
    AtlasEdge inverseEdge = graphHelper.getEdgeForLabel(inverseVertex, inverseEdgeLabel);
    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(inverseType, inverseAttribute.getName());
    // create new inverse reference
    AtlasEdge newEdge = createInverseReferenceUsingRelationship(inverseAttribute, edge, relationshipAttributes);
    boolean inverseUpdated = true;
    switch(inverseAttribute.getAttributeType().getTypeCategory()) {
        case OBJECT_ID_TYPE:
            if (inverseEdge != null) {
                if (!inverseEdge.equals(newEdge)) {
                    // Disconnect old reference
                    deleteHandler.deleteEdgeReference(inverseEdge, inverseAttribute.getAttributeType().getTypeCategory(), inverseAttribute.isOwnedRef(), true, inverseVertex);
                } else {
                    // Edge already exists for this attribute between these vertices.
                    inverseUpdated = false;
                }
            }
            break;
        case ARRAY:
            // Add edge ID to property value
            List<String> elements = inverseVertex.getProperty(propertyName, List.class);
            if (newEdge != null && elements == null) {
                elements = new ArrayList<>();
                elements.add(newEdge.getId().toString());
                inverseVertex.setProperty(propertyName, elements);
            } else {
                if (newEdge != null && !elements.contains(newEdge.getId().toString())) {
                    elements.add(newEdge.getId().toString());
                    inverseVertex.setProperty(propertyName, elements);
                } else {
                    // Property value list already contains the edge ID.
                    inverseUpdated = false;
                }
            }
            break;
        default:
            break;
    }
    if (inverseUpdated) {
        RequestContextV1 requestContext = RequestContextV1.get();
        if (!requestContext.isDeletedEntity(GraphHelper.getGuid(inverseVertex))) {
            updateModificationMetadata(inverseVertex);
            requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(inverseVertex));
        }
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContextV1(org.apache.atlas.RequestContextV1) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 8 with AtlasEdge

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

the class EntityGraphMapper method addTagPropagation.

private List<AtlasVertex> addTagPropagation(AtlasVertex classificationVertex, List<AtlasVertex> propagatedEntityVertices) {
    List<AtlasVertex> ret = null;
    if (CollectionUtils.isNotEmpty(propagatedEntityVertices) && classificationVertex != null) {
        String classificationName = getTypeName(classificationVertex);
        AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationName);
        for (AtlasVertex propagatedEntityVertex : propagatedEntityVertices) {
            AtlasEdge existingEdge = getPropagatedClassificationEdge(propagatedEntityVertex, classificationVertex);
            if (existingEdge != null) {
                continue;
            }
            String entityTypeName = getTypeName(propagatedEntityVertex);
            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
            if (classificationType.canApplyToEntityType(entityType)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug(" --> Adding propagated classification: [{}] to {} ({}) using edge label: [{}]", classificationName, getTypeName(propagatedEntityVertex), GraphHelper.getGuid(propagatedEntityVertex), CLASSIFICATION_LABEL);
                }
                if (ret == null) {
                    ret = new ArrayList<>();
                }
                ret.add(propagatedEntityVertex);
                graphHelper.addClassificationEdge(propagatedEntityVertex, classificationVertex, true);
                addToPropagatedTraitNames(propagatedEntityVertex, classificationName);
            }
        }
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 9 with AtlasEdge

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

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

the class EntityGraphMapper method getArrayElementsUsingRelationship.

public static List<Object> getArrayElementsUsingRelationship(AtlasVertex vertex, AtlasAttribute attribute, AtlasType elementType) {
    List<Object> ret = null;
    if (AtlasGraphUtilsV1.isReference(elementType)) {
        AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection();
        String edgeLabel = attribute.getRelationshipEdgeLabel();
        Iterator<AtlasEdge> edgesForLabel = GraphHelper.getEdgesForLabel(vertex, edgeLabel, edgeDirection);
        ret = IteratorUtils.toList(edgesForLabel);
    }
    return ret;
}
Also used : AtlasRelationshipEdgeDirection(org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection) 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