diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java index 732fabb120..b0e85782df 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/ClassificationAssociator.java @@ -51,6 +51,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -245,13 +246,16 @@ private Map> validateAndTransfer(AtlasEntityHe Map> operationListMap = new HashMap<>(); Set requiredClassificationKeys = Stream.concat( - incomingEntityHeader.getRemoveClassifications().stream(), - incomingEntityHeader.getUpdateClassifications().stream() - ).map(this::generateClassificationComparisonKey) + Optional.ofNullable(incomingEntityHeader.getRemoveClassifications()).orElse(Collections.emptyList()).stream(), + Optional.ofNullable(incomingEntityHeader.getUpdateClassifications()).orElse(Collections.emptyList()).stream() + ).filter(classification -> classification.getEntityGuid().equals(entityToBeChanged.getGuid())) + .map(this::generateClassificationComparisonKey) .collect(Collectors.toSet()); - Set preExistingClassificationKeys = entityToBeChanged.getClassifications() + Set preExistingClassificationKeys = Optional.ofNullable(entityToBeChanged.getClassifications()) + .orElse(Collections.emptyList()) .stream() + .filter(classification -> classification.getEntityGuid().equals(entityToBeChanged.getGuid())) .map(this::generateClassificationComparisonKey) .collect(Collectors.toSet()); @@ -264,8 +268,10 @@ private Map> validateAndTransfer(AtlasEntityHe throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_ASSOCIATED_WITH_ENTITY, firstTypeName); } - List filteredClassifications = incomingEntityHeader.getAppendClassifications() + List filteredClassifications = Optional.ofNullable(incomingEntityHeader.getAppendClassifications()) + .orElse(Collections.emptyList()) .stream() + .filter(classification -> classification.getEntityGuid().equals(entityToBeChanged.getGuid())) .filter(appendClassification -> !preExistingClassificationKeys.contains(generateClassificationComparisonKey(appendClassification))) .collect(Collectors.toList());