aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java9
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelConvertUtil.java129
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelConvertUtilTest.java116
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/emptyImportList.yml5
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTest.yml (renamed from openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml)5
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTestNoImport.yml (renamed from openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTestNoImport.yml)0
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importMultiLineGrammar.yml10
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidImportMultiLineGrammar.yml10
-rw-r--r--common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidToscaImport.yml (renamed from openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaImport.yml)0
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java12
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java69
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java53
13 files changed, 292 insertions, 130 deletions
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java
index 8a5e0da399..becd34a8ef 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplate.java
@@ -16,10 +16,13 @@
package org.onap.sdc.tosca.datatypes.model;
+import static org.onap.sdc.tosca.services.DataModelConvertUtil.convertToscaImports;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.heatextend.AnnotationType;
import org.onap.sdc.tosca.error.ToscaRuntimeException;
@@ -84,12 +87,12 @@ public class ServiceTemplate implements Template {
this.description = description;
}
- public List<Map<String, Import>> getImports() {
+ public List getImports() {
return imports;
}
- public void setImports(List<Map<String, Import>> imports) {
- this.imports = imports;
+ public void setImports(List imports) {
+ this.imports = convertToscaImports(imports);
}
public Map<String, ArtifactType> getArtifact_types() {
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelConvertUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelConvertUtil.java
new file mode 100644
index 0000000000..693e7d66df
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelConvertUtil.java
@@ -0,0 +1,129 @@
+package org.onap.sdc.tosca.services;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.error.ToscaRuntimeException;
+
+public class DataModelConvertUtil {
+
+ private static final String INVALID_TOSCA_IMPORT_SECTION = "Invalid TOSCA import section";
+
+ private DataModelConvertUtil() {
+ //Hiding implicit default constructor
+ }
+
+ public static List<Map<String, Import>> convertToscaImports(List importObj) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ List<Map<String, Import>> convertedImport = new ArrayList<>();
+ if (CollectionUtils.isEmpty(importObj)) {
+ return null;
+ }
+ for (Object importEntry : importObj) {
+ convertToscaImportEntry(convertedImport, importEntry, toscaExtensionYamlUtil);
+ }
+ return convertedImport;
+ }
+
+ private static void convertToscaImportEntry(List<Map<String, Import>> convertedImport, Object importEntry,
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil) {
+ if (importEntry instanceof String) {
+ //Support for import short notation
+ /*
+ imports:
+ - <file_URI_1>
+ - <file_URI_2>
+ */
+ convertImportShortNotation(convertedImport, importEntry.toString());
+ } else if (importEntry instanceof Map) {
+ handleImportMultiLineGrammar(convertedImport, importEntry, toscaExtensionYamlUtil);
+ }
+ }
+
+ private static void handleImportMultiLineGrammar(List<Map<String, Import>> convertedImport, Object importEntry,
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil) {
+ try {
+ if (((Map) importEntry).containsKey("file")) {
+ //Support for import entry of the format - file: <file_uri> or - file: <import object>
+ Import importObject = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importEntry), Import.class);
+ convertImportExtendedNotation(convertedImport, importObject);
+ } else {
+ convertImportMultiLineGrammar(convertedImport, (Map) importEntry, toscaExtensionYamlUtil);
+ }
+ } catch (Exception ex) {
+ throw new ToscaRuntimeException(INVALID_TOSCA_IMPORT_SECTION, ex);
+ }
+ }
+
+ private static void convertImportMultiLineGrammar(List<Map<String, Import>> convertedImport, Map importEntry,
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil) {
+ Set<Map.Entry<String, Object>> importEntries = importEntry.entrySet();
+ for (Map.Entry<String, Object> toscaImport : importEntries) {
+ String key = toscaImport.getKey();
+ Object importValue = toscaImport.getValue();
+ if (importValue instanceof Map) {
+ /* Support for import entry of the format multi line extended import notation
+ - another_definition_file:
+ file: path1/file.yaml
+ repository: service_repo
+ namespace_uri: http://test.xyz/uri
+ namespace_prefix: pref
+ */
+ Import importObject = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importValue), Import.class);
+ Map<String, Import> convertedToscaImport = new HashMap<>();
+ convertedToscaImport.put(key, importObject);
+ convertedImport.add(convertedToscaImport);
+ } else {
+ //Support for import entry of the format - some_definition_file: path1/path2/fileName.yaml
+ convertedImport.add((Map<String, Import>) importEntry);
+ }
+ }
+ }
+
+ private static void convertImportExtendedNotation(List<Map<String, Import>> convertedImport, Import importEntry) {
+ Map<String, Import> importMap = new HashMap<>();
+ Optional<String> fileNameWithoutExtension =
+ getFileNameWithoutExtension(getFileName(importEntry.getFile()).replaceAll("/", "_"));
+ if (fileNameWithoutExtension.isPresent()) {
+ importMap.put(fileNameWithoutExtension.get(), importEntry);
+ convertedImport.add(importMap);
+ }
+ }
+
+ private static void convertImportShortNotation(List<Map<String, Import>> convertImport, String fileFullName) {
+ Import importObject = new Import();
+ importObject.setFile(fileFullName);
+ Map<String, Import> importMap = new HashMap<>();
+ Optional<String> fileNameWithoutExtension = getFileNameWithoutExtension(getFileName(fileFullName));
+ if (fileNameWithoutExtension.isPresent()) {
+ importMap.put(fileNameWithoutExtension.get().replaceAll("/", "_"), importObject);
+ convertImport.add(importMap);
+ }
+ }
+
+ private static Optional<String> getFileNameWithoutExtension(String fileName) {
+ if (Objects.isNull(fileName)) {
+ return Optional.empty();
+ }
+ return !fileName.contains(".") ? Optional.of(fileName)
+ : Optional.of(fileName.substring(0, fileName.lastIndexOf('.')));
+ }
+
+
+ private static String getFileName(String relativeFileName) {
+ if (relativeFileName.contains("../")) {
+ return relativeFileName.replace("../", "");
+ } else {
+ return relativeFileName;
+ }
+ }
+}
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelConvertUtilTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelConvertUtilTest.java
new file mode 100644
index 0000000000..d4c1a75e9a
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelConvertUtilTest.java
@@ -0,0 +1,116 @@
+package org.onap.sdc.tosca.services;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+
+
+public class DataModelConvertUtilTest {
+
+ @Test
+ public void testConvertToscaImport() throws Exception {
+ ServiceTemplate serviceTemplate;
+ String inputResourceName = "/mock/serviceTemplate/importConvertTest.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ serviceTemplate = toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ }
+ assertNotNull(((Map)serviceTemplate.getImports().get(0)).get("data"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(1)).get("artifacts"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(2)).get("capabilities"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(3)).get("api_interfaces"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(4)).get("api_util_relationships"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(5)).get("common"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(6)).get("api_util"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(7)).get("relationshipsExt"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(8)).get("some_definition_file"));
+ assertNotNull(((Map)serviceTemplate.getImports().get(9)).get("site_index"));
+ }
+
+ @Test
+ public void testConvertToscaImportForEmptyImport() throws Exception {
+ ServiceTemplate serviceTemplate;
+ String inputResourceName = "/mock/serviceTemplate/importConvertTestNoImport.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ serviceTemplate = toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ }
+
+ Assert.assertNull(serviceTemplate.getImports());
+ }
+
+ @Test
+ public void testInvalidToscaImportSection() {
+ String inputResourceName = "/mock/serviceTemplate/invalidToscaImport.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ Assert.fail();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex.getMessage().contains("Cannot create property=imports"));
+ }
+ }
+
+ @Test
+ public void testEmptyImportList() throws Exception {
+ String inputResourceName = "/mock/serviceTemplate/emptyImportList.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ assertNull(serviceTemplate.getImports());
+ }
+ }
+
+ @Test
+ public void testConvertToscaImportMultiLineGrammar() throws Exception {
+ ServiceTemplate serviceTemplate;
+ String inputResourceName = "/mock/serviceTemplate/importMultiLineGrammar.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ serviceTemplate = toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ }
+ Map<String, Import> parsedMultiLineImport = (Map<String, Import>) serviceTemplate.getImports().get(0);
+ assertNotNull(parsedMultiLineImport);
+ Import multiLineGrammarImport = parsedMultiLineImport.get("multi_line_grammar_import");
+ assertNotNull(multiLineGrammarImport);
+ assertEquals(multiLineGrammarImport.getFile(), "path1/path2/importFile.yaml");
+ assertEquals(multiLineGrammarImport.getRepository(), "service_repo");
+ assertEquals(multiLineGrammarImport.getNamespace_uri(), "http://test.xyz/tosca/1.0/platform");
+ assertEquals(multiLineGrammarImport.getNamespace_prefix(), "ns_prefix");
+ }
+
+
+ @Test
+ public void testConvertToscaImportInvalidMultiLineGrammar() {
+ String inputResourceName = "/mock/serviceTemplate/invalidImportMultiLineGrammar.yml";
+ URL resource = this.getClass().getResource(inputResourceName);
+ File inputPayload = new File(resource.getFile());
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ try (FileInputStream fis = new FileInputStream(inputPayload)) {
+ toscaExtensionYamlUtil.yamlToObject(fis, ServiceTemplate.class);
+ Assert.fail();
+ } catch (Exception ex) {
+ Assert.assertTrue(ex.getMessage().contains("Cannot create property=imports"));
+ }
+ }
+}
diff --git a/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/emptyImportList.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/emptyImportList.yml
new file mode 100644
index 0000000000..51b5dbb901
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/emptyImportList.yml
@@ -0,0 +1,5 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+imports: []
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTest.yml
index 08ddc3c206..8603e37b3c 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTest.yml
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTest.yml
@@ -9,6 +9,11 @@ imports:
file: api/common.yaml
- file: api/util.yaml
- relationshipsExt.yml
+- some_definition_file: api/util.yaml
+- file: site/index.yml
+ repository: nexus_repo
+ namespace_uri: http://namespace_uri
+ namespace_prefix: ns_prefix
node_types:
tosca.nodes.Root:
description: The TOSCA Node Type all other TOSCA base Node Types derive from \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTestNoImport.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTestNoImport.yml
index 536e1367e5..536e1367e5 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/importConvertTestNoImport.yml
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importConvertTestNoImport.yml
diff --git a/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importMultiLineGrammar.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importMultiLineGrammar.yml
new file mode 100644
index 0000000000..347e20d0d3
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/importMultiLineGrammar.yml
@@ -0,0 +1,10 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+imports:
+- multi_line_grammar_import:
+ file: path1/path2/importFile.yaml
+ repository: service_repo
+ namespace_uri: http://test.xyz/tosca/1.0/platform
+ namespace_prefix: ns_prefix
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from \ No newline at end of file
diff --git a/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidImportMultiLineGrammar.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidImportMultiLineGrammar.yml
new file mode 100644
index 0000000000..b5581900cf
--- /dev/null
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidImportMultiLineGrammar.yml
@@ -0,0 +1,10 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+imports:
+- multi_line_grammar_import:
+ file: path1/path2/importFile.yaml
+ repository: service_repo
+ namespace_uri: http://test.xyz/tosca/1.0/platform
+ invalid_key: ns_prefix
+node_types:
+ tosca.nodes.Root:
+ description: The TOSCA Node Type all other TOSCA base Node Types derive from \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaImport.yml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidToscaImport.yml
index 8a5cfaa9ac..8a5cfaa9ac 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/analyzerService/invalidToscaImport.yml
+++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/invalidToscaImport.yml
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
index 859d3da9dc..0b0c6e42f9 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
@@ -46,6 +46,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@@ -180,12 +181,11 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
}
private void convertImports(ServiceTemplate serviceTemplate) {
- serviceTemplate.setImports(new ArrayList<>());
- serviceTemplate.getImports()
- .add(createImportMap(openecompHeatIndex, HEAT_INDEX_IMPORT_FILE));
- serviceTemplate.getImports().add(createImportMap(ONAP_INDEX, ONAP_INDEX_IMPORT_FILE));
- serviceTemplate.getImports().add(createImportMap(globalSubstitution, globalStName));
-
+ List<Map<String, Import>> imports = new ArrayList<>();
+ imports.add(createImportMap(openecompHeatIndex, HEAT_INDEX_IMPORT_FILE));
+ imports.add(createImportMap(ONAP_INDEX, ONAP_INDEX_IMPORT_FILE));
+ imports.add(createImportMap(globalSubstitution, globalStName));
+ serviceTemplate.setImports(imports);
}
private Map<String, Import> createImportMap(String key, String fileName) {
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
index d5a99106bc..2c3ff0ae5d 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
@@ -44,8 +44,8 @@ public class ToscaConvertorDefinitionsTest {
assertNotNull(serviceTemplate.getImports());
assertFalse(serviceTemplate.getImports().isEmpty());
assertEquals(1 ,serviceTemplate.getImports().size());
- assertTrue(serviceTemplate.getImports().get(0).containsKey(HEAT_INDEX));
- assertTrue(serviceTemplate.getImports().get(0).containsKey(ONAP_INDEX));
+ assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(HEAT_INDEX));
+ assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(ONAP_INDEX));
assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 053253a993..14cf90a272 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -169,11 +169,10 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
void loadToscaYamlFile(ToscaServiceModel toscaServiceModel, ToscaExtensionYamlUtil toscaExtensionYamlUtil,
- byte[] fileContent, String fileFullName) {
+ byte[] fileContent, String fileFullName) {
try {
- String serviceTemplateYamlString = convertServiceTemplateImport(toscaExtensionYamlUtil, fileContent);
ServiceTemplate serviceTemplate =
- toscaExtensionYamlUtil.yamlToObject(serviceTemplateYamlString, ServiceTemplate.class);
+ toscaExtensionYamlUtil.yamlToObject(new String(fileContent), ServiceTemplate.class);
toscaServiceModel.addServiceTemplate(fileFullName, serviceTemplate);
} catch (Exception exc) {
@@ -181,70 +180,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
}
- String convertServiceTemplateImport(ToscaExtensionYamlUtil toscaExtensionYamlUtil, byte[] fileContent) {
- Map serviceTemplateMap = toscaExtensionYamlUtil.yamlToObject(new String(fileContent), Map.class);
- convertToscaImports(serviceTemplateMap, toscaExtensionYamlUtil);
- return toscaExtensionYamlUtil.objectToYaml(serviceTemplateMap);
- }
-
- private void convertToscaImports(Map serviceTemplateMap, ToscaExtensionYamlUtil toscaExtensionYamlUtil) {
- List<Map<String, Import>> convertedImport = new ArrayList<>();
- Object importObj = serviceTemplateMap.get(IMPORTS);
- if (Objects.nonNull(importObj) && !(importObj instanceof List)) {
- throw new SdcRuntimeException(new IllegalStateException("Invalid TOSCA import section"));
- }
- List<Object> imports = (List) importObj;
- if (CollectionUtils.isEmpty(imports)) {
- return;
- }
- for (Object importEntry : imports) {
- convertToscaImportEntry(convertedImport, importEntry, toscaExtensionYamlUtil);
- }
- serviceTemplateMap.remove(IMPORTS);
- serviceTemplateMap.put(IMPORTS, convertedImport);
- }
-
- private void convertToscaImportEntry(List<Map<String, Import>> convertedImport, Object importEntry,
- ToscaExtensionYamlUtil toscaExtensionYamlUtil) {
- if (importEntry instanceof String) {
- convertImportShortNotation(convertedImport, importEntry.toString());
- } else if (importEntry instanceof Map) {
- if (((Map) importEntry).containsKey("file")) {
- Import importObject = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importEntry),
- Import.class);
- convertImportExtendNotation(convertedImport, importObject);
- } else {
- convertedImport.add((Map<String, Import>) importEntry);
- }
- }
- }
-
- private void convertImportExtendNotation(List<Map<String, Import>> convertedImport, Import importEntry) {
- Map<String, Import> importMap = new HashMap();
- importMap.put(FileUtils.getFileWithoutExtention(getFileName(importEntry.getFile()).replaceAll("/", "_")),
- importEntry);
- convertedImport.add(importMap);
- }
-
- private void convertImportShortNotation(List<Map<String, Import>> convertImport, String fileFullName) {
- Import importObject = new Import();
- importObject.setFile(fileFullName);
- Map<String, Import> importMap = new HashMap();
- importMap
- .put((FileUtils.getFileWithoutExtention(getFileName(fileFullName)).replaceAll("/", "_")), importObject);
- convertImport.add(importMap);
- }
-
- private static String getFileName(String relativeFileName) {
- if (relativeFileName.contains("../")) {
- return relativeFileName.replace("../", "");
- } else {
- return relativeFileName;
- }
-
- }
-
private static boolean isFile(String currentEntryName) {
return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/"));
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
index a915b9b131..f8e6759555 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
@@ -30,6 +30,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+
import org.apache.commons.io.IOUtils;
import org.hamcrest.core.StringContains;
import org.junit.Assert;
@@ -62,7 +63,6 @@ import org.onap.sdc.tosca.datatypes.model.Status;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.tosca.TestUtil;
@@ -1177,57 +1177,6 @@ public class ToscaAnalyzerServiceImplTest {
}
@Test
- public void testConvertToscaImport() throws Exception {
- String inputResourceName = "/mock/analyzerService/importConvertTest.yml";
- byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
-
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
- String convertServiceTemplateImport =
- toscaAnalyzerServiceImpl.convertServiceTemplateImport(toscaExtensionYamlUtil, uploadedFileData);
-
- Assert.assertNotNull(convertServiceTemplateImport);
- ServiceTemplate serviceTemplate =
- new YamlUtil().yamlToObject(convertServiceTemplateImport, ServiceTemplate.class);
- Assert.assertNotNull(serviceTemplate.getImports().get(0).get("data"));
- Assert.assertNotNull(serviceTemplate.getImports().get(1).get("artifacts"));
- Assert.assertNotNull(serviceTemplate.getImports().get(2).get("capabilities"));
- Assert.assertNotNull(serviceTemplate.getImports().get(3).get("api_interfaces"));
- Assert.assertNotNull(serviceTemplate.getImports().get(4).get("api_util_relationships"));
- Assert.assertNotNull(serviceTemplate.getImports().get(5).get("common"));
- Assert.assertNotNull(serviceTemplate.getImports().get(6).get("api_util"));
- Assert.assertNotNull(serviceTemplate.getImports().get(7).get("relationshipsExt"));
- }
-
- @Test
- public void testConvertToscaImportForEmptyImport() throws Exception {
- String inputResourceName = "/mock/analyzerService/importConvertTestNoImport.yml";
- byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
-
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
- String convertServiceTemplateImport =
- toscaAnalyzerServiceImpl.convertServiceTemplateImport(toscaExtensionYamlUtil, uploadedFileData);
-
- Assert.assertNotNull(convertServiceTemplateImport);
- ServiceTemplate serviceTemplate =
- new YamlUtil().yamlToObject(convertServiceTemplateImport, ServiceTemplate.class);
- Assert.assertNull(serviceTemplate.getImports());
- }
-
- @Test
- public void testInvalidToscaImportSection() throws Exception {
- thrown.expect(SdcRuntimeException.class);
- thrown.expectMessage("Invalid TOSCA import section");
- String inputResourceName = "/mock/analyzerService/invalidToscaImport.yml";
- byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));
-
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- ToscaAnalyzerServiceImpl toscaAnalyzerServiceImpl = new ToscaAnalyzerServiceImpl();
- toscaAnalyzerServiceImpl.convertServiceTemplateImport(toscaExtensionYamlUtil, uploadedFileData);
- }
-
- @Test
public void loadValidToscaYamlFileTest() throws Exception {
String inputResourceName = "/mock/analyzerService/ServiceTemplateInterfaceInheritanceTest.yaml";
byte[] uploadedFileData = IOUtils.toByteArray(this.getClass().getResource(inputResourceName));