summaryrefslogtreecommitdiffstats
path: root/appc-directed-graph
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-16 14:05:43 +0100
committerPatrick Brady <pb071s@att.com>2018-02-19 22:40:10 +0000
commitfc59e7faae3cafbd7a5f9f107bbcda35fc490817 (patch)
tree90ea820c8d7b5abfc3cdcea81942eb8328bb601a /appc-directed-graph
parentbbda29c7e9f4960c65b6fe0b8cc2b266ba3d5dd0 (diff)
DGXMLLoad sonar fixes
Change-Id: I1e9965c8e5bd74f17fec1e47448af245b9b339c8 Issue-ID: APPC-642 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-directed-graph')
-rw-r--r--appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLException.java26
-rw-r--r--appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLLoad.java69
2 files changed, 64 insertions, 31 deletions
diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLException.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLException.java
new file mode 100644
index 000000000..d3c93acf2
--- /dev/null
+++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLException.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.dg.loader;
+
+class DGXMLException extends Exception{
+
+ DGXMLException(String message) {
+ super(message);
+ }
+}
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 115681574..0b072c4a5 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
@@ -25,30 +25,33 @@
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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
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 final static Logger logger = LoggerFactory.getLogger(DGXMLLoad.class);
+
+ private static final Logger logger = LoggerFactory.getLogger(DGXMLLoad.class);
+ public static final String STRING_ENCODING = "utf-8";
+
private final SvcLogicStore store;
- public static String STRING_ENCODING = "utf-8";
- public DGXMLLoad(String propfile) throws Exception {
+ public DGXMLLoad(String propfile) throws DGXMLException, SvcLogicException {
if (StringUtils.isBlank(propfile)) {
- throw new Exception(propfile + " Profile file is not defined");
+ throw new DGXMLException(propfile + " Profile file is not defined");
}
this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
}
- protected DGXMLLoad(SvcLogicStore store) throws Exception {
+ protected DGXMLLoad(SvcLogicStore store) {
this.store = store;
}
@@ -58,59 +61,63 @@ public class DGXMLLoad {
}
}
- private void loadDGXMLDir(String xmlPath) throws Exception {
+ private void loadDGXMLDir(String xmlPath) {
try {
logger.info(
- "******************** Loading DG into Database *****************************");
- List<String> errors = new ArrayList<String>();
+ "******************** 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"};
+ String[] extensions = new String[]{"xml", "XML"};
List<File> files = (List<File>) FileUtils.listFiles(xmlDir, extensions, true);
- for (File file : files) {
- logger.info("Loading DG XML file :" + file.getCanonicalPath());
- try {
- SvcLogicParser.load(file.getCanonicalPath(), this.store);
- } catch (Exception e) {
- errors.add("Failed to load XML " + file.getCanonicalPath()
- + ", Exception : " + e.getMessage());
- }
- }
+ tryLoadXmls(errors, files);
} else {
- throw new Exception(xmlPath + " is not a valid XML Directory");
+ throw new DGXMLException(xmlPath + " is not a valid XML Directory");
}
} else {
- throw new Exception("Failed to initialise SvcLogicStore");
+ throw new DGXMLException("Failed to initialise SvcLogicStore");
}
- if (errors.size() > 0) {
- throw new Exception(errors.toString());
+ if (!errors.isEmpty()) {
+ throw new DGXMLException(errors.toString());
}
} catch (Exception e) {
- logger.error(e.getMessage());
+ 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());
+ }
}
}
public static void main(String[] args) {
try {
- String xmlPath = null;
- String propertyPath = null;
+ String xmlPath;
+ String propertyPath;
if (args != null && args.length >= 2) {
xmlPath = args[0];
propertyPath = args[1];
} else {
- throw new Exception(
- "Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <dbPropertyfile>");
+ throw new DGXMLException(
+ "Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <dbPropertyfile>");
}
DGXMLLoad dgXMLLoadDB = new DGXMLLoad(propertyPath);
dgXMLLoadDB.loadDGXMLDir(xmlPath);
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("Arguments missing", e);
} finally {
System.exit(1);
}
}
-
}