script to import multiple dgs 43/20643/1
authorSheshi Chinthakayala <sc2914@att.com>
Wed, 25 Oct 2017 22:53:03 +0000 (17:53 -0500)
committerSheshi Chinthakayala <sc2914@att.com>
Wed, 25 Oct 2017 22:55:49 +0000 (17:55 -0500)
into the dgbuilder. The script appends the dgs to flows.json which is used by the dgbuilder.

Issue-ID:CCSDK-130

Change-Id: Ide3842299832cf125b8129d268e6d8527ca4c5c6
Signed-off-by: Sheshi Chinthakayala <sc2914@att.com>
dgbuilder/tools/multiple_dg_load.js [new file with mode: 0644]
dgbuilder/tools/multiple_dg_load.sh [new file with mode: 0755]

diff --git a/dgbuilder/tools/multiple_dg_load.js b/dgbuilder/tools/multiple_dg_load.js
new file mode 100644 (file)
index 0000000..8640667
--- /dev/null
@@ -0,0 +1,115 @@
+
+var fs = require('fs');
+var obj =[];
+try{
+ obj = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
+}catch(err){
+}
+var dirPath=process.argv[3];
+console.log(dirPath);
+function getID() {
+        return (1+Math.random()*4294967295).toString(16);
+}
+
+var filteredArray = obj.filter(function(itm){
+  return itm.type == 'tab' ;
+});
+
+var tabsArr=filteredArray;
+ var files = fs.readdirSync(dirPath);
+    for (var i in files) {
+       var currentFile = dirPath + '/' + files[i];
+       //console.log(currentFile);
+       var stats = fs.statSync(currentFile);
+try{
+       if (stats.isFile()) {
+               var moduleName="";
+               var methodName="";
+               console.log("processing... " + currentFile);
+               var o = JSON.parse(fs.readFileSync(currentFile, 'utf8'));
+               for(var idx in o){
+                       if(o[idx].type == "service-logic"){
+                               moduleName=o[idx].name;
+                       } 
+                       if(o[idx].type == "method"){
+                               methodName=o[idx].name;
+                               methodName = methodName.replace("method ","");
+                       } 
+                       if(moduleName != "" && methodName != ""){
+                               break;
+                       }
+               }
+               var id  = o[0].z;
+               //console.log("tab id:" + id);
+               var newId = id;
+               var number_of_tabs = 0;
+               if(filteredArray != null ){
+                number_of_tabs = filteredArray.length;
+               }
+               //console.log("number_of_tabs:" + number_of_tabs);
+               //console.log("id:" + id);
+               if(filteredArray != null  && filteredArray.length > 0){
+                       for(var i in filteredArray){
+                               if(filteredArray[i].id == id){
+                                       newId = getID();        
+                                       console.log("Using new id:" + newId);
+                               }
+                       }
+                       for(var idx in o){
+                               o[idx].z= newId;
+                               var oldNodeId = o[idx].id;
+                               var newNodeId = getID();
+                               o[idx].id= newNodeId;
+                               for(var k=0;k<o.length;k++){
+                                       if(o[k] != null && o[k].wires != undefined && o[k].wires != null){      
+                                               for(var j=0;o[k].wires[0] != null && j< o[k].wires[0].length;j++){
+                                                       if(o[k].wires[0][j] == oldNodeId){
+                                                               o[k].wires[0][j]=newNodeId;
+                                                       }
+                                                       
+                                               }       
+                                       }
+                               }
+                       }
+               }
+                       //"label": "Sheet " + (number_of_tabs + 1),
+               var tabObj= {
+                       "id": newId,
+                       "label": methodName,
+                       "type": "tab"
+               };
+       
+               filteredArray.push(tabObj);
+               obj.unshift(tabObj);
+               for(var idx in o){
+                       obj.push(o[idx]);
+               }
+               //console.dir(obj);
+       }
+}catch(err){
+       console.log(err);
+}
+};
+function getCurrentDate(){
+                var d = new Date();
+                var mm = d.getMonth() + 1;
+                var dd =   d.getDate();
+                var yyyy = d.getYear() + 1900;
+                var hr = d.getHours();
+                var min = d.getMinutes();
+                var sec = d.getSeconds();
+                if(mm<10) mm = "0" + mm;
+                if(dd<10) dd = "0" + dd;
+                if(hr<10) hr = "0" + hr;
+                if(min<10) min = "0" + min;
+                if(sec<10) sec = "0" + sec;
+                var formatedValue = mm + "-" + dd + "-" + yyyy + "_" + hr + "" + min + "" + sec;
+                return formatedValue;
+        }
+if (fs.existsSync(process.argv[2])) {
+       fs.renameSync(process.argv[2],process.argv[2]+ "_" + getCurrentDate());
+}
+fs.writeFileSync( process.argv[2] + ".new", JSON.stringify(obj));
+if (fs.existsSync(process.argv[2] + ".new")) {
+       fs.renameSync(process.argv[2] + ".new",process.argv[2]);
+}
diff --git a/dgbuilder/tools/multiple_dg_load.sh b/dgbuilder/tools/multiple_dg_load.sh
new file mode 100755 (executable)
index 0000000..ca74355
--- /dev/null
@@ -0,0 +1,6 @@
+if [ "$#" != "2" ]
+then
+       echo "Usage:$0 full_path_to_flows.json full_path_to_the_files_directory"
+       exit
+fi
+node multiple_dg_load.js $1 $2

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use