From 1a64c83fc436e17f93e468f7d46ff9f5fcb081ce Mon Sep 17 00:00:00 2001 From: vasraz Date: Fri, 7 Feb 2020 10:14:06 +0000 Subject: Add support for simple yaml profile 1.2 Change-Id: I735d25c6b6c3344c4b742f09b3aeaf4d03c2d17c Signed-off-by: Vasyl Razinkov Issue-ID: SDC-2738 --- .../sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java | 5 +++-- .../tosca/services/impl/ToscaValidationServiceImpl.java | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-lib') 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 1bc547aed7..3ce9badea0 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 @@ -56,6 +56,7 @@ import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.SdcRuntimeException; import org.openecomp.sdc.common.zip.ZipUtils; @@ -192,8 +193,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService { } private boolean isToscaYamlFile(byte[] fileContent) { - Map fileMap = new YamlUtil().yamlToObject(new String(fileContent), Map.class); - return fileMap.containsKey("tosca_definitions_version"); + final Map fileMap = new YamlUtil().yamlToObject(new String(fileContent), Map.class); + return fileMap.containsKey(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()); } private void updateMinMaxOccurencesForNodeTypeRequirement(Map.Entry entry, diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java index 0394073e57..9f3dd0790f 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaValidationServiceImpl.java @@ -26,6 +26,7 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.logging.api.Logger; @@ -55,7 +56,6 @@ public class ToscaValidationServiceImpl implements ToscaValidationService { private static final String SDCPARSER_JTOSCA_VALIDATIONISSUE_CONFIG = "SDCParser_jtosca-validation-issue-configuration.yaml"; private static final String SDCPARSER_ERROR_CONFIG = "SDCParser_error-configuration.yaml"; - private static final String TOSCA_DEFINITION_VERSION = "tosca_definitions_version"; static { // Override default SDC Parser configuration @@ -119,17 +119,17 @@ public class ToscaValidationServiceImpl implements ToscaValidationService { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - private boolean isToscaYaml(String filePath) { + private boolean isToscaYaml(final String filePath) { boolean retValue = false; - try (InputStream input = new BufferedInputStream(new FileInputStream(new File(filePath)));) { - Yaml yaml = new Yaml(); - LinkedHashMap data = (LinkedHashMap) yaml.load(input); - if(data.get(TOSCA_DEFINITION_VERSION) != null) { + try (final InputStream input = new BufferedInputStream(new FileInputStream(new File(filePath)));) { + final Yaml yaml = new Yaml(); + final LinkedHashMap data = (LinkedHashMap) yaml.load(input); + if(data.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName()) != null) { retValue = true; } } - catch(Exception e){ + catch(final Exception e){ LOGGER.info("Ignore the exception as the input file may not be a Tosca Yaml; let the " + "default value return", e); } -- cgit 1.2.3-korg