From 56c184e1622436654d9f12b1098a8020a6323a3a Mon Sep 17 00:00:00 2001 From: AvinashS Date: Mon, 18 Sep 2017 12:55:57 +0000 Subject: Instantiate validation with path To populate csar files during object creation. Change-Id: I66b5cf8b46f98990240e9cc470eff6a8874f3de0 IssueId: VNFSDK-90 Signed-off-by: AvinashS --- .../java/org/onap/validation/csar/CsarParser.java | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'csarvalidation/src/main/java') diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java index 410562c..76a7b11 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarParser.java @@ -41,6 +41,23 @@ public class CsarParser { private static HashMap> csar = new HashMap>(); private static final CsarUtil cUtil = new CsarUtil(); + + public CsarParser(String csarWithPath) { + + try { + FileInputStream is = new FileInputStream(csarWithPath); + } catch (FileNotFoundException e2) { + LOG.error("CSAR %s is not found! ", e2); + } + try { + boolean ret = csarExtract(csarWithPath); + if(ret == true) { + LOG.debug("CSAR extracted sucessfully."); + } + } catch (Exception e1) { + LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); + } + } /* * pubic static boolean validateCsar(String filePath) { * @@ -74,13 +91,15 @@ public class CsarParser { } } - public static boolean csarExtract(String filePath) { + private static boolean csarExtract(String filePath) { try { String tempfolder = CsarUtil.getUnzipDir(filePath); csarFiles = CsarUtil.unzip(filePath, tempfolder); + } catch (IOException e1) { LOG.error("CSAR extraction error ! " + e1.getMessage()); + return false; } return true; @@ -118,22 +137,24 @@ public class CsarParser { return false; } } - - } - reader.close(); + } + reader.close(); + return true; } } catch (IOException e2) { - e2.printStackTrace(); - return false; + LOG.error("Exception cought while validateCsarMeta ! " + e2.getMessage()); + //e2.printStackTrace(); + } finally { if (reader != null) { try { reader.close(); + } catch (IOException e1) { LOG.error("close reader failed ! " + e1.getMessage()); } } - return true; + } } @@ -145,7 +166,7 @@ public class CsarParser { String cfile = csarFiles.get(CommonConstants.TOSCA_META); try { - if (!cfile.isEmpty() && cfile.contains("/" + CommonConstants.TOSCA_METADATA + "/" + CommonConstants.TOSCA_META)) { + if (!cfile.isEmpty() && cfile.contains( System.getProperty("file.separator")+ CommonConstants.TOSCA_METADATA + System.getProperty("file.separator") + CommonConstants.TOSCA_META)) { String value = checkEntryFor("Entry-Definitions:", cfile); if (value == null) { -- cgit 1.2.3-korg