aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2017-11-15 16:18:32 +0200
committertalio <tali.orenbach@amdocs.com>2017-11-15 16:52:40 +0200
commit0872b963f2b2c0db594cea153efd09ad43c48888 (patch)
treec3d01067364c324e357432882fdcf7664cb51cbf /openecomp-be/lib/openecomp-tosca-converter-lib
parent68ca07bdc8b0aa86e31d06c083d73a140798f04d (diff)
import tosca
added exception when recognizing an invalid substitution mappings section inside imported csar Issue-Id : SDC-661 Change-Id: Id608b066d5e440ff5462ec3ba5742d3cff50bf5a Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java20
-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
3 files changed, 63 insertions, 10 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java
new file mode 100644
index 0000000000..9ae66dd91c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java
@@ -0,0 +1,20 @@
+package org.openecomp.core.converter.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+public class SubstitutionMappingsConverterErrorBuilder extends BaseErrorBuilder {
+ private static final String SUB_MAPPINGS_CAPABILITY_REQUIREMENT_ENTRY_VALUE_ILLEGAL = "%s value" +
+ " in substitution mappings is invalid, expected it to be %s";
+ private static final String IMPORT_TOSCA = "IMPORT_TOSCA";
+
+
+ public SubstitutionMappingsConverterErrorBuilder(String section,
+ String expectedType) {
+ getErrorCodeBuilder()
+ .withId(IMPORT_TOSCA)
+ .withCategory(ErrorCategory.APPLICATION)
+ .withMessage(String.format(SUB_MAPPINGS_CAPABILITY_REQUIREMENT_ENTRY_VALUE_ILLEGAL, section, expectedType));
+
+ }
+}
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;