/**
 * Copyright 2013 IBM Corp.
 *
 * 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.
 **/

var express = require('express');
var util = require('util');
var multer = require('multer');
var when = require('when');
var exec = require('child_process').exec;

var createUI = require("./ui");
var redNodes = require("./nodes");
var comms = require("./comms");
var storage = require("./storage");
var fs=require('fs');
var path = require("path");
var app = null;
var nodeApp = null;
var server = null;
var settings = null;

var flowShareUsers = require("../flowShareUsers");
	
//console.dir(flowShareUsers);

function createServer(_server,_settings) {
    server = _server;
    settings = _settings;

    comms.init(_server,_settings);
    
    nodeApp = express();
    app = express();
        
    if (settings.httpAdminRoot !== false) {
        
        
        if (!settings.disableEditor) {
            createUI(settings,app);
        }
        
	var slaActions = require("./sla");

        app.get("/flows",function(req,res) {
            res.json(redNodes.getFlows());
        });

        app.get("/loadJSFiles",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var generatedJSDir=appDir + "/generatedJS";
		var glob = require("glob")
		glob(generatedJSDir + "/**/*.js", null, function (er, files) {
			  // files is an array of filenames.
			 // If the `nonull` option is set, and nothing
  			// was found, then files is ["**/*.js"]
  			// er is an error object or null.
			//console.dir(files);
			var sliValuesObj =[];
			for(var i=0;files!= null && i<files.length;i++){
				var f = files[i].replace( new RegExp(generatedJSDir + "/", "g" ), "" );
				console.log("loading file " + f);
				try{
					sliValuesObj.push(require(files[i]));
					//console.dir(sliValuesObj);
				}catch(err){
					console.log("Error:Could not load file " + files[i]);
				}
			}
			res.json({"sliValuesObj" : sliValuesObj});
        	});
        });

        app.get("/loadSelectedModules",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var generatedJSDir=appDir + "/generatedJS";
		//console.dir(req);
		var selectedModulesStr = req.query.selectedModules;
		var selectedModules = [];
		if(selectedModulesStr != undefined && selectedModulesStr != null){ 
		 	selectedModules = selectedModulesStr.split(",");		
		}
		console.log(selectedModules);
		var loaded_modules = {"selected_modules" :selectedModules};
		var file = userDir + "/selected_modules";
		var content = "module.exports=\n" + JSON.stringify(loaded_modules);
		try{
			fs.writeFileSync(file, content, 'utf8');
		}catch(err){
			console.log("could not write to file " + file);
		}
		var sliValuesObj =[];
		for(var i=0;selectedModules!= null && i<selectedModules.length;i++){
			var f = generatedJSDir + "/" + selectedModules[i] + "_inputs.js";
			try{
				delete require.cache[require.resolve(f)]
				require.resolve();
			}catch(err){
				console.log("error deleting loaded module " + f + " from cache");
			}
			//console.log("loading file " + f);
			try{
				sliValuesObj.push(require(f));
			}catch(err){
				console.log("Error:Could not load file " + f);
			}
		}
		//console.dir(sliValuesObj);
		res.json({"sliValuesObj" : sliValuesObj});
        });

        app.get("/initialLoadSelectedModules",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var generatedJSDir=appDir + "/generatedJS";
		var file = userDir + "/selected_modules";
		var sliValuesObj =[];
		var selected_modules = [];
		var selectedModules;
		try{
			selectedModules = require(file);	
			selected_modules=selectedModules["selected_modules"];
			//console.log("selected_modules are ");
			//console.dir(selected_modules);
		}catch(err){
			console.log("Could not load the file " + file);
		}
		for(var i=0;selected_modules!= null && i<selected_modules.length;i++){
			var f = generatedJSDir + "/" + selected_modules[i] + "_inputs.js";
			console.log("loading file " + f);
			try{
				sliValuesObj.push(require(f));
			}catch(err){
				console.log("Error:Could not load file " + f);
			}
		}
		res.json({"sliValuesObj" : sliValuesObj});
        });

        app.get("/listAvailableModules",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var generatedJSDir=appDir + "/generatedJS";
		var glob = require("glob")
		var file = userDir + "/selected_modules";
		var selected_modules = [];
		var selectedModules;
		try{
			delete require.cache[require.resolve(file)]
			require.resolve();
		}catch(err){
			console.log("error deleting loaded module " + file + " from cache");
		}
		try{
			selectedModules = require(file);	
			selected_modules=selectedModules["selected_modules"];
			console.log("selected_modules are ");
			//console.dir(selected_modules);
		}catch(err){
			console.log("Could not load the file " + file);
		}
		glob(generatedJSDir + "/**/*.js", null, function (er, files) {
			var filesList =[];
			for(var i=0;files!= null && i<files.length;i++){
				var f = files[i].replace( new RegExp(generatedJSDir + "/", "g" ), "" );
				f = f.replace("_inputs.js","");
				if(selected_modules != undefined && selected_modules != null && selected_modules.indexOf(f) != -1){
					filesList.push(f + ":checked");
				}else{
					filesList.push(f + ":unchecked");
				}
			}
			res.json({"files" : filesList});
		});
        });

        app.get("/listSLA",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
                slaActions.listSLA(jsonObj,req,res);
        });

        app.get("/listCurrentDGs",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
                slaActions.listCurrentDGs(jsonObj,req,res);
        });

        app.get("/activateDG",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
            slaActions.activateDG(jsonObj,req,res);
        });

        app.get("/deActivateDG",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
            slaActions.deActivateDG(jsonObj,req,res);
        });

        app.get("/deleteDG",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
            slaActions.deleteDG(jsonObj,req,res);
        });

        app.get("/getCurrentSettings",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		//console.log("userDir:" + userDir);
		var settingsFile = userDir + "/customSettings.js"; 
		var jsonObj = require(settingsFile);
            	res.json(jsonObj);
        });

        app.get("/getCommitsInfo", function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		//console.dir(req);
                var filePath = req.query.filePath;
                var fullFilePath = userDir + "/codecloud/" + filePath ;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitlog " + fullFilePath ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,function (error,stdout,stderr){
                if(error){
			console.log("Error occured:" + error);
			if(stderr){
				//console.log("stderr:" + stderr);
				res.send(500,{'error':error,'stderr':stderr});
			}else{
				res.send(500,{'error':error});
			}
			//console.log("stdout :" + stdout);
                }else{
			if(stderr){
				console.log("stderr:" + stderr);
			}
			if(stdout){
				//console.log("output:" + stdout);
				res.send(200,{'stdout':stdout,'stderr':stderr});
                	}
		}
		});
	});

        app.get("/importCodeCloudFlow",
		 function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		//console.dir(req);
                var commitId = req.query.commitId;
                var filePath = req.query.filePath;
                var fullFilePath = userDir + "/codecloud/" + filePath ;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitckout " + commitId + " " + fullFilePath ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,{maxBuffer: 1024 * 1024 * 16}, function (error,stdout,stderr){
                if(error){
			console.log("Error occured:" + error);
			if(stderr){
				//console.log("stderr:" + stderr);
				res.send(500,{'error':error,'stderr':stderr});
			}else{
				res.send(500,{'error':error});
			}
                }else{
			if(stderr){
				console.log("stderr:" + stderr);
			}
			if(stdout){
				//console.log("output:" + stdout);
				res.send(200,{'stdout':stdout,'stderr':stderr});
                	}
		}
		});
	});

        app.get("/importGitLocalFlow",
 		function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var gitLocalRepository =  settings.gitLocalRepository;
		//console.dir(req);
                var filePath = req.query.filePath;
                var fullFilePath = gitLocalRepository +"/" + filePath ;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec =  "cat " + fullFilePath ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,{maxBuffer: 1024 * 1024 * 16}, function (error,stdout,stderr){
                if(error){
			console.log("Error occured:" + error);
			if(stderr){
				//console.log("stderr:" + stderr);
				res.send(500,{'error':error,'stderr':stderr});
			}else{
				res.send(500,{'error':error});
			}
                }else{
			if(stderr){
				console.log("stderr:" + stderr);
			}
			if(stdout){
				//console.log("output:" + stdout);
				res.send(200,{'stdout':stdout,'stderr':stderr});
                	}
		}
		});
	});


        app.get("/gitcheckout", function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var gitLocalRepository =  settings.gitLocalRepository;
		//console.dir(req);
                var branch = req.query.branch;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitcheckout " + gitLocalRepository + " " + branch ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"output":stderr});
					}else{
						res.json({"output":error});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						res.json({"output": stderr + " " + stdout});
					}
				}
			});
	});

        app.get("/gitpull", function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var gitLocalRepository =  settings.gitLocalRepository;
		//console.dir(req);
                var branch = req.query.branch;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitpull " + gitLocalRepository ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"output":stderr});
					}else{
						res.json({"output":error});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						res.json({"output": stderr + " " + stdout});
					}
				}
			});
	});

        app.get("/gitstatus", function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var gitLocalRepository =  settings.gitLocalRepository;
		//console.dir(req);
                var branch = req.query.branch;
		//console.log("fullFilePath:" + fullFilePath);	
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitstatus " + gitLocalRepository ;
		console.log("commandToExec:" + commandToExec);
        	var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"output":stderr});
					}else{
						res.json({"output":error});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						res.json({"output": stderr + " " + stdout});
					}
				}
			});
	});
	
        app.post("/getSharedFlow",
            express.json(),
            function(req,res) {
		var qs = require('querystring');
		var body = '';
        	req.on('data', function (data) {
            		body += data;
        	});
        	req.on('end', function () {
			var post = qs.parse(body);
			//console.log("body:" + body);
			fs.readFile(post.filePath, 'utf8', function (err,data) {
  				if (err) {
    					return console.log(err);
  				}
				res.json(data);
  				//console.log(data);
			});
            	//res.sendFile(body.filePath);
        	});
        });
        
        app.post("/downloadYang",
            express.json(),
            function(req,res) {
		var qs = require('querystring');
		var body = '';
        	req.on('data', function (data) {
            		body += data;
        	});
        	req.on('end', function () {
			var post = qs.parse(body);
			var fileName = post.fileName;
			var appDir = path.dirname(require.main.filename);
			var yangDir = appDir + "/yangFiles" ;
			var fullPathToFile = yangDir + "/" + fileName;
			res.setHeader('Content-disposition', 'attachment; filename=' + fileName);
			res.setHeader('Content-type', 'application/yang');
			res.download(fullPathToFile);
        	});
        });

	function writeToFile(fullPathToFileName,str){
        	try{
           		fs.writeFileSync(fullPathToFileName,str);
        	}catch(e){
                	console.log("Error:" + e);
        	}
    	}
	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;
	}


        app.post("/downloadXml",
            express.json({'limit':'16mb'}),
            function(req,res) {
		//console.log("Received request and processing:" + new Date());
        	var qs = require('querystring');
        	var body = '';
        	//var msecs1= Date.now();
        	req.on('data', function (data) {
            		body += data;
        	});
        	req.on('end', function () {
			var appDir = path.dirname(require.main.filename);
			var xmlDir = appDir + "/" + settings.xmlPath;
                	//var msecs2= Date.now();
                	//console.log("Time taken to get request body:" + (msecs2 - msecs1));
                	var msecs3= Date.now();
                	var post = qs.parse(body);
                	var msecs4= Date.now();
                	//console.log("Time taken to parse body:" + (msecs4 - msecs3));
                	var xml = post['flowXml'];
			//var pd = require('pretty-data').pd;
			//var formatted_xml = pd.xml(xml);
                	var moduleName = post['moduleName'];
                	var methodName = post['methodName'];
                	if(moduleName == "" || methodName == ""){
                        	res.send({"ERROR":"ServiceLogic Module Name and method name are required."});
                	}else{
                        	//var formatted_date = getCurrentDate();
                        	//var fileNameForServer=moduleName + "_" +methodName+ "_" +  formatted_date + ".xml";
                        	//var fileName=moduleName + "_method_" +methodName+ ".xml";
                        	var fileName=moduleName + "_" +methodName+ ".xml";
                        	var file = xmlDir + "/" + fileName;

                        	//var msecs2= Date.now();
                        	writeToFile(file,xml);
                        	//var msecs3= Date.now();
                        	//console.log("Time taken to write File:" + (msecs3 - msecs2));
                        	res.setHeader('Content-disposition', 'attachment; filename=' + fileName);
                        	res.setHeader('Content-type', 'text/xml');
                        	res.end(xml);
                        	//console.log("Response sent:" + new Date());
			}
        	});
	});

        app.post("/downloadJson",
            express.json({'limit':'16mb'}),
            function(req,res) {
			var appDir = path.dirname(require.main.filename);
			var sharedDir = appDir + "/" + settings.sharedDir;
		 	var qs = require('querystring');
        		var body = '';
        		req.on('data', function (data) {
            			body += data;
        		});
        		req.on('end', function () {
                		var post = qs.parse(body);
                		var jsonStr = post['flowJson'];
                		var moduleName = post['moduleName'];
                		var methodName = post['methodName'];
                		//console.log("jsonStr:" + jsonStr);
                		if(moduleName == "" || methodName == ""){
                        		res.send({"ERROR":"ServiceLogic Module Name and method name are required."});
                		}else{
                        		var formatted_date = getCurrentDate();
                        		//console.log("moduleName:" + moduleName);
                        		//console.log("methodName:" + methodName);

                        		//var fileName=moduleName + "_method_" +methodName + ".json";
                        		//var renameOldfileTo=moduleName + "_method_" +methodName+ "_" +  formatted_date + ".json";
                        		var fileName=moduleName + "_" +methodName + ".json";
                        		var renameOldfileTo=moduleName + "_" +methodName+ "_" +  formatted_date + ".json";
                        		var file = sharedDir + "/" + fileName;
                        		//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);
                                		}
                                		//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);
					});
				}
	   		});
	});

        app.post("/flows",
            express.json({'limit':'16mb'}),
            function(req,res) {
		//console.log("Processing Request");
                var flows = req.body;
                redNodes.setFlows(flows).then(function() {
                    res.send(204);
                }).otherwise(function(err) {
                    util.log("[red] Error saving flows : "+err);
                    res.send(500,err.message);
                });
            },
            function(error,req,res,next) {
                res.send(400,"Invalid Flow.  Error " + error);
            }
        );
            
        app.get("/nodes",function(req,res) {
            if (req.get("accept") == "application/json") {
                res.json(redNodes.getNodeList());
            } else {
                res.send(redNodes.getNodeConfigs());
            }
        });
        
        app.post("/nodes",
            express.json(),
            function(req,res) {
                if (!settings.available()) {
                    res.send(400,new Error("Settings unavailable").toString());
                    return;
                }
                var node = req.body;
                var promise;
                if (node.file) {
                    promise = redNodes.addNode(node.file).then(reportAddedModules);
                } else if (node.module) {
                    var module = redNodes.getNodeModuleInfo(node.module);
                    if (module) {
                        res.send(400,"Module already loaded");
                        return;
                    }
                    promise = installModule(node.module);
                } else {
                    res.send(400,"Invalid request");
                    return;
                }
                promise.then(function(info) {
                    res.json(info);
                }).otherwise(function(err) {
                    if (err.code === 404) {
                        res.send(404);
                    } else {
                        res.send(400,err.toString());
                    }
                });
            },
            function(err,req,res,next) {
                console.log(err.toString());
                res.send(400,err);
            }
        );
        
        app.delete("/nodes/:id",
            function(req,res) {
                if (!settings.available()) {
                    res.send(400,new Error("Settings unavailable").toString());
                    return;
                }
                var id = req.params.id;
                var removedNodes = [];
                try {
                    var node = redNodes.getNodeInfo(id);
                    var promise = null;
                    if (!node) {
                        var module = redNodes.getNodeModuleInfo(id);
                        if (!module) {
                            res.send(404);
                            return;
                        } else {
                            promise = uninstallModule(id);
                        }
                    } else {
                        promise = when.resolve([redNodes.removeNode(id)]).then(reportRemovedModules);
                    }
                    
                    promise.then(function(removedNodes) {
                        res.json(removedNodes);
                    }).otherwise(function(err) {
                        console.log(err.stack);
                        res.send(400,err.toString());
                    });
                } catch(err) {
                    res.send(400,err.toString());
                }
            },
            function(err,req,res,next) {
                res.send(400,err);
            }
        );
        
        app.get("/nodes/:id", function(req,res) {
            var id = req.params.id;
            var result = null;
            if (req.get("accept") == "application/json") {
                result = redNodes.getNodeInfo(id);
            } else {
                result = redNodes.getNodeConfig(id);
            }
            if (result) {
                res.send(result);
            } else {
                res.send(404);
            }
        });
        
        app.put("/nodes/:id", 
            express.json(),
            function(req,res) {
                if (!settings.available()) {
                    res.send(400,new Error("Settings unavailable").toString());
                    return;
                }
                var body = req.body;
                if (!body.hasOwnProperty("enabled")) {
                    res.send(400,"Invalid request");
                    return;
                }
                try {
                    var info;
                    var id = req.params.id;
                    var node = redNodes.getNodeInfo(id);
                    if (!node) {
                        res.send(404);
                    } else if (!node.err && node.enabled === body.enabled) {
                        res.json(node);
                    } else {
                        if (body.enabled) {
                            info = redNodes.enableNode(id);
                        } else {
                            info = redNodes.disableNode(id);
                        }
                        if (info.enabled == body.enabled && !info.err) {
                            comms.publish("node/"+(body.enabled?"enabled":"disabled"),info,false);
                            util.log("[red] "+(body.enabled?"Enabled":"Disabled")+" node types:");
                            for (var i=0;i<info.types.length;i++) {
                                util.log("[red] - "+info.types[i]);
                            }
                        } else if (body.enabled && info.err) {
                            util.log("[red] Failed to enable node:");
                            util.log("[red] - "+info.name+" : "+info.err);
                        }
                        res.json(info);
                    }
                } catch(err) {
                    res.send(400,err.toString());
                }            
            }
        );
        app.get("/getCodeCloudFlows",function(req,res) {
		var userDir=settings.userDir;
		var codeCloudDir=userDir + "/codecloud";
		var glob = require("glob")
		glob(codeCloudDir + "/**/*.json", null, function (er, files) {
			  // files is an array of filenames.
			 // If the `nonull` option is set, and nothing
  			// was found, then files is ["**/*.js"]
  			// er is an error object or null.
			//console.dir(files);
			var filesList =[];
			for(var i=0;files!= null && i<files.length;i++){
				var f = files[i].replace( new RegExp(codeCloudDir + "/", "g" ), "" );
				filesList.push(f);

			}
			res.json({"files" : filesList});
		});
        });

        app.get("/getCurrentGitBranch",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir=settings.userDir;
		var settingsFile = appDir + "/" +  userDir + "/customSettings.js"; 
		//console.log("settingsFile:" + settingsFile);
		var jsonObj = require(settingsFile);
		var gitLocalRepository=jsonObj.gitLocalRepository;
		if(gitLocalRepository == undefined || gitLocalRepository == null || gitLocalRepository == ''){
			res.json({"output" : "GIT_LOCAL_REPOSITORY_NOT_SET"});
			return;
		}
		var exec = require('child_process').exec;
		var commandToExec = appDir + "/git_scripts/gitcurbranch " + gitLocalRepository ;
			console.log("commandToExec:" + commandToExec);
        		var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"output":stderr});
					}else{
						res.json({"output":error});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						res.json({"output":stdout});
					}
				}
			});
				
	});

        app.get("/getGitLocalFlows",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var userDir=settings.userDir;
		var settingsFile = appDir + "/" +  userDir + "/customSettings.js"; 
		//console.log("settingsFile:" + settingsFile);
		var jsonObj = require(settingsFile);
		var performGitPull = jsonObj.performGitPull;
		if(performGitPull == undefined || performGitPull == null) {
			performGitPull="N";
		}
		var gitLocalRepository=jsonObj.gitLocalRepository;
		if(gitLocalRepository == undefined || gitLocalRepository == null || gitLocalRepository == ''){
			res.json({"files" : ["GIT_LOCAL_REPOSITORY_NOT_SET"]});
			return;
				
		   }

		if(performGitPull == "Y"){	
			var exec = require('child_process').exec;
			var commandToExec = appDir + "/git_scripts/gitpull " + gitLocalRepository ;
			console.log("commandToExec:" + commandToExec);
        		var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"files":[]});
					}else{
						res.json({"files":[]});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						var glob = require("glob")
						glob(gitLocalRepository + "/**/*.json", null, function (er, files) {
			  			// files is an array of filenames.
			 			// If the `nonull` option is set, and nothing
  						// was found, then files is ["**/*.js"]
  						// er is an error object or null.
						//console.dir(files);
						var filesList =[];
						for(var i=0;files!= null && i<files.length;i++){
							var f = files[i].replace( new RegExp(gitLocalRepository + "/", "g" ), "" );
							filesList.push(f);

						}
						res.json({"files" : filesList});
						});
                			}
				}
			});
		}else{//git pull not requested
			var glob = require("glob")
			glob(gitLocalRepository + "/**/*.json", null, function (er, files) {
			// files is an array of filenames.
			// If the `nonull` option is set, and nothing
  			// was found, then files is ["**/*.js"]
  			// er is an error object or null.
			//console.dir(files);
			var filesList =[];
			for(var i=0;files!= null && i<files.length;i++){
				var f = files[i].replace( new RegExp(gitLocalRepository + "/", "g" ), "" );
				filesList.push(f);

			}
			res.json({"files" : filesList});
			});
		}
	
        });

        app.get("/flowShareUsers",function(req,res) {
            res.json(flowShareUsers);
        });
        app.get("/getRelease",function(req,res) {
		var userDir = settings.userDir;
		//var release = userDir.replace(/releases/g,"release");
            	res.json({"release" : userDir});
        });
        app.post("/getFiles/:id",function(req,res) {
            var id = req.params.id;
		//console.log("id:" + id);
		var userDir=settings.userDir;
		var flowDir= userDir + "/../" + id + "/flows/shared"; 
		//console.log("flowDir:" + flowDir);
		fs.readdir(flowDir,function(err, files){
			if(err){
				res.json({"files": []});
			}else{
				var onlyFilesArr =[];
				if(files != null && files.length>0){
					files.sort(function(a,b){
						//console.log("file1:" + a);	
						//console.log("file2:" + b);	
						var fileStat1=fs.statSync(flowDir+ "/" + a);	
						var fileStat2=fs.statSync(flowDir+ "/" + b);	
						if(fileStat1.mtime > fileStat2.mtime){
							return 1;
						}else if(fileStat1.mtime < fileStat2.mtime){
							return -1;
						}else{
							return 0;
						}
					});
					for(var i=0;i<files.length;i++){
						var fileStat=fs.statSync(flowDir+ "/" + files[i]);
						if(fileStat.isFile()){
						    onlyFilesArr.push({"filePath":flowDir+ "/" + files[i],"name":files[i]});
						}
					}
					res.json(onlyFilesArr);
				}else{
					res.json({"files": []});
				}
			}
		});
        });

        app.post("/updateConfiguration",
            express.json(),
            function(req,res) {
		var qs = require('querystring');
		//console.log("Received the request:");
		var body ="";
		 req.on('data', function (data) {
            		body += data;
        	});
		req.on('end',function(){
			var post = qs.parse(body);
                	var dbHost = post["dbHost"];
                	var dbPort = post["dbPort"];
                	var dbName = post["dbName"];
                	var dbUser = post["dbUser"];
                	var dbPassword = post["dbPassword"];
                	var gitLocalRepository = post["gitLocalRepository"];
                	var performGitPull = post["performGitPull"];
			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.flowFile = jsonObj.flowFile.replace(appDir + "/",'');
				jsonObj.dbHost = dbHost;
				jsonObj.dbPort = dbPort;
				jsonObj.dbName = dbName;
				jsonObj.dbUser = dbUser;
				jsonObj.dbPassword = dbPassword;
				jsonObj.gitLocalRepository = gitLocalRepository;
				jsonObj.performGitPull = performGitPull;
				var updatedSettings = jsonObj;

				var settingsStr= "module.exports=" + JSON.stringify(updatedSettings,null,4);
				//console.log("settingsStr:" + settingsStr);
           			fs.writeFileSync(settingsFile,settingsStr);
				var svcLogicPropStr = "" ;
					svcLogicPropStr += "org.openecomp.sdnc.sli.dbtype=jdbc" + "\n";
					svcLogicPropStr += "org.openecomp.sdnc.sli.jdbc.url=jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "\n";
					svcLogicPropStr += "org.openecomp.sdnc.sli.jdbc.database=" + dbName + "\n";
					svcLogicPropStr += "org.openecomp.sdnc.sli.jdbc.user=" + dbUser  + "\n";
					svcLogicPropStr += "org.openecomp.sdnc.sli.jdbc.password=" + dbPassword;
				
				//create svclogic.properties file in the conf dir
				var svcPropFile = userDir + "/conf/svclogic.properties";
           			fs.writeFileSync(svcPropFile,svcLogicPropStr);

				res.send({"status": "success"});
        		}catch(e){
                		console.log("Error:" + e);
				res.send({"status": "error"});
        		}
		});
            }
	);

        app.post("/deleteYangFile",
            express.json(),
            function(req,res) {
		var qs = require('querystring');
		//console.log("Received the request:");
		var body ="";
		 req.on('data', function (data) {
            		body += data;
        	});
		req.on('end',function(){
			var post = qs.parse(body);
			//console.dir(body);
                	var fileName = post["fileName"];
			var appDir = path.dirname(require.main.filename);
			var yangFilePath = appDir + "/yangFiles/" + fileName;
			try{
				fs.unlinkSync(yangFilePath);
				res.send({"status" :"SUCCESS"});
			}catch(err){
				console.log("error" + err);
				res.send({"status" :"ERROR"});
			}
			//console.log("prevPassword:" + settings.httpAuth.pass );
		});
            }
	);

        app.post("/updatePassword",
            express.json(),
            function(req,res) {
		var qs = require('querystring');
		//console.log("Received the request:");
		var body ="";
		 req.on('data', function (data) {
            		body += data;
        	});
		req.on('end',function(){
			var post = qs.parse(body);
			//console.dir(body);
                	var password = post["password"];
			//console.log("prevPassword:" + settings.httpAuth.pass );
			//console.log("New password:" + password);
			var crypto = require("crypto");
			var cryptPasswd = crypto.createHash('md5').update(password,'utf8').digest('hex')
			var appDir = path.dirname(require.main.filename);
			var userDir = appDir + "/" + settings.userDir;
			//console.log("userDir:" + userDir);
			/*var newSettings = settings;
			newSettings.httpAuth.pass = cryptPasswd;
			var updatedSettings = JSON.stringify(settings,null,4);
			var settingsStr = "module.exports=" + updatedSettings;
			console.log(updatedSettings);
			*/
			try{
				var settingsFile = userDir + "/customSettings.js"; 
				//console.log("settingsFile:" + settingsFile);
				//var buf = fs.readFileSync(settingsFile, "utf8");
				var jsonObj = require(settingsFile);
				//console.log("jsonObj:" + JSON.stringify(jsonObj));
				jsonObj.httpAuth.pass = cryptPasswd;
				jsonObj.httpAdminAuth.pass = cryptPasswd;
				jsonObj.httpNodeAuth.pass = cryptPasswd;
				jsonObj.flowFile = jsonObj.flowFile.replace(appDir + "/",'');
				var updatedSettings = jsonObj;
				/*
    				delete updatedSettings.httpRoot;
    				delete updatedSettings.disableEditor;
    				delete updatedSettings.httpAdminRoot;
    				delete updatedSettings.httpAdminAuth;
    				delete updatedSettings.httpNodeRoot;
    				delete updatedSettings.httpNodeAuth;
    				delete updatedSettings.uiHost;
    				delete updatedSettings.version;
				*/
				var settingsStr= "module.exports=" + JSON.stringify(updatedSettings,null,4);
				//console.log("settingsStr:" + settingsStr);
           			fs.writeFileSync(settingsFile,settingsStr);
				settings.httpAuth.pass = cryptPasswd;
				res.send({"status": "success"});
        		}catch(e){
                		console.log("Error:" + e);
				res.send({"status": "error"});
        		}
		});
            }
	);

	var appDir = path.dirname(require.main.filename);
	var yangDir = appDir + "/yangFiles" ;
	var diskStorage =   multer.diskStorage({
  			destination: function (req, file, callback) {
    						callback(null, yangDir);
  			},
  			filename: function (req, file, callback) {
    				//callback(null, file.fieldname + '-' + Date.now());
    				callback(null, file.originalname);
  			}
	});
	var upload = multer({ storage : diskStorage}).single('yangFile');

	app.post('/api/uploadyang',function(req,res){
    		upload(req,res,function(err) {
        		if(err) {
				console.log(err);
            			return res.end("Error uploading file." + err);
        		}
			//console.dir(req);	
			var fileName = req.file.originalname;
			var yangFileFullPath =  appDir + "/yangFiles/" + fileName;
			console.log("yangFileFullPath:" + yangFileFullPath);
			var commandToExec =""; 
			if(fileName != null){
				var matchedArr = fileName.match(/.zip$/);
				if(matchedArr != null && matchedArr.length >0){
					console.log("uploaded zip file" + fileName);
					//commandToExec = appDir + "/tools/generate_props_from_yangs_zip.sh " + yangFileFullPath ;
					commandToExec = appDir + "/tools/generate_props_from_yang.sh " + yangFileFullPath ;
				}else{
					commandToExec = appDir + "/tools/generate_props_from_yang.sh " + yangFileFullPath ;
					console.log("uploaded file" + fileName);
				}
			}
			var exec = require('child_process').exec;
			console.log("commandToExec:" + commandToExec);
        		var child = exec(commandToExec ,function (error,stdout,stderr){
                		if(error){
					console.log("Error occured:" + error);
					var msg = "File " + fileName + " could not be processed successfully.";
					if(stderr){
						console.log("stderr:" + stderr);
						res.json({"sliValuesObj" : [],"message":msg});
					}else{
						res.json({"sliValuesObj" : [],"message":msg});
					}
                		}else{
					if(stderr){
						console.log("stderr:" + stderr);
					}
					if(stdout){
						console.log("stdout:" + stdout);
					}
					var msg = "File " + fileName + " processed successfully.";
					var generatedJSDir=appDir + "/generatedJS";
					var sliValuesObj =[];
					//var glob = require("glob");
					//glob(generatedJSDir + "/**/*.js", null, function (er, files) {
					/*
						var sliValuesObj =[];
						for(var i=0;files!= null && i<files.length;i++){
							var f = files[i].replace( new RegExp(generatedJSDir + "/", "g" ), "" );
							console.log("loading file " + f);
							try{
								sliValuesObj.push(require(files[i]));
								//console.dir(sliValuesObj);
							}catch(err){
								console.log("Error:Could not load file " + files[i]);
							}
						} 
						res.json({"sliValuesObj" : sliValuesObj,"message":msg});
                			});
					*/
					res.json({"sliValuesObj" : sliValuesObj,"message":msg});
    	                	}
        		});
		});
        });
        app.get("/getYangFiles",function(req,res) {
		var appDir = path.dirname(require.main.filename);
		var yangFilesDir=appDir + "/yangFiles";
		var glob = require("glob")
		glob(yangFilesDir + "/**/*.yang", null, function (er, files) {
			var filesList =[];
			for(var i=0;files!= null && i<files.length;i++){
				var f = files[i].replace( new RegExp(yangFilesDir + "/", "g" ), "" );
				filesList.push(f);

			}
			res.json({"files" : filesList});
		});
        });
	}
}

