Fix use of Optional in ComponentBusinessLogic 52/126552/2
authorfranciscovila <javier.paradela.vila@est.tech>
Tue, 11 Jan 2022 11:02:57 +0000 (11:02 +0000)
committerMichael Morris <michael.morris@est.tech>
Thu, 13 Jan 2022 09:34:24 +0000 (09:34 +0000)
Checking the Optionals are present before getting
their values in the ComponentBusinessLogic class

Issue-ID: SDC-3829
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I9ec1825dfa0489875933728fa708fc79f0991751

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

index 8d20209..6625d72 100644 (file)
@@ -543,8 +543,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
             throw new ByResponseFormatComponentException(
                 componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
         }
-        ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
-            .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().get();
+
+        final ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
+            .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().orElseThrow(() -> {
+                throw new ByResponseFormatComponentException(
+                        componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+            });
         return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact);
     }