diff options
author | Chris André <chris.andre@yoppworks.com> | 2020-05-05 07:54:27 -0400 |
---|---|---|
committer | Chris André <chris.andre@yoppworks.com> | 2020-05-12 07:03:26 -0400 |
commit | 3309283afc95e598a90461ad44d937f94b33cbfe (patch) | |
tree | 3ac2326443f361afd5f6e0c18a7f713ff99d6dae /catalog-model/src/main/java/org | |
parent | bbdbadb2c020d284748cc41e02b642da31189cf5 (diff) |
Add tests for the presence of Optional values
Issue-ID: SDC-3014
Signed-off-by: Chris Andre <chris.andre@yoppworks.com>
Change-Id: I041c0109c41bb1a716792074c004fd8f54857038
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/IdMapper.java | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/IdMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/IdMapper.java index 922f94bc5b..a20eb4dc14 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/IdMapper.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/IdMapper.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,6 +25,7 @@ import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Component; @@ -53,19 +54,27 @@ public class IdMapper { Map<String, CompositionDataDefinition> jsonComposition = (Map<String, CompositionDataDefinition>) serviceVertex.getJson(); CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue()); - Optional<ComponentInstanceDataDefinition> componentInstanceDataDefinitionOptional = null; + Optional<ComponentInstanceDataDefinition> componentInstanceDataDefinitionOptional; if (fromCompName) { - componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getNormalizedName().equals(componentUniqueIdOrName)).findAny(); - result = componentInstanceDataDefinitionOptional.get().getUniqueId(); - log.debug("Compponent Instance Unique Id = {}", result); + componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values() + .stream().filter(c -> c.getNormalizedName().equals(componentUniqueIdOrName)).findAny(); + + if (componentInstanceDataDefinitionOptional.isPresent()) { + result = componentInstanceDataDefinitionOptional.get().getUniqueId(); + log.debug("Component Instance Unique Id = {}", result); + } } else { - componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getUniqueId().equals(componentUniqueIdOrName)).findAny(); - result = componentInstanceDataDefinitionOptional.get().getNormalizedName(); - log.debug("Compponent Instance Normalized Name = {}", result); - } + componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values() + .stream().filter(c -> c.getUniqueId().equals(componentUniqueIdOrName)).findAny(); + if (componentInstanceDataDefinitionOptional.isPresent()) { + result = componentInstanceDataDefinitionOptional.get().getNormalizedName(); + log.debug("Component Instance Normalized Name = {}", result); + } + } } catch (Exception e) { - log.error("Failed to map UUID or Normalized name of " + componentUniqueIdOrName, e); + log.error(EcompLoggerErrorCode.DATA_ERROR, "Failed to map UUID or Normalized name of {}", + componentUniqueIdOrName, e); } return result; } |