diff options
Diffstat (limited to 'vnfcatalogue/VNF_Catalogue/routes')
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/add_project.js | 116 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/add_tag.js | 52 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/index.js | 18 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/project_profile.js | 19 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/search_projects.js | 94 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/search_tag.js | 36 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/search_vnf.js | 36 | ||||
-rw-r--r-- | vnfcatalogue/VNF_Catalogue/routes/vnf_tag_association.js | 55 |
8 files changed, 0 insertions, 426 deletions
diff --git a/vnfcatalogue/VNF_Catalogue/routes/add_project.js b/vnfcatalogue/VNF_Catalogue/routes/add_project.js deleted file mode 100644 index 229620d..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/add_project.js +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); -var multer = require('multer'); - - -var storage = multer.diskStorage({ - destination: function (req, file, callback) { - callback(null, './public/uploads'); - }, - filename: function (req, file, callback) { - console.log(file); - console.log(req.body); - callback(null, file.fieldname + '-' + Date.now() + '.jpg'); - } -}); - -var fileFilter = function (req, file, cb) { - if (file.mimetype !== 'image/png') { - //req.fileValidationError = 'goes wrong on the mimetype'; - cb(null, false); - } else { - cb(null, true); - } -} - -var upload = multer({ fileFilter: fileFilter, storage : storage}).single('file_upload'); - - -router.post('/', function(req, res) { - upload(req,res,function(err) { - console.log(req.body); - console.log(req.file) - if(req.file == null && req.body['file_url'] != '') { - response = 'File Upload error: wrong Filetype'; - res.status(500); - res.end(JSON.stringify({'error': response})); - - } - if(err) { - console.log(err); - response = 'File Upload error: ' + err; - console.log(response); - //return res.end(req.fileValidationError); - res.status(500); - res.send({'error': response}); - return; - } - - console.log(req.file); - req.body['photo_url'] = (req.file) ? req.file['filename'] : 'logo.png'; - console.log(req.body); - - req.checkBody("vnf_name", "VNF Name must not be empty").notEmpty(); - req.checkBody("repo_url", "Repository URL must not be empty").notEmpty(); - req.checkBody("license", "Please select a License").notEmpty(); - req.checkBody("opnfv_indicator", "Please select an OPNFV Indicator").notEmpty(); - req.checkBody("repo_url", "Must be a Github URL").matches('.*github\.com.*'); - - var errors = req.validationErrors(); - console.log(errors); - - var response = ''; for(var i = 0; i < errors.length; i++) { - console.log(errors[i]['msg']); - response = response + errors[i]['msg'] + '; '; - } - - if(errors) { res.status(500); - res.send({'error': response}); - return; - } - - var vnf_details = req.body; - delete vnf_details.file_url; - - db_pool.getConnection(function(err, connection) { - // Use the connection - - sql_query = 'INSERT INTO photo(photo_url) values(\'' + req.body['photo_url'] + '\')\;SELECT LAST_INSERT_ID() photo_id'; - // TODO look above query prone to sql_injections - - console.log(sql_query); - connection.query(sql_query, function (error, results, fields) { - console.log('hola'); - console.log(results[1][0].photo_id); - //connection.query(sql_query, vnf_details, function (error, results, fields) { - delete vnf_details.photo_url; - vnf_details['photo_id'] = results[1][0].photo_id; - sql_query = 'INSERT INTO vnf SET ?' - connection.query(sql_query, vnf_details, function (error, results, fields) { - // And done with the connection. - connection.release(); - if (error) throw error; - - // Handle error after the release. - res.end('{"success" : "Updated Successfully", "status" : 200}'); - return; - // Don't use the connection here, it has been returned to the pool. - }); - }); - }); - - - }); - -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/add_tag.js b/vnfcatalogue/VNF_Catalogue/routes/add_tag.js deleted file mode 100644 index 511f4cc..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/add_tag.js +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -router.post('/', function(req, res) { - console.log(req.body); - req.checkBody("tag_name", "TAG Name must not be empty").notEmpty(); - - var errors = req.validationErrors(); - console.log(errors); - - var response = ''; for(var i = 0; i < errors.length; i++) { - console.log(errors[i]['msg']); - response = response + errors[i]['msg'] + '; '; - } - - if(errors) { res.status(500); - res.send({'error': response}); - return; - } - - var tag_details = req.body; - - db_pool.getConnection(function(err, connection) { - // Use the connection - sql_query = 'INSERT INTO tag SET ?' - connection.query(sql_query, tag_details, function (error, results, fields) { - // And done with the connection. - res.end('{"success" : "Updated Successfully", "status" : 200}'); - return; - connection.release(); - // Handle error after the release. - if (error) throw error; - // Don't use the connection here, it has been returned to the pool. - }); - }); - - - res.end('{"success" : "Updated Successfully", "status" : 200}'); - return; - -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/index.js b/vnfcatalogue/VNF_Catalogue/routes/index.js deleted file mode 100644 index 950fcd5..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/index.js +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -/* GET VNF_Catalogue Home Page. */ -router.get('/', function(req, res) { - res.render('index', { title: 'Express' }); -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/project_profile.js b/vnfcatalogue/VNF_Catalogue/routes/project_profile.js deleted file mode 100644 index be06642..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/project_profile.js +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -router.get('/', function(req, res) { - var tags = req.param('tags'); - console.log(tags); - res.render('project_profile', { title: 'Express' }); -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/search_projects.js b/vnfcatalogue/VNF_Catalogue/routes/search_projects.js deleted file mode 100644 index 96f68db..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/search_projects.js +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); -var async = require('async'); - - -var renderer = function(res, err, results) { - console.log(results); - res.render('search_projects', { title: 'Express', json: results }); -} - -var get_tags = function(result, callback) { - db_pool.getConnection(function(err, connection) { - sql_query = 'select tag_name from tag where tag_id in (select tag_id from vnf_tags where vnf_id = ' + result['vnf_id'] + ') limit 5'; - // TODO find why it works and not above - connection.query(sql_query, function (error, results, fields) { - console.log(results); - result['tags'] = results; - callback(null, result); - //connection.release(); - if (error) throw error; - }); - }); -} - - -var get_images = function(result, callback) { - db_pool.getConnection(function(err, connection) { - sql_query = 'select photo_url from photo where photo_id = ' + result['photo_id']; - // TODO find why it works here and not when declared outside the method - console.log(sql_query); - connection.query(sql_query, function (error, results, fields) { - console.log(results[0].photo_url); - result['photo_url'] = results[0].photo_url; - callback(null, result); - //connection.release(); - if (error) throw error; - }); - }); -} - -var sql_data = function(tags, renderer, res) { - var tag_array = "\'" + tags.map(function (item) { return item; }).join("\',\'") + "\'"; - console.log(tag_array); - var condition = ''; - db_pool.getConnection(function(err, connection) { - sql_query = 'select tag_id from tag where tag_name in (' + tag_array + ')'; - connection.query(sql_query, function (error, results, fields) { - condition = 'SELECT * FROM vnf as v'; - for (var i in results) { - condition += (i == 0) ? ' WHERE ' : ' AND '; - condition += 'v.vnf_id IN (SELECT vnf_id from vnf_tags where tag_id = ' + results[i]['tag_id'] + ')'; - } - - connection.query(condition, function (error, results, fields) { - console.log(results); - async.map(results, get_images, function(error, results) { - async.map(results, get_tags, renderer.bind(null, res)); - }); - //connection.release(); - if (error) throw error; - }); - - connection.release(); - if (error) throw error; - }); - }); - -} - -router.get('/', function(req, res) { - - console.log(typeof(req.param('tags'))); - var tags = req.param('tags'); - - if(tags) { - tags = tags.toLowerCase().split(/[ ,]+/); - console.log(tags); - sql_data(tags, renderer, res); - } else { - res.render('search_projects', { title: 'Express', json: false}); - } - -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/search_tag.js b/vnfcatalogue/VNF_Catalogue/routes/search_tag.js deleted file mode 100644 index cbe8cae..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/search_tag.js +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -/* Post Controller for Tag autocomplete form */ -router.get('/', function(req, res) { - tag_partial = req.param('key'); - db_pool.getConnection(function(err, connection) { - - sql_query = 'select tag_name from tag where tag_name like "%'+ tag_partial + '%" limit 5'; - // TODO find why it works and not above - connection.query(sql_query, function (error, results, fields) { - console.log(results); - - var data=[]; - for(i = 0; i < results.length; i++) { - data.push(results[i].tag_name.replace(/\r?\n|\r/g, '')); - } - console.log(results); - connection.release(); - res.end(JSON.stringify(results)); - - if (error) throw error; - }); - }); -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/search_vnf.js b/vnfcatalogue/VNF_Catalogue/routes/search_vnf.js deleted file mode 100644 index a5cf09c..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/search_vnf.js +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -/* Post Controller for Search Vnf autocomplete form */ -router.get('/', function(req, res) { - tag_partial = req.param('key'); - db_pool.getConnection(function(err, connection) { - - sql_query = 'select vnf_name from vnf where vnf_name like "%'+ tag_partial + '%" limit 5'; - // TODO find why it works and not above - connection.query(sql_query, function (error, results, fields) { - console.log(results); - - var data=[]; - for(i = 0; i < results.length; i++) { - data.push(results[i].vnf_name.replace(/\r?\n|\r/g, '')); - } - console.log(results); - connection.release(); - res.end(JSON.stringify(results)); - - if (error) throw error; - }); - }); -}); - -module.exports = router; diff --git a/vnfcatalogue/VNF_Catalogue/routes/vnf_tag_association.js b/vnfcatalogue/VNF_Catalogue/routes/vnf_tag_association.js deleted file mode 100644 index d1a3d72..0000000 --- a/vnfcatalogue/VNF_Catalogue/routes/vnf_tag_association.js +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Kumar Rishabh and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -var express = require('express'); -var router = express.Router(); - -/* Post controller for VNF_TAG Association */ -router.post('/', function(req, res) { - req.checkBody("tag_name", "TAG Name must not be empty").notEmpty(); - req.checkBody("vnf_name", "VNF Name must not be empty").notEmpty(); - - var errors = req.validationErrors(); - console.log(errors); - - var response = ''; for(var i = 0; i < errors.length; i++) { - console.log(errors[i]['msg']); - response = response + errors[i]['msg'] + '; '; - } - - if(errors) { res.status(500); - res.send({'error': response}); - return; - } - - var tag_name = req.param('tag_name'); - var vnf_name = req.param('vnf_name'); - - db_pool.getConnection(function(err, connection) { - // Use the connection - //sql_query = 'INSERT INTO tag SET ?' - sql_query = 'insert into vnf_tags(vnf_id, tag_id) values ((select vnf_id from vnf where vnf_name = \'' + vnf_name + '\'), (select tag_id from tag where tag_name = \'' + tag_name + '\'))'; - console.log(sql_query); - connection.query(sql_query, function (error, results, fields) { - // And done with the connection. - - connection.release(); - res.end('{"success" : "Updated Successfully", "status" : 200}'); - - // Handle error after the release. - if (error) throw error; - // Don't use the connection here, it has been returned to the pool. - }); - }); - - res.end('{"success" : "Updated Successfully", "status" : 200}'); - //res.render('vnf_tag_association', { title: 'Express' }); -}); - -module.exports = router; |