From 80a4b4a14a63509990bdbcb960538d30ae22a6e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Chris=20Andr=C3=A9?= Date: Tue, 21 Apr 2020 21:26:12 -0400 Subject: [PATCH] Add null test in ArtifactsOperations - Added if statement in `updateArtifactOnGraph` to account for the case where variable `artifactInst` has not been properly initialized Issue-ID: SDC-2919 Signed-off-by: Chris Andre Change-Id: I73fe3b3bcef59e5797a0f7cfe7b6894816d0d3fb --- .../operations/ArtifactsOperations.java | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperations.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperations.java index 3c8e0ee5cf..30e76a8b79 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperations.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArtifactsOperations.java @@ -686,22 +686,30 @@ public class ArtifactsOperations extends BaseOperation { List pathKeys = new ArrayList<>(); pathKeys.add(instanceId); if (isNeedToClone) { - MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); - if (artifatcsOnInstance != null) { - Map mapToscaDataDefinition = artifatcsOnInstance.getMapToscaDataDefinition(); - ArtifactDataDefinition artifactDataDefinitionToUpdate = new ArtifactDataDefinition(artifactToUpdate); - mapToscaDataDefinition.put(artifactToUpdate.getArtifactLabel(), artifactDataDefinitionToUpdate); - } + if (artifactInst != null) { + MapArtifactDataDefinition artifatcsOnInstance = artifactInst.get(instanceId); + if (artifatcsOnInstance != null) { + Map mapToscaDataDefinition = artifatcsOnInstance + .getMapToscaDataDefinition(); + ArtifactDataDefinition artifactDataDefinitionToUpdate = new ArtifactDataDefinition( + artifactToUpdate); + mapToscaDataDefinition.put(artifactToUpdate.getArtifactLabel(), artifactDataDefinitionToUpdate); + } - for (Entry e : artifactInst.entrySet()) { - List toscaDataListPerInst = e.getValue().getMapToscaDataDefinition().values().stream().collect(Collectors.toList()); - List pathKeysPerInst = new ArrayList<>(); - pathKeysPerInst.add(e.getKey()); - status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.ARTIFACT_LABEL); - if (status != StorageOperationStatus.OK) { - log.debug("Failed to update atifacts group for instance {} in component {} edge type {} error {}", instanceId, componentId, edgeLabelEnum, status); - res = Either.right(status); - break; + for (Entry e : artifactInst.entrySet()) { + List toscaDataListPerInst = e.getValue().getMapToscaDataDefinition() + .values().stream().collect(Collectors.toList()); + List pathKeysPerInst = new ArrayList<>(); + pathKeysPerInst.add(e.getKey()); + status = updateToscaDataDeepElementsOfToscaElement(componentId, edgeLabelEnum, vertexTypeEnum, + toscaDataListPerInst, pathKeysPerInst, JsonPresentationFields.ARTIFACT_LABEL); + if (status != StorageOperationStatus.OK) { + log.debug( + "Failed to update atifacts group for instance {} in component {} edge type {} error {}", + instanceId, componentId, edgeLabelEnum, status); + res = Either.right(status); + break; + } } } } else { -- 2.16.6