/**
 * 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;
		/*
		var userDir=settings.userDir;
		var outputDir  = appDir + "/" +  userDir + "/orig_dgs";
		if (!fs.existsSync(outputDir)){
			fs.mkdirSync(outputDir);
		}
		*/
		//console.dir(req);
                var filePath = req.query.filePath;
                //var currTabId = req.query.currTabId;
                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){
				/*
				var jsonStr= stdout;
				var jsonStrFormatted=[];
				try{
					jsonStrFormatted= JSON.parse(jsonStr);
				}catch(e){
				}
				fs.writeFileSync( outputDir + "/" +currTabId,JSON.stringify(jsonStrFormatted,null,4) );	
				*/
				//console.log("output:" + stdout);
				res.send(200,{'stdout':stdout,'stderr':stderr});
                	}
		}
		});
	});

        app.post("/saveImportedDG",
            express.json(),
            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 userDir=settings.userDir;
			var outputDir  = appDir + "/" +  userDir + "/orig_dgs";
			if (!fs.existsSync(outputDir)){
				fs.mkdirSync(outputDir);
			}
			var post = qs.parse(body);
                	var importedNodes = post.importedNodes;
                	var currTabId = post.currTabId;
			fs.writeFileSync( outputDir + "/" +currTabId,importedNodes );	
			res.send(200,{"output":"SUCCESS"});
        	});
        });

 	app.post("/saveImportedDG",
            express.json(),
            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 userDir=settings.userDir;
                        var outputDir  = appDir + "/" +  userDir + "/orig_dgs";
                        if (!fs.existsSync(outputDir)){
                                fs.mkdirSync(outputDir);
                        }
                        var post = qs.parse(body);
                        var importedNodes = post.importedNodes;
                        var currTabId = post.currTabId;
                        fs.writeFileSync( outputDir + "/" +currTabId,importedNodes );
                        res.send(200,{"output":"SUCCESS"});
                });
        });

        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);
					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);
					}
				}
	   		});
	});

        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.get("/readFile",function(req,res) {
		var userDir=settings.userDir;
		var filePath = userDir + "/" +  req.query.filePath;
		var buf = fs.readFileSync(filePath, "utf8");
            	res.json({"output" :buf });
        });
        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 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;
				jsonObj.dbName = dbName;
				jsonObj.dbUser = dbUser;
				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);
				//console.log("settingsStr:" + settingsStr);
           			fs.writeFileSync(settingsFile,settingsStr);
				var svcLogicPropStr = "" ;
					svcLogicPropStr += "org.onap.ccsdk.sli.dbtype=jdbc" + "\n";
					svcLogicPropStr += "org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "\n";
					svcLogicPropStr += "org.onap.ccsdk.sli.jdbc.database=" + dbName + "\n";
					svcLogicPropStr += "org.onap.ccsdk.sli.jdbc.user=" + dbUser  + "\n";
					svcLogicPropStr += "org.onap.ccsdk.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 ;
				}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});
    	                	}
        		});
		});
        });

	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<files.length;i++){
						var f = files[i].replace( new RegExp(inputFilesDir + "/", "g" ), "" );
						filesList.push(f); 
					}
					res.json({"files" : filesList});
				});
        		});
	});

        app.post("/deleteInputFile",
            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 filePath = appDir + "/inputFiles/" + fileName;
			try{
				fs.unlinkSync(filePath);
				res.send({"status" :"SUCCESS"});
			}catch(err){
				console.log("error" + err);
				res.send({"status" :"ERROR"});
			}
			//console.log("prevPassword:" + settings.httpAuth.pass );
		});
            });

        app.post("/loadInputFile",
            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"];
			//console.log("fileName" + fileName);
			var appDir = path.dirname(require.main.filename);
			var filePath = appDir + "/inputFiles/" + fileName;
			//console.log("filePath:" + filePath);
			try{
				fs.readFile(filePath, 'utf8', function (err,data) {
  					if (err) {
    						return console.log(err);
  					}
					res.json({'input':data});
				});	
			}catch(err){
				console.log("error" + err);
				res.json({"status" :"ERROR"});
			}
		});
            });


        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();
	//split and save startup dgs if any from flows.json file
		var appDir = path.dirname(require.main.filename);
		var userDir = appDir + "/" + settings.userDir;
		var flowFile = settings.flowFile;
		var outputDir = userDir + "/orig_dgs";
		console.log("appDir:" + appDir);
		console.log("flowFile:" + flowFile);
		var execFile = require('child_process').execFile;
		var commandToExec = appDir + "/tools/splitFlows.sh" ;
		console.log("commandToExec:" + commandToExec);
		var args = [flowFile,outputDir];
        	var child = execFile(commandToExec ,args,function (error,stdout,stderr){
                if(error){
			console.log("Error occured:" + error);
			if(stderr){
				console.log("stderr:" + stderr);
			}else{
				console.log("error:" + error);
			}
                }else{
			if(stderr){
				console.log("stderr:" + stderr);
			}
			if(stdout){
				console.log("output:" + stdout);
                	}
		}
		});
		
    
    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 });