function reportAddedModules(info) {
    comms.publish("node/added",info,false);
    if (info.length > 0) {
        util.log("[red] Added node types:");
        for (var i=0;i<info.length;i++) {
            for (var j=0;j<info[i].types.length;j++) {
                util.log("[red] - "+
                    (info[i].module?info[i].module+":":"")+
                    info[i].types[j]+
                    (info[i].err?" : "+info[i].err:"")
                    );
            }
        }
    }
    return info;
}

function reportRemovedModules(removedNodes) {
    comms.publish("node/removed",removedNodes,false);
    util.log("[red] Removed node types:");
    for (var j=0;j<removedNodes.length;j++) {
        for (var i=0;i<removedNodes[j].types.length;i++) {
            util.log("[red] - "+(removedNodes[i].module?removedNodes[i].module+":":"")+removedNodes[j].types[i]);
        }
    }
    return removedNodes;
}

function installModule(module) { 
    //TODO: ensure module is 'safe'
    return when.promise(function(resolve,reject) {
        if (/[\s;]/.test(module)) {
            reject(new Error("Invalid module name"));
            return;
        }
        util.log("[red] Installing module: "+module);
        var child = exec('npm install --production '+module, function(err, stdin, stdout) {
            if (err) {
                var lookFor404 = new RegExp(" 404 .*"+module+"$","m");
                if (lookFor404.test(stdout)) {
                    util.log("[red] Installation of module "+module+" failed: module not found");
                    var e = new Error();
                    e.code = 404;
                    reject(e);
                } else {
                    util.log("[red] Installation of module "+module+" failed:");
                    util.log("------------------------------------------");
                    console.log(err.toString());
                    util.log("------------------------------------------");
                    reject(new Error("Install failed"));
                }
            } else {
                util.log("[red] Installed module: "+module);
                resolve(redNodes.addModule(module).then(reportAddedModules));
            }
        });
    });
}

