diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..52aa1dd3f788667537c5aa7e72ee93d7461f290e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM node:latest + +RUN apt-get -y update -qq && apt-get install -y -qq apt-utils tree + +COPY . . + +RUN npm install + +EXPOSE 4001 + +CMD npm start \ No newline at end of file diff --git a/README.md b/README.md index 31d4f1d6f49515b19a456f79629ce4c0e7fdff8f..ae82e7f2f25193f28e1ceff9117a5942d5b6c7c3 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,30 @@ The result will be something similar to: { "category_name": "Categoria teste", "category_description": "Categoria usada para testar funcionalidades" -} \ No newline at end of file +} +``` + +## Deploy on SMPPIRHOMOLOGA + +Whenever you are ready to deploy, please change the `datasources.json` with the `datasources.json.homologa`. + +After that, you can use the Docker image: + +Para criar a imagem nova + +`sudo docker build --tag mapping-api .` + +Para exportar a imagem + +`sudo docker save -o ~/mapping-api.tar mapping-api` + +Para importar a image + +`sudo docker load -i ~/mapping-api.tar ` + +Para rodar a imagem + +`sudo docker run -d --rm -p 4001:4001 --net="host" --name mapping-api mapping-api` + + +:warning: O `-d` significa daemon, não quiser que o comando de rodar imagem rode em segundo plano, remova este argumento :warning: \ No newline at end of file diff --git a/common/models/category.js b/common/models/category.js index 050036846587c89ded4f5994f283fa122a618f6d..86cbfd695d4efe9e92ba3f5301f16ab4e0b20679 100644 --- a/common/models/category.js +++ b/common/models/category.js @@ -1,4 +1,73 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; module.exports = function(Category) { + Category.csvexport = function(res, callback ) { + var datetime = new Date(); + var datetimeFuture = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate()+7) + res.set('Expires', datetimeFuture+''); + res.set('Cache-Control', 'max-age=0, no-cache, must-revalidate, proxy-revalidate'); + res.set('Last-Modified', datetime+''); + res.set('Content-Type','application/force-download'); + res.set('Content-Type','application/octet-stream'); + res.set('Content-Type','application/download'); + res.set('Content-Disposition','attachment;filename=category.csv'); + res.set('Content-Transfer-Encoding','binary'); + + Category.find(function(err, categories) + { + // conversão JSON para CSV + // cabeçalho do csv + var headers = { + category_name: "category_name", + category_description: "category_description", + id: "id" + }; + + //Adiciona os headers no CSV + categories.unshift(headers); + + var jsonObject = JSON.stringify(categories); + var array = typeof jsonObject != 'object' ? JSON.parse(jsonObject) : jsonObject; + var csv = ''; + + for (var i = 0; i < array.length; i++) { + var line = ''; + for (var index in array[i]) { + if (line != '') line += ';' // aqui muda o separador do csv + line += array[i][index]; + } + csv += line + '\n'; + } + res.send(csv); + }); + }; + + Category.remoteMethod('csvexport', + { + accepts: [ + {arg: 'res', type: 'object', 'http': {source: 'res'}} + ], + returns: {}, + http: {path: '/csv', verb: 'get'}, + }); }; diff --git a/common/models/end_user.js b/common/models/end_user.js index 216d33748cba86cba391a8722c8948faa148bfe5..c3aa7e66feb20093bf20fb102e4bb45ac06f63ee 100644 --- a/common/models/end_user.js +++ b/common/models/end_user.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; module.exports = function(EndUser) { diff --git a/common/models/geolocation.js b/common/models/geolocation.js index 77d4c050d351d866bf0fa0172a3c3a052565d5c6..cbf8f0f3c8e71538346ff289d0b3fd4784b12da7 100644 --- a/common/models/geolocation.js +++ b/common/models/geolocation.js @@ -1,5 +1,99 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; module.exports = function(Geolocation) { + Geolocation.csvexport = function(type, res, callback ) { + if (type == "padrao" || type == "android"){ + var datetime = new Date(); + var datetimeFuture = new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate()+7) + res.set('Expires', datetimeFuture+''); + res.set('Cache-Control', 'max-age=0, no-cache, must-revalidate, proxy-revalidate'); + res.set('Last-Modified', datetime +''); + res.set('Content-Type','application/force-download'); + res.set('Content-Type','application/octet-stream'); + res.set('Content-Type','application/download'); + res.set('Content-Disposition','attachment;filename=geolocation.csv'); + res.set('Content-Transfer-Encoding','binary'); + + Geolocation.find(function(err, geolocations) { + // conversão JSON para CSV + // cabeçalho do csv + var headers = { + category_id: "category_id", + geolocation_name: "geolocation_name", + latitude: "latitude", + longitude: "longitude", + when_sent: "when_sent", + description_location: "description_location", + user_id: "user_id", + id: "id" + }; + + // cabeçalho do csv - Adiciona android_id + if (type == "android"){ + headers['android_id'] = "android_id" + } + + //Ordena header + var ordered_header = {} + Object.keys(headers).sort().forEach(function(key) { + ordered_header[key] = headers[key]; + }); + + //Adiciona os headers no CSV + geolocations.unshift(headers); + + // Posição do Android ID 4 atualmente esta em 8 + var jsonObject = JSON.stringify(geolocations); + var array = typeof jsonObject != 'object' ? JSON.parse(jsonObject) : jsonObject; + var csv = ''; + + for (let i = 0; i < array.length; i++) { + var line = ''; + var aux = {} + Object.keys(array[i]).sort().forEach(function(key) { + aux[key] = array[i][key]; + }); + if (type == "padrao"){ + delete aux["android_id"]; + } + for (let index in aux) { + if (line != '') line += ';' // aqui muda o separador do csv + line += array[i][index]; + } + csv += line + '\n'; + } + res.send(csv); + }); + } + }; + Geolocation.remoteMethod('csvexport', + { + accepts: [ + {arg: 'type', type: 'string'}, + {arg: 'res', type: 'object', 'http': {source: 'res'}} + ], + returns: {}, + http: {path: '/csv/:type', verb: 'get'} + }); }; diff --git a/enviroment.js b/enviroment.js index e8faa909d2bd1715542a0370e9e796ce3ae052cc..5f2483cf96c5a1861760ecb74971af5028fd9244 100644 --- a/enviroment.js +++ b/enviroment.js @@ -1,4 +1,24 @@ -const URL = 'http://localhost:3000/api/'; +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + +const URL = 'http://localhost:4001/api/'; const randomLowerCase = function() { let possible = 'abcdefghijklmnopqrstuvwxyz'; diff --git a/server/boot/access-control.js b/server/boot/access-control.js index 38f66df86ae077ce96e2a0d594d4050024924259..3c52e3868e8ce1faaa916e6198df2ae81031fa6e 100644 --- a/server/boot/access-control.js +++ b/server/boot/access-control.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + /* 2 Permissions : admin, user diff --git a/server/boot/authentication.js b/server/boot/authentication.js index 8e88d4b555e29d66158a7ad189f8abe16fed235f..e6a21eb006f57f451fc52258a712e364e71c03eb 100644 --- a/server/boot/authentication.js +++ b/server/boot/authentication.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; module.exports = function enableAuthentication(server) { diff --git a/server/boot/hook.js b/server/boot/hook.js index 35fea512f23d9aec214aab29a2b292e02e33a9f1..f32cef5fbde18d141a18f0b2a0a7b342d1129791 100644 --- a/server/boot/hook.js +++ b/server/boot/hook.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + module.exports = function(server) { var remotes = server.remotes(); // modify all returned values diff --git a/server/boot/models-automigratioin.js b/server/boot/models-automigratioin.js index 56f146aaaf54ad08c5f4110d1e43e427c9e8ab49..79661101320800c9f434a9cff4aaa2f272e24023 100644 --- a/server/boot/models-automigratioin.js +++ b/server/boot/models-automigratioin.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + // module.exports = function(app) { // 'use strict'; // var db = app.dataSources.SMPPIR_CheckIn2; diff --git a/server/boot/root.js b/server/boot/root.js index 6adce90ad3574a847350e866bf2bbd3fb6240c58..46ca3155fd0d77ea37267be772bbdb651eaabb77 100644 --- a/server/boot/root.js +++ b/server/boot/root.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; module.exports = function(server) { diff --git a/server/config.json b/server/config.json index ff5c9c9d302706d42b389614189c6705e77c7430..440a9393de249fcc9717e193388bd1cdef90b55e 100644 --- a/server/config.json +++ b/server/config.json @@ -1,7 +1,7 @@ { "restApiRoot": "/api", "host": "0.0.0.0", - "port": 3000, + "port": 4001, "remoting": { "context": false, "rest": { diff --git a/server/datasources.json.homologa b/server/datasources.json.homologa new file mode 100644 index 0000000000000000000000000000000000000000..fec5524b67a15405573a8bf974424153d9e9a5b4 --- /dev/null +++ b/server/datasources.json.homologa @@ -0,0 +1,18 @@ +{ + "db": { + "name": "db", + "connector": "memory" + }, + "SMPPIR_CheckIn2": { + "host": "localhost", + "port": 5432, + "url": "postgres://smppir:123mudar@localhost:5432/smppir_checkin?ssl=false", + "database": "smppir_checkin", + "password": "123mudar", + "name": "SMPPIR_CheckIn2", + "connector": "postgresql", + "user": "postgres", + "ssl": false + } + } + \ No newline at end of file diff --git a/server/server.js b/server/server.js index ef738abce2052d808ddcb92db1a3a3f0e4b17b96..b3c308d47e375bd07215d09a2afc25c6a4b2a9a2 100644 --- a/server/server.js +++ b/server/server.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + 'use strict'; var loopback = require('loopback'); diff --git a/test/account.js b/test/account.js index e70a592ec11542d1ece61b40d65628dd4cbc1e8f..c9f58f83dad74c6efb8f5b96032c67fc62617a39 100644 --- a/test/account.js +++ b/test/account.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + var chakram = require('chakram'), expect = chakram.expect; var env = require('../enviroment'); const URL = env.URL; diff --git a/test/category.js b/test/category.js index ac84fac4aec5c23433a9996a784ad70ff65e90af..5194689e51a4b12a36d1681627e0ad719a9d4617 100644 --- a/test/category.js +++ b/test/category.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + var chakram = require('chakram'), expect = chakram.expect; var env = require('../enviroment'); const URL = env.URL; diff --git a/test/geolocation.js b/test/geolocation.js index 3808bac278c039843490a08189efd07f2d525e0d..66ee565ebbd74583fe6203bfaf927d375898f3cd 100644 --- a/test/geolocation.js +++ b/test/geolocation.js @@ -1,3 +1,23 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of SMPPIR-CheckIn. + +SMPPIR-CheckIn is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SMPPIR-CheckIn is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SMPPIR-CheckIn. If not, see <https://www.gnu.org/licenses/>. +*/ + var chakram = require('chakram'), expect = chakram.expect; var env = require('../enviroment'); const URL = env.URL;