From 7a919528f28ee9fa95580312af160c649ca58a51 Mon Sep 17 00:00:00 2001 From: AvinashS Date: Thu, 2 Nov 2017 18:07:42 +0530 Subject: Fix sonar issues Fix new blocker and criticals Change-Id: I43536f95e869477cc5b44ad8553d2f49e5464723 Issue-Id: VNFSDK-117 Signed-off-by: AvinashS --- .../org/onap/validation/csar/CsarValidator.java | 5 ++- .../validation/csar/ValidatorSchemaLoader.java | 41 +++++++++++----------- 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'csarvalidation') diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java index f1c1a1e..a286665 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -228,7 +228,7 @@ public class CsarValidator { } } } catch (IOException | NullPointerException e) { - LOG.error("CSAR_TOSCA_VALIDATION" + ":" + "Could not read file %s ! " +ErrorCodes.FILE_IO+ " " +ErrorCodes.RESOURCE_MISSING); + LOG.error("CSAR_TOSCA_VALIDATION" + ":" + "Could not read file %s ! " +ErrorCodes.FILE_IO+ " " +ErrorCodes.RESOURCE_MISSING,e); throw new ValidationException(ErrorCodes.RESOURCE_MISSING); } @@ -359,7 +359,10 @@ public class CsarValidator { } catch (FileNotFoundException e) { LOG.error("CSAR_TOSCA_LOAD" + ":" + "TOSCA metadata is not loaded by Yaml! " +ErrorCodes.FILE_IO, e); } + if(toscaMeta != null){ return toscaMeta.keySet().containsAll((vsl.getToscaMeta().keySet())); + } + return false; } } diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java index 7d9c8c1..7731801 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java @@ -23,6 +23,8 @@ import org.slf4j.LoggerFactory; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.stream.Stream; + import org.apache.commons.io.FilenameUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.scanner.ScannerException; @@ -36,10 +38,10 @@ public class ValidatorSchemaLoader { private static final Logger LOG = LoggerFactory.getLogger(ValidatorSchemaLoader.class); // Map of Schema files - private static Map toscaMeta; - private static Map csarentryd; - private static Map mrfYaml; - private static Map mrfManifest; + private Map toscaMeta; + private Map csarentryd; + private Map mrfYaml; + private Map mrfManifest; // List of configured schemas static List schemaFileList = new ArrayList(); @@ -49,13 +51,13 @@ public class ValidatorSchemaLoader { static HashMap optionTwoSchema; private String schema_folder; - public ValidatorSchemaLoader() throws Exception { + public ValidatorSchemaLoader() throws NullPointerException, FileNotFoundException, ScannerException, IOException { try { loadResources(); } catch ( FileNotFoundException e1) { - LOG.error("Schema file not found or schema repository corrupted"); + LOG.error("Schema file not found or schema repository corrupted", e1); } } @@ -63,12 +65,11 @@ public class ValidatorSchemaLoader { @SuppressWarnings("unchecked") private boolean loadResources() throws FileNotFoundException { - - try { - String schema_folder = getClass().getResource("../../../../schema").getPath(); + String schema_folder = getClass().getResource("../../../../schema").getPath(); + try (Stream paths = Files.walk(Paths.get(schema_folder))){ + - Files.walk(Paths.get(schema_folder)) - .filter(Files::isRegularFile) + paths.filter(Files::isRegularFile) .forEach((Path e) -> { File file = e.toFile(); @@ -85,28 +86,28 @@ public class ValidatorSchemaLoader { try { toscaMeta = (Map) yaml.load(new FileInputStream(file)); } catch (ScannerException | FileNotFoundException e1) { - LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + LOG.error("Schema files %s format is not as per standard prescribed", file.getName(), e1); } break; case "CSAR.meta": try { csarentryd = (Map) yaml.load(new FileInputStream(file)); } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + LOG.error("Schema files %s format is not as per standard prescribed", file.getName(), e2); } break; case "MRF.yaml": try { mrfYaml = (Map) yaml.load(new FileInputStream(file)); } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + LOG.error("Schema files %s format is not as per standard prescribed", file.getName(), e2); } break; case "MRF.mf": try { mrfManifest = (Map) yaml.load(new FileInputStream(file)); } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + LOG.error("Schema files %s format is not as per standard prescribed", file.getName(), e2); } break; } @@ -121,23 +122,23 @@ public class ValidatorSchemaLoader { return true; } - public static Map getToscaMeta() { + public Map getToscaMeta() { return toscaMeta; } - public static Map getCsarentryd() { + public Map getCsarentryd() { return csarentryd; } - public static Map getMrfYaml() { + public Map getMrfYaml() { return mrfYaml; } - public static Map getMrfManifest() { + public Map getMrfManifest() { return mrfManifest; } - public static List getSchemaFileList() { + public List getSchemaFileList() { return schemaFileList; } } \ No newline at end of file -- cgit 1.2.3-korg