From: franciscovila Date: Tue, 11 Jan 2022 11:02:57 +0000 (+0000) Subject: Fix use of Optional in ComponentBusinessLogic X-Git-Tag: 1.10.1~27 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F52%2F126552%2F2;p=sdc.git Fix use of Optional in ComponentBusinessLogic Checking the Optionals are present before getting their values in the ComponentBusinessLogic class Issue-ID: SDC-3829 Signed-off-by: franciscovila Change-Id: I9ec1825dfa0489875933728fa708fc79f0991751 --- diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index 8d202092b5..6625d72bcf 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -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); }