From 8f6a6c445eaeb7356e1db9d10d10b7d3fa42f27e Mon Sep 17 00:00:00 2001 From: "Chinthakayala,Sheshashailavas(sc2914)" Date: Wed, 27 Jun 2018 16:11:44 +0000 Subject: removed dependency on built-editor.min.js and added ability to test DG from dgbuilder and fixed the break node on XML generation and added ability to download formatted DG XML and DG JSON Issue-ID: SDNC-353 Change-Id: I799de5de2c4f61e9b56dbe996d8ac3e3b28061f7 Signed-off-by: Chinthakayala,Sheshashailavas(sc2914) --- dgbuilder/red/server.js | 155 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 150 insertions(+), 5 deletions(-) (limited to 'dgbuilder/red') diff --git a/dgbuilder/red/server.js b/dgbuilder/red/server.js index 91bee453..c0a5125d 100644 --- a/dgbuilder/red/server.js +++ b/dgbuilder/red/server.js @@ -563,17 +563,26 @@ function createServer(_server,_settings) { //console.log("fileName:" + fileName); var renameFilePath = sharedDir + "/backups/" + renameOldfileTo; //console.log("localfile:" + localfile); - fs.rename(file,renameFilePath, function (err) { - if(err){ - console.log('Error :' + err); - } + if (fs.existsSync(file)) { + fs.rename(file,renameFilePath, function (err) { + if(err){ + console.log('Error :' + err); + } + //write the newer version + writeToFile(file,jsonStr); + res.setHeader('Content-disposition', 'attachment; filename=' + fileName); + res.setHeader('Content-type', 'application/json'); + //res.download(file); + res.end(jsonStr); + }); + }else{ //write the newer version writeToFile(file,jsonStr); res.setHeader('Content-disposition', 'attachment; filename=' + fileName); res.setHeader('Content-type', 'application/json'); //res.download(file); res.end(jsonStr); - }); + } } }); }); @@ -930,12 +939,19 @@ function createServer(_server,_settings) { var dbPassword = post["dbPassword"]; var gitLocalRepository = post["gitLocalRepository"]; var performGitPull = post["performGitPull"]; + var restConfUrl = post["restConfUrl"]; + var restConfUser = post["restConfUser"]; + var restConfPassword = post["restConfPassword"]; + var emailAddress = post["emailAddress"]; + var formatXML = post["formatXML"]; + var formatJSON = post["formatJSON"]; var appDir = path.dirname(require.main.filename); var userDir = appDir + "/" + settings.userDir; console.log("userDir:" + userDir); try{ var settingsFile = userDir + "/customSettings.js"; var jsonObj = require(settingsFile); + jsonObj.emailAddress = emailAddress; jsonObj.flowFile = jsonObj.flowFile.replace(appDir + "/",''); jsonObj.dbHost = dbHost; jsonObj.dbPort = dbPort; @@ -944,6 +960,11 @@ function createServer(_server,_settings) { jsonObj.dbPassword = dbPassword; jsonObj.gitLocalRepository = gitLocalRepository; jsonObj.performGitPull = performGitPull; + jsonObj.restConfUrl = restConfUrl; + jsonObj.restConfUser = restConfUser; + jsonObj.restConfPassword = restConfPassword; + jsonObj.formatXML = formatXML; + jsonObj.formatJSON = formatJSON; var updatedSettings = jsonObj; var settingsStr= "module.exports=" + JSON.stringify(updatedSettings,null,4); @@ -1135,6 +1156,130 @@ function createServer(_server,_settings) { }); }); }); + + function getFormattedDate(){ + 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 = yyyy + "-" + mm + "-" + dd + "_" + hr + ":" + min + ":" + sec; + return formatedValue; + } + + + app.post("/saveTestDGInput", + express.json({'limit':'16mb'}), + function(req,res) { + var qs = require('querystring'); + var body = ''; + req.on('data', function (data) { + body += data; + }); + req.on('end', function () { + var appDir = path.dirname(require.main.filename); + var inputFilesDir = appDir + "/" + "inputFiles"; + if (!fs.existsSync(inputFilesDir)){ + fs.mkdirSync(inputFilesDir); + } + var post = qs.parse(body); + var moduleName = post['moduleName']; + var rpcName = post['rpcName']; + var fullFileName = inputFilesDir + "/" +moduleName + "_" + rpcName + "_" + getFormattedDate(); + var inputStr = post['inputStr']; + writeToFile(fullFileName,inputStr); + res.end(); + }); + }); + + app.post("/getInputFiles",function(req,res) { + var qs = require('querystring'); + var body = ''; + req.on('data', function (data) { + body += data; + }); + req.on('end', function () { + var appDir = path.dirname(require.main.filename); + var inputFilesDir = appDir + "/" + "inputFiles"; + if (!fs.existsSync(inputFilesDir)){ + fs.mkdirSync(inputFilesDir); + } + var post = qs.parse(body); + var moduleName = post['moduleName']; + var rpcName = post['rpcName']; + var glob = require("glob"); + var filePatt = "/**/" + moduleName + "_" + rpcName + "*"; + glob(inputFilesDir + filePatt, null, function (er, files) { + var filesList =[]; + for(var i=0;files!= null && i