diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-02-21 15:24:46 +0100 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-02-22 16:02:32 -0500 |
commit | 7353bcd8f2b85a50720b7cc7ca04c837c7b1796a (patch) | |
tree | 92a9c90b5852b3aea04da1526b5f81a1ec1b4223 /appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java | |
parent | 78cc8df2d203e32296e15e5564d9f809734c2e26 (diff) |
DGXML classes refactoring
Did some refactor in org.onap.sdnc.dg.loader package in order to reduce code duplication
Change-Id: I5c063487046c7ff72042d067213ea3d639a37227
Issue-ID: APPC-655
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java')
-rw-r--r-- | appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java | 78 |
1 files changed, 5 insertions, 73 deletions
diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java index 0b072c4a5..5aaf8bb6d 100644 --- a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java +++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java @@ -24,87 +24,19 @@ package org.onap.sdnc.dg.loader; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicParser; -import org.onap.ccsdk.sli.core.sli.SvcLogicStore; -import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DGXMLLoad { - private static final Logger logger = LoggerFactory.getLogger(DGXMLLoad.class); - public static final String STRING_ENCODING = "utf-8"; + private static final Logger logger = LoggerFactory.getLogger(DGXMLLoader.class); - private final SvcLogicStore store; - - public DGXMLLoad(String propfile) throws DGXMLException, SvcLogicException { - if (StringUtils.isBlank(propfile)) { - throw new DGXMLException(propfile + " Profile file is not defined"); - } - this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile); - } - - protected DGXMLLoad(SvcLogicStore store) { - this.store = store; - } - - public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException { - if (dgXMLpath != null) { - SvcLogicParser.load(dgXMLpath, this.store); - } - } - - private void loadDGXMLDir(String xmlPath) { - try { - logger.info( - "******************** Loading DG into Database *****************************"); - List<String> errors = new ArrayList<>(); - if (this.store != null) { - File xmlDir = new File(xmlPath); - if (xmlDir.isDirectory()) { - String[] extensions = new String[]{"xml", "XML"}; - List<File> files = (List<File>) FileUtils.listFiles(xmlDir, extensions, true); - tryLoadXmls(errors, files); - } else { - throw new DGXMLException(xmlPath + " is not a valid XML Directory"); - } - } else { - throw new DGXMLException("Failed to initialise SvcLogicStore"); - } - - if (!errors.isEmpty()) { - throw new DGXMLException(errors.toString()); - } - } catch (Exception e) { - logger.error("Failed to load DGXML directories", e); - } - } - - private void tryLoadXmls(List<String> errors, List<File> files) throws IOException { - for (File file : files) { - logger.info("Loading DG XML file :" + file.getCanonicalPath()); - try { - SvcLogicParser.load(file.getCanonicalPath(), store); - } catch (Exception e) { - logger.error("Failed to load XML " + file.getCanonicalPath(), e); - errors.add("Failed to load XML " + file.getCanonicalPath() - + ", Exception : " + e.getMessage()); - } - } - } + private DGXMLLoad(){} public static void main(String[] args) { try { String xmlPath; String propertyPath; - if (args != null && args.length >= 2) { xmlPath = args[0]; propertyPath = args[1]; @@ -112,10 +44,10 @@ public class DGXMLLoad { throw new DGXMLException( "Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <dbPropertyfile>"); } - DGXMLLoad dgXMLLoadDB = new DGXMLLoad(propertyPath); - dgXMLLoadDB.loadDGXMLDir(xmlPath); + DGXMLLoader loader = new DGXMLLoader(propertyPath); + loader.loadDGXMLDir(xmlPath); } catch (Exception e) { - logger.error("Arguments missing", e); + logger.error("Arguments missing", e); } finally { System.exit(1); } |