diff options
author | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:37:53 -0500 |
---|---|---|
committer | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:40:37 -0500 |
commit | 324ee36fe31763e507b422ab0a88e4230045e205 (patch) | |
tree | d0b04520f6657601c918ce63fd27575977624187 /admportal/server/router/routes/helpers.js | |
parent | f0c97e8db427481e28c0a16b789bc73801b35e47 (diff) |
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680
Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com>
Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'admportal/server/router/routes/helpers.js')
-rw-r--r-- | admportal/server/router/routes/helpers.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/admportal/server/router/routes/helpers.js b/admportal/server/router/routes/helpers.js new file mode 100644 index 00000000..6ac8215f --- /dev/null +++ b/admportal/server/router/routes/helpers.js @@ -0,0 +1,66 @@ +
+var _ = require('lodash');
+var csvtojson = require('csvtojson');
+var async = require('async');
+var uuid = require('node-uuid'); // generate a uuid with "uuid.v1()"
+var path = require('path');
+var fs = require("fs");
+var moment = require('moment');
+
+var helpers = module.exports;
+
+function puts(obj) { console.log(obj); }
+function putd(obj) { console.log(obj); }
+helpers.puts = puts;
+helpers.putd = putd;
+
+
+helpers.readCsv = function(filedir, filename, callback) {
+
+
+ var Converter=csvtojson.Converter;
+ var csvFileName=path.join(filedir,filename);
+ var fileStream=fs.createReadStream(csvFileName);
+ fileStream.on('error', function(err){
+ callback(err, null);
+ });
+ var param={noheader:true, checkType:false};
+ var csvConverter=new Converter(param);
+ csvConverter.on("end_parsed",function(jsonObj){
+ var returnValue = jsonObj;
+ callback(null, returnValue);
+ });
+ fileStream.on('error', function(err) {
+ putd(err);
+ callback(err,"");
+ });
+ fileStream.pipe(csvConverter);
+}
+
+helpers.getParam = function(csv, matchField, matchValue, returnField) {
+ dataRow=_.find(csv, matchField, matchValue);
+ dataValue=dataRow[returnField];
+ return dataValue;
+}
+
+helpers.writeOutput = function(req, filename, jsonOutput, callback) {
+ try {
+ fs.writeFileSync(filename, jsonOutput);
+ }
+ catch(err){
+ callback(err);
+ }
+}
+
+helpers.getFileName = function(req, defFilename) {
+
+ var fileObj = null;
+ for (var x=0; x < req.files.length; x++)
+ {
+ var fileObj = req.files[x];
+ if ( fileObj.filename.indexOf(defFilename) != -1 ){
+ return fileObj.filename;
+ }
+ }
+ return null;
+}
|