summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java49
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java4
2 files changed, 43 insertions, 10 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index 9b694c5207..685f39c3cb 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -1,10 +1,12 @@
package org.openecomp.core.impl;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.core.converter.ServiceTemplateReaderService;
import org.openecomp.core.converter.ToscaConverter;
import org.openecomp.core.converter.datatypes.Constants;
import org.openecomp.core.converter.datatypes.CsarFileTypes;
+import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder;
import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -326,16 +328,51 @@ public class ToscaConverterImpl implements ToscaConverter {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType));
- substitutionMapping.setCapabilities(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities)));
- substitutionMapping.setRequirements(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements)));
+ setSubstitutionMappingsSection(
+ capabilities, substitutionMapping,
+ convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities)));
+ setSubstitutionMappingsSection(
+ requirements, substitutionMapping,
+ convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements)));
return substitutionMapping;
}
- private Map<String, List<String>> convertSubstitutionMappingsSections(
- Map<String, Object> sectionToConvert) {
+ private void setSubstitutionMappingsSection(String sectionName,
+ SubstitutionMapping substitutionMapping,
+ Map<String, List<String>> convertedSection) {
+ if(MapUtils.isEmpty(convertedSection)
+ || StringUtils.isEmpty(sectionName)
+ || Objects.isNull(substitutionMapping)){
+ return;
+ }
+
+ switch (sectionName){
+ case requirements:
+ substitutionMapping.setRequirements(convertedSection);
+ break;
+ case capabilities:
+ substitutionMapping.setCapabilities(convertedSection);
+ break;
+ }
+ }
+
+ private Map<String, List<String>> convertSubstitutionMappingsSections(String sectionName,
+ Object sectionToConvert) {
+ if(Objects.isNull(sectionToConvert)){
+ return null;
+ }
+
+ if(!(sectionToConvert instanceof Map)){
+ throw new CoreException(
+ new SubstitutionMappingsConverterErrorBuilder(
+ sectionName, "Map").build());
+ }
+
+ return convertSubstitutionMappongsSection((Map<String, Object>) sectionToConvert);
+ }
+
+ private Map<String, List<String>> convertSubstitutionMappongsSection(Map<String, Object> sectionToConvert) {
Map<String, List<String>> convertedSection = new HashMap<>();
if (MapUtils.isEmpty(sectionToConvert)) {
return null;
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
index fa8532546c..8155fcc7f6 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
@@ -1,11 +1,7 @@
package org.openecomp.core.impl.services;
import org.openecomp.core.converter.ServiceTemplateReaderService;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.tosca.services.YamlUtil;
-import org.yaml.snakeyaml.error.YAMLException;
import java.util.HashMap;
import java.util.Map;