function uninstallModule(module) {
    var list = redNodes.removeModule(module);
    return when.promise(function(resolve,reject) {
        if (/[\s;]/.test(module)) {
            reject(new Error("Invalid module name"));
            return;
        }
        util.log("[red] Removing module: "+module);
        var child = exec('npm remove '+module, function(err, stdin, stdout) {
            if (err) {
                util.log("[red] Removal of module "+module+" failed:");
                util.log("------------------------------------------");
                console.log(err.toString());
                util.log("------------------------------------------");
                reject(new Error("Removal failed"));
            } else {
                util.log("[red] Removed module: "+module);
                reportRemovedModules(list);
                resolve(list);
            }
        });
    });
}

function start() {
    var defer = when.defer();
    
    storage.init(settings).then(function() {
        settings.load(storage).then(function() {
            console.log("\nWelcome to Node-RED\n===================\n");
            if (settings.version) {
                util.log("[red] Version: "+settings.version);
            }
            util.log("[red] Loading palette nodes");
            redNodes.init(settings,storage);
            redNodes.load().then(function() {
                var i;
                var nodes = redNodes.getNodeList();
                var nodeErrors = nodes.filter(function(n) { return n.err!=null;});
                var nodeMissing = nodes.filter(function(n) { return n.module && n.enabled && !n.loaded && !n.err;});
                if (nodeErrors.length > 0) {
                    util.log("------------------------------------------");
                    if (settings.verbose) {
                        for (i=0;i<nodeErrors.length;i+=1) {
                            util.log("["+nodeErrors[i].name+"] "+nodeErrors[i].err);
                        }
                    } else {
                        util.log("[red] Failed to register "+nodeErrors.length+" node type"+(nodeErrors.length==1?"":"s"));
                        util.log("[red] Run with -v for details");
                    }
                    util.log("------------------------------------------");
                }
                if (nodeMissing.length > 0) {
                    util.log("[red] Missing node modules:");
                    var missingModules = {};
                    for (i=0;i<nodeMissing.length;i++) {
                        var missing = nodeMissing[i];
                        missingModules[missing.module] = (missingModules[missing.module]||[]).concat(missing.types);
                    }
                    var promises = [];
                    for (i in missingModules) {
                        if (missingModules.hasOwnProperty(i)) {
                            util.log("[red] - "+i+": "+missingModules[i].join(", "));
                            if (settings.autoInstallModules) {
                                installModule(i).otherwise(function(err) {
                                    // Error already reported. Need the otherwise handler
                                    // to stop the error propagating any further
                                });
                            }
                        }
                    }
                    if (!settings.autoInstallModules) {
                        util.log("[red] Removing modules from config");
                        redNodes.cleanNodeList();
                    }
                }
                defer.resolve();
                
                redNodes.loadFlows();
            }).otherwise(function(err) {
                console.log(err);
            });
            comms.start();
        });
    }).otherwise(function(err) {
        defer.reject(err);
    });
    
    return defer.promise;
}

function stop() {
    redNodes.stopFlows();
    comms.stop();
}

module.exports = { 
    init: createServer,
    start: start,
    stop: stop
}

module.exports.__defineGetter__("app", function() { return app });
module.exports.__defineGetter__("nodeApp", function() { return nodeApp });
module.exports.__defineGetter__("server", function() { return server });
