ArtifactsBusinessLogic refactor to remove NullPointerException 01/106301/4
authorChris André <chris.andre@yoppworks.com>
Tue, 2 Jun 2020 15:37:03 +0000 (11:37 -0400)
committerChris André <chris.andre@yoppworks.com>
Tue, 2 Jun 2020 16:07:24 +0000 (12:07 -0400)
- Reformatted `downloadResourceInstanceArtifactByUUIDs`
- Fixed Sonar-related warning regarding a NPE in `validateInput`

Issue-ID: SDC-2979
Signed-off-by: Chris Andre <chris.andre@yoppworks.com>
Change-Id: I5a62daabcc436f28fba1f09317c5723281df15bf

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java

index 1db7d44..a914973 100644 (file)
@@ -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);
+        }
     }
 
     /**