aboutsummaryrefslogtreecommitdiffstats
path: root/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java
diff options
context:
space:
mode:
authorSkip Wonnell <kw5258@att.com>2017-08-28 22:02:54 -0500
committerSkip Wonnell <kw5258@att.com>2017-08-28 22:44:49 -0500
commit574417bd1d70e30e7074f7f3375ea443b44740ab (patch)
treeafd17b4edcb4ea0261caa5c44a49d94b6737ed4e /appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java
parentd0bcf2eca3ff91fa69b20aabc8b6c57b789fb0ff (diff)
Clean up directed graph java code
Issue-ID: APPC-90 Change-Id: I3ea4912523eed1fed85aa2e5909ec897bb13b72b Signed-off-by: Skip Wonnell <kw5258@att.com>
Diffstat (limited to 'appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java')
-rw-r--r--appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java173
1 files changed, 85 insertions, 88 deletions
diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java
index 1cb446a83..b37400ba7 100644
--- a/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java
+++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/openecomp/sdnc/dg/loader/DGXMLActivate.java
@@ -36,93 +36,90 @@ import org.slf4j.LoggerFactory;
public class DGXMLActivate {
- private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
- private final SvcLogicStore store;
- public static String STRING_ENCODING = "utf-8";
-
- public DGXMLActivate(String propfile) throws Exception{
- if(StringUtils.isBlank(propfile)){
- throw new Exception(propfile + " Profile file is not defined");
- }
- this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
- }
-
-
- public void activateDg(String activateFilePath) throws Exception {
- logger.info("******************** Activating DG into Database *****************************");
- try {
- List<String> errors = new ArrayList<String>();
- if(this.store != null){
- File activateFile = new File(activateFilePath);
- if(activateFile != null && activateFile.isFile()){
- List<String> fileLines = FileUtils.readLines(activateFile,STRING_ENCODING);
- if(fileLines != null ){
- for (String line : fileLines) {
- if(line != null && ! line.trim().startsWith("#")){
- String lineArray[] = line.trim().split(":");
- try {
- if(lineArray != null && lineArray.length >= 4){
- String module = lineArray[0];
- String rpc = lineArray[1];
- String version = lineArray[2];
- String mode = lineArray[3];
- if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc)
- && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){
- logger.info("Activating DG :" + line);
- SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode);
- if(graph != null){
- logger.info("Found Graph :" + line + " Activating ...");
- this.store.activate(graph);
- }else{
- throw new Exception("Failed to fetch from Database");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- errors.add("Failed to Activate "+line + ", "+e.getMessage());
- }
- }
- }
- }
- }else{
- throw new Exception(activateFile + " is not a valid Activate file Path");
- }
- }else{
- throw new Exception("Failed to initialise SvcLogicStore");
- }
-
- if(errors.size() > 0){
- throw new Exception(errors.toString());
- }
- } catch (Exception e) {
- logger.error(e.getMessage());
- }
- }
-
-
- public static void main(String[] args) {
- try {
-
- String activateFile = null;
- String propertyPath = null;
-
- if(args != null && args.length >= 2){
- activateFile = args[0];
- propertyPath = args[1];
- }else{
- throw new Exception("Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
- }
-
- DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
- dgXmlActivate.activateDg(activateFile);
- } catch (Exception e) {
- e.printStackTrace();
- }finally {
- System.exit(1);
- }
- }
-
-
+ private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
+ private final SvcLogicStore store;
+ public static String STRING_ENCODING = "utf-8";
+
+ public DGXMLActivate(String propfile) throws Exception{
+ if(StringUtils.isBlank(propfile)){
+ throw new Exception(propfile + " Profile file is not defined");
+ }
+ this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
+ }
+
+
+ public void activateDg(String activateFilePath) throws Exception {
+ logger.info("******************** Activating DG into Database *****************************");
+ try {
+ List<String> errors = new ArrayList<String>();
+ if(this.store != null){
+ File activateFile = new File(activateFilePath);
+ if(activateFile != null && activateFile.isFile()){
+ List<String> fileLines = FileUtils.readLines(activateFile,STRING_ENCODING);
+ if(fileLines != null ){
+ for (String line : fileLines) {
+ if(line != null && ! line.trim().startsWith("#")){
+ String lineArray[] = line.trim().split(":");
+ try {
+ if(lineArray != null && lineArray.length >= 4){
+ String module = lineArray[0];
+ String rpc = lineArray[1];
+ String version = lineArray[2];
+ String mode = lineArray[3];
+ if(StringUtils.isNotBlank(module) && StringUtils.isNotBlank(rpc)
+ && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(mode)){
+ logger.info("Activating DG :" + line);
+ SvcLogicGraph graph = this.store.fetch(module, rpc, version, mode);
+ if(graph != null){
+ logger.info("Found Graph :" + line + " Activating ...");
+ this.store.activate(graph);
+ }else{
+ throw new Exception("Failed to fetch from Database");
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ errors.add("Failed to Activate "+line + ", "+e.getMessage());
+ }
+ }
+ }
+ }
+ }else{
+ throw new Exception(activateFile + " is not a valid Activate file Path");
+ }
+ }else{
+ throw new Exception("Failed to initialise SvcLogicStore");
+ }
+
+ if(errors.size() > 0){
+ throw new Exception(errors.toString());
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage());
+ }
+ }
+
+
+ public static void main(String[] args) {
+ try {
+ String activateFile = null;
+ String propertyPath = null;
+
+ if(args != null && args.length >= 2){
+ activateFile = args[0];
+ propertyPath = args[1];
+ }else{
+ throw new Exception("Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
+ }
+
+ DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
+ dgXmlActivate.activateDg(activateFile);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }finally {
+ System.exit(1);
+ }
+ }
}