aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core
diff options
context:
space:
mode:
authorAvi Gaffa <avi.gaffa@amdocs.com>2017-11-16 07:02:02 +0000
committerGerrit Code Review <gerrit@onap.org>2017-11-16 07:02:02 +0000
commit5d0f52a1833aa44bb740f6ca6152cdb3846691a7 (patch)
treef6557be41a4b29a096d2dba12a2ff10f3701250d /openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core
parentd83844341d03178eab318404fe46661837e5a69e (diff)
parent0872b963f2b2c0db594cea153efd09ad43c48888 (diff)
Merge "import tosca"
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core')
-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;