summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2017-11-21 10:00:27 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2017-11-21 09:30:22 +0000
commit2b79f16651701fdfa04eb100bc83f2a42b8ed609 (patch)
treef61d47888514142c0be011466f2d5c3526e9a07a /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
parent15dfe1e9a127bc73f671b9601d8b8c8e25c2d65f (diff)
fix NPE in extract
fix NPE when extracting components without images / flavors Issue - Id : SDC-694 Change-Id: I3e4444132a40a2567833375ceea1951803dd16b0 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java46
1 files changed, 18 insertions, 28 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java
index 93b95240d1..19e48eceaa 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/composition/CompositionDataExtractorImpl.java
@@ -324,43 +324,33 @@ public class CompositionDataExtractorImpl implements CompositionDataExtractor {
private Map<String,List<String>> getComponentImages(Map<String, NodeTemplate>
computeNodeTemplates,
ToscaServiceModel toscaServiceModel) {
- Map<String,List<String>> computeImages = new HashMap<>();
- for (String component : computeNodeTemplates.keySet()) {
- List<String> images = new ArrayList<>();
- Map<String,Object> properties = computeNodeTemplates.get(component).getProperties();
-
- List<Object> imagesList = properties.entrySet()
- .stream()
- .filter(map -> map.getKey().equals("image"))
- .map(map -> map.getValue())
- .collect(Collectors.toList());
- for (Object obj : imagesList) {
- if (obj instanceof String) {
- images.add((String) obj);
- } else {
- Map<String,String> objMap = new ObjectMapper().convertValue(obj,Map.class);
- images.add(getInputs(toscaServiceModel,objMap.get("get_input")));
- }
- }
- computeImages.put(component,images);
- }
- return computeImages;
+ return getComponentProperty(ToscaConstants.COMPUTE_IMAGE, computeNodeTemplates, toscaServiceModel);
}
private Map<String,List<String>> getComponentComputeFlavor(Map<String, NodeTemplate>
computeNodeTemplates,
ToscaServiceModel toscaServiceModel) {
- Map<String,List<String>> componentComputeFlavor = new HashMap<>();
+ return getComponentProperty(ToscaConstants.COMPUTE_FLAVOR, computeNodeTemplates, toscaServiceModel);
+ }
+
+ private Map<String, List<String>> getComponentProperty(String propertyName,
+ Map<String, NodeTemplate> computeNodeTemplates,
+ ToscaServiceModel toscaServiceModel) {
+ Map<String,List<String>> componentPropertyValues = new HashMap<>();
for (String component : computeNodeTemplates.keySet()) {
List<String> computes = new ArrayList<>();
Map<String,Object> properties = computeNodeTemplates.get(component).getProperties();
- List<Object> computessList = properties.entrySet()
+ if(MapUtils.isEmpty(properties)){
+ continue;
+ }
+
+ List<Object> computesList = properties.entrySet()
.stream()
- .filter(map -> map.getKey().equals("flavor"))
- .map(map -> map.getValue())
+ .filter(map -> map.getKey().equals(propertyName))
+ .map(Map.Entry::getValue)
.collect(Collectors.toList());
- for (Object obj : computessList) {
+ for (Object obj : computesList) {
if (obj instanceof String) {
computes.add((String) obj);
} else {
@@ -368,9 +358,9 @@ public class CompositionDataExtractorImpl implements CompositionDataExtractor {
computes.add(getInputs(toscaServiceModel, objMap.get("get_input")));
}
}
- componentComputeFlavor.put(component,computes);
+ componentPropertyValues.put(component,computes);
}
- return componentComputeFlavor;
+ return componentPropertyValues;
}
private String getInputs(ToscaServiceModel toscaServiceModel, String inputValue) {