From b917a4cc7336d1f1b1e51f516e7927fb9227298b Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Tue, 4 Sep 2018 17:19:35 +0530 Subject: VTP: Fix validation logic Fails to validate the metadata. Change-Id: I47d3ead452a3e55f18d7b16d1918727974c19fbc Issue-ID: VNFSDK-305 Signed-off-by: Kanagaraj Manickam k00365106 --- .../validation/csar/ValidatorSchemaLoader.java | 78 ++++++---------------- 1 file changed, 20 insertions(+), 58 deletions(-) (limited to 'csarvalidation/src/main/java/org/onap') 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 a33fe93..eb9c9da 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java @@ -71,63 +71,29 @@ public class ValidatorSchemaLoader { } } + private Map readYaml(String fileName) { + Yaml yaml = new Yaml(); + return (Map)yaml.load(this.getClass().getResourceAsStream(fileName)); + } + @SuppressWarnings("unchecked") private boolean loadResources() throws FileNotFoundException, URISyntaxException { - URL schemafolder = this.getClass().getClassLoader().getResource("schema"); - try (Stream paths = Files.walk(Paths.get(schemafolder.toURI()))) { - - paths.filter(Files::isRegularFile).forEach((Path e) -> { - - File file = e.toFile(); - - if(!file.isDirectory() && (FilenameUtils.isExtension(file.getName(), "yaml") - || FilenameUtils.isExtension(file.getName(), "mf") - || FilenameUtils.isExtension(file.getName(), "meta"))) { - - Yaml yaml = new Yaml(); - - switch(file.getName()) { - case "TOSCA.meta": - 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(), - 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(), - 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(), - 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(), - e2); - } - break; - } - } - schemaFileList.add(e.toAbsolutePath().toString()); - }); - - } catch(NullPointerException | IOException err) { - LOG.error("Schema files/folder access error" + err); + for (String metaFile: new String []{"TOSCA.meta", "CSAR.meta", "MRF.mf" }) { + switch(metaFile) { + case "TOSCA.meta": + toscaMeta = this.readYaml("/schema/" + metaFile); + break; + case "CSAR.meta": + csarentryd = this.readYaml("/schema/" + metaFile); + break; + case "MRF.yaml": + mrfYaml = this.readYaml("/schema/" + metaFile); + break; + case "MRF.mf": + mrfManifest = this.readYaml("/schema/" + metaFile); + break; + } } - return true; } @@ -146,8 +112,4 @@ public class ValidatorSchemaLoader { public Map getMrfManifest() { return mrfManifest; } - - public List getSchemaFileList() { - return schemaFileList; - } } -- cgit 1.2.3-korg