From 8a5f3aebc6b5681c5c44307b7a0cdf868802e790 Mon Sep 17 00:00:00 2001 From: Chris André Date: Tue, 2 Jun 2020 11:37:03 -0400 Subject: ArtifactsBusinessLogic refactor to remove NullPointerException - Reformatted `downloadResourceInstanceArtifactByUUIDs` - Fixed Sonar-related warning regarding a NPE in `validateInput` Issue-ID: SDC-2979 Signed-off-by: Chris Andre Change-Id: I5a62daabcc436f28fba1f09317c5723281df15bf --- .../sdc/be/components/impl/ArtifactsBusinessLogic.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index 1db7d447f6..a91497356b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -1142,7 +1142,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { if (isDeploymentArtifact(artifactInfo)) { if (componentType != ComponentTypeEnum.RESOURCE_INSTANCE) { final String artifactName = artifactInfo.getArtifactName(); - if (operation.isCreateOrLink() || !artifactName.equalsIgnoreCase(existingArtifactInfo.getArtifactName())) { + final String existingArtifactName = + (existingArtifactInfo == null) ? null : existingArtifactInfo.getArtifactName(); + + if (operation.isCreateOrLink() + || ((artifactName != null) && !artifactName.equalsIgnoreCase(existingArtifactName))) { validateSingleDeploymentArtifactName(artifactName, parentComponent); } } @@ -3833,8 +3837,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { public byte[] downloadResourceInstanceArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID) { ComponentInstance resourceInstance = getRelatedComponentInstance(componentType, componentUuid, resourceInstanceName); - return downloadArtifact(resourceInstance == null ? null : resourceInstance.getDeploymentArtifacts(), - artifactUUID, resourceInstance.getName()); + + if (resourceInstance != null) { + return downloadArtifact(resourceInstance.getDeploymentArtifacts(), artifactUUID, resourceInstance.getName()); + } else { + return downloadArtifact(null, artifactUUID, null); + } } /** -- cgit 1.2.3-korg