Search in sources :

Example 1 with PropagationState

use of org.apache.atlas.model.instance.AtlasClassification.PropagationState in project atlas by apache.

the class EntityGraphRetriever method mapClassifications.

private void mapClassifications(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException {
    List<AtlasEdge> edges = getAllClassificationEdges(entityVertex);
    if (CollectionUtils.isNotEmpty(edges)) {
        List<AtlasClassification> allClassifications = new ArrayList<>();
        List<AtlasClassification> propagationDisabledClassifications = new ArrayList<>();
        for (AtlasEdge edge : edges) {
            PropagationState edgeState = getClassificationEdgeState(edge);
            AtlasVertex classificationVertex = edge.getInVertex();
            if (edgeState == ACTIVE) {
                allClassifications.add(toAtlasClassification(classificationVertex));
            } else if (edgeState == DELETED && isPropagatedClassificationEdge(edge)) {
                propagationDisabledClassifications.add(toAtlasClassification(classificationVertex));
            }
        }
        entity.setClassifications(allClassifications);
        entity.setPropagationDisabledClassifications(propagationDisabledClassifications);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ArrayList(java.util.ArrayList) PropagationState(org.apache.atlas.model.instance.AtlasClassification.PropagationState) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 2 with PropagationState

use of org.apache.atlas.model.instance.AtlasClassification.PropagationState in project atlas by apache.

the class EntityGraphMapper method setPropagatedClassificationState.

public void setPropagatedClassificationState(String entityGuid, String classificationName, String sourceEntityGuid, boolean disablePropagation) throws AtlasBaseException {
    AtlasVertex entityVertex = AtlasGraphUtilsV1.findByGuid(entityGuid);
    if (entityVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, entityGuid);
    }
    AtlasEdge propagatedEdge = getPropagatedClassificationEdge(entityVertex, classificationName, sourceEntityGuid);
    if (propagatedEdge == null) {
        throw new AtlasBaseException(AtlasErrorCode.PROPAGATED_CLASSIFICATION_NOT_ASSOCIATED_WITH_ENTITY, classificationName);
    }
    PropagationState currentState = getClassificationEdgeState(propagatedEdge);
    PropagationState updatedState = (disablePropagation) ? PropagationState.DELETED : PropagationState.ACTIVE;
    if (currentState != updatedState) {
        AtlasGraphUtilsV1.setProperty(propagatedEdge, CLASSIFICATION_EDGE_STATE_PROPERTY_KEY, updatedState);
        if (disablePropagation) {
            removeFromPropagatedTraitNames(entityVertex, classificationName);
        } else {
            addToPropagatedTraitNames(entityVertex, classificationName);
        }
        updateModificationMetadata(entityVertex);
        AtlasEntityWithExtInfo entityWithExtInfo = instanceConverter.getAndCacheEntity(entityGuid);
        AtlasEntity entity = (entityWithExtInfo != null) ? entityWithExtInfo.getEntity() : null;
        if (updatedState == PropagationState.DELETED) {
            entityChangeNotifier.onClassificationDeletedFromEntity(entity, Collections.singletonList(classificationName));
        } else {
            AtlasClassification classification = entityRetriever.toAtlasClassification(propagatedEdge.getInVertex());
            entityChangeNotifier.onClassificationAddedToEntity(entity, Collections.singletonList(classification));
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) PropagationState(org.apache.atlas.model.instance.AtlasClassification.PropagationState) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 PropagationState (org.apache.atlas.model.instance.AtlasClassification.PropagationState)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 ArrayList (java.util.ArrayList)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1