diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main')
-rw-r--r-- | openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java | 69 |
1 files changed, 2 insertions, 67 deletions
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("/")); } |