Repository: atlas Updated Branches: refs/heads/master 59673d48c -> 45d3872b6
ATLAS-2513: Notifications are not sent about impacted entities when classification is updated at source entity Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/45d3872b Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/45d3872b Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/45d3872b Branch: refs/heads/master Commit: 45d3872b6d5cb58615894541f3ad7f6aa01480b3 Parents: 59673d4 Author: Sarath Subramanian <[email protected]> Authored: Mon Mar 26 09:19:27 2018 -0700 Committer: Sarath Subramanian <[email protected]> Committed: Mon Mar 26 09:19:27 2018 -0700 ---------------------------------------------------------------------- .../store/graph/v1/EntityGraphMapper.java | 37 +++++++++++++++----- .../store/graph/v1/EntityGraphRetriever.java | 7 ++-- 2 files changed, 33 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/45d3872b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java index 57aa41b..c76f640 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java @@ -22,6 +22,7 @@ import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; import org.apache.atlas.RequestContextV1; import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.TimeBoundary; import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntity; @@ -1479,10 +1480,11 @@ public class EntityGraphMapper { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid); } - String entityTypeName = AtlasGraphUtilsV1.getTypeName(entityVertex); - AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); - List<AtlasClassification> updatedClassifications = new ArrayList<>(); - List<AtlasVertex> entitiesToPropagateTo = new ArrayList<>(); + String entityTypeName = AtlasGraphUtilsV1.getTypeName(entityVertex); + AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName); + List<AtlasClassification> updatedClassifications = new ArrayList<>(); + List<AtlasVertex> entitiesToPropagateTo = new ArrayList<>(); + Map<AtlasVertex, List<AtlasClassification>> addedPropagations = null; Map<AtlasVertex, List<String>> removedPropagations = null; @@ -1508,12 +1510,31 @@ public class EntityGraphMapper { validateAndNormalizeForUpdate(classification); - Map<String, Object> classificationAttributes = classification.getAttributes(); + boolean isClassificationUpdated = false; + + // check for attribute update + Map<String, Object> updatedAttributes = classification.getAttributes(); - if (MapUtils.isNotEmpty(classificationAttributes)) { - for (String attributeName : classificationAttributes.keySet()) { - currentClassification.setAttribute(attributeName, classificationAttributes.get(attributeName)); + if (MapUtils.isNotEmpty(updatedAttributes)) { + for (String attributeName : updatedAttributes.keySet()) { + currentClassification.setAttribute(attributeName, updatedAttributes.get(attributeName)); } + + isClassificationUpdated = true; + } + + // check for validity period update + List<TimeBoundary> currentValidityPeriods = currentClassification.getValidityPeriods(); + List<TimeBoundary> updatedValidityPeriods = classification.getValidityPeriods(); + + if (!Objects.equals(currentValidityPeriods, updatedValidityPeriods)) { + currentClassification.setValidityPeriods(updatedValidityPeriods); + + isClassificationUpdated = true; + } + + if (isClassificationUpdated && CollectionUtils.isEmpty(entitiesToPropagateTo)) { + entitiesToPropagateTo = graphHelper.getImpactedVertices(guid); } if (LOG.isDebugEnabled()) { http://git-wip-us.apache.org/repos/asf/atlas/blob/45d3872b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java index 3885157..8fe635a 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java @@ -17,6 +17,7 @@ */ package org.apache.atlas.repository.store.graph.v1; +import com.fasterxml.jackson.core.type.TypeReference; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.TimeBoundary; @@ -100,8 +101,8 @@ public final class EntityGraphRetriever { private final String CREATE_TIME = "createTime"; private final String QUALIFIED_NAME = "qualifiedName"; - private static final List<TimeBoundary> TIME_BOUNDARIES_LIST = new ArrayList<>(); - private static final GraphHelper graphHelper = GraphHelper.getInstance(); + private static final TypeReference<List<TimeBoundary>> TIME_BOUNDARIES_LIST_TYPE = new TypeReference<List<TimeBoundary>>() {}; + private static final GraphHelper graphHelper = GraphHelper.getInstance(); private final AtlasTypeRegistry typeRegistry; @@ -249,7 +250,7 @@ public final class EntityGraphRetriever { String strValidityPeriods = AtlasGraphUtilsV1.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class); if (strValidityPeriods != null) { - ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST.getClass())); + ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE)); } mapAttributes(classificationVertex, ret, null);
