aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-01-13 11:54:10 +0000
committerMichael Morris <michael.morris@est.tech>2022-01-17 10:21:11 +0000
commitd80ae5529f51d6ad10759c07cb4960762700faef (patch)
treec0ea07b6973d232e851136f6627743e2a4c410a6 /openecomp-be
parent08e100185603620b455d8e0e421de0b66d97fbee (diff)
Fix use of Optional in ToscaAnalyzerServiceImpl
Checking the Optionals are present before getting their values in the ToscaAnalyzerServiceImpl class Issue-ID: SDC-3836 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: I206877115abf36d8b80a8d38dac2415407828c4b
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java38
1 files changed, 19 insertions, 19 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index c5deee4ebd..1a37f90bfb 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -407,25 +407,25 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (requirementMapping != null && !requirementMapping.isEmpty()) {
String mappedNodeTemplateId = requirementMapping.get(0);
Optional<NodeTemplate> mappedNodeTemplate = getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId);
- mappedNodeTemplate.orElseThrow(
- () -> new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build()));
- Map.Entry<String, NodeTemplate> mappedNodeTemplateEntry = new Map.Entry<String, NodeTemplate>() {
- @Override
- public String getKey() {
- return mappedNodeTemplateId;
- }
-
- @Override
- public NodeTemplate getValue() {
- return mappedNodeTemplate.get();
- }
-
- @Override
- public NodeTemplate setValue(NodeTemplate value) {
- return null;
- }
- };
- return Optional.of(mappedNodeTemplateEntry);
+ if (mappedNodeTemplate.isPresent()) {
+ final NodeTemplate nodeTemplate = mappedNodeTemplate.get();
+ return Optional.of(new HashMap.Entry<>() {
+ @Override
+ public String getKey() {
+ return mappedNodeTemplateId;
+ }
+ @Override
+ public NodeTemplate getValue() {
+ return nodeTemplate;
+ }
+ @Override
+ public NodeTemplate setValue(final NodeTemplate nodeTemplate) {
+ return null;
+ }
+ });
+ } else {
+ throw new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build());
+ }
}
}
}