Commit e742b255 authored by Rafael S Castilho's avatar Rafael S Castilho

Merge branch 'development' into 'master'

Development

See merge request !58
parents 18380179 ecee8c50
.git
.dockerignore
docker-compose.yml
Dockerfile
.env
package-lock.json
*.bak
ENSALAMENTO_DB_USER=ensalamento
ENSALAMENTO_DB_PASSWORD=123mudar
ENSALAMENTO_NODE_ENV=development
/client/
\ No newline at end of file
{
"extends": "loopback"
}
\ No newline at end of file
sie-report
*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
node_modules
npm-debug.log
.vscode/
*.sublime*
dist
*xunit.xml
.nyc_output/
.editorconfig
.env
[submodule "bin/ensalador"]
path = bin/ensalador
url = https://gitlab.c3sl.ufpr.br/ensalamento/ensalador.git
branch = development
{
"generator-loopback": {}
}
\ No newline at end of file
FROM node:8.12-stretch
LABEL maintainer="horstmannmat <mch15@inf.ufpr.br>"
# Set an environment variable to prevent debian warning.
ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
# Set an environment variable to store where the app is installed to inside of the Docker image.
ENV WORKSPACE /app
RUN mkdir -p $WORKSPACE
# Install apt-utils to prevent warning messages
RUN apt-get -qq update -y && apt-get -qq install -y apt-utils git
# Install necessary libs to compile and run ensalador
RUN apt-get -qq install -y cmake libstdc++6 libyaml-cpp-dev libboost-all-dev --no-install-recommends
RUN git clone --quiet https://github.com/saebyn/munkres-cpp.git /tmp/munkres-cpp && cd /tmp/munkres-cpp && mkdir build && cd build && cmake .. && make && make install && cd / && rm -rf /tmp/munkres-cpp
# Change WORKSPACE owner
RUN chown -R node:node $WORKSPACE
# Change running user
USER node
# This sets the context of where commands will be ran in and is documented
# on Docker's website extensively.
# Set app directory
WORKDIR $WORKSPACE
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node:node package.json .
COPY --chown=node:node yarn.lock .
# If you are building your code for production
# RUN yarn install --production --frozen-lockfile --silent --non-interactive
RUN yarn install --frozen-lockfile --silent --non-interactive
## Compile ensalor here
RUN mkdir /app/bin/ && mkdir /app/bin/ensalador
COPY --chown=node:node bin/ensalador /app/bin/ensalador
RUN cd /app/bin/ensalador && cmake . && make && cd /app
# Bundle app source
COPY --chown=node:node . .
ENV PATH=$PATH:/app/node_modules/.bin
EXPOSE 3000
ENTRYPOINT ["/app/ensalamento-entrypoint.sh"]
CMD ["DEVELOPMENT"]
This diff is collapsed.
# Ensalamento-back
## Getting Started
```bash
git clone --recurse-submodules git@gitlab.c3sl.ufpr.br:ensalamento/ensalamento-back
cd ensalamento-back
docker-compose up
```
## Prerequisite: install Node.js
......
"use strict";
var async = require('async');
var path = require('path');
var models = require(path.resolve(__dirname,'../common/models/models.js'))
var app = require(path.resolve(__dirname, '../server/server'));
var old_db = require(path.resolve(__dirname, '../bin/load-old-database'));
var ds = app.datasources.ensalamento;
var lbTables = models.models;
//lbTables.splice(31,2)
console.log(lbTables)
var LOG_CREATE = false;
ds.automigrate(lbTables, function(err) {
if (err) throw err;
async.waterfall([
loadModelFromOldDB(old_db.get_salas, app.models.Sala, LOG_CREATE),
loadModelFromOldDB(old_db.get_blocos, app.models.Bloco, LOG_CREATE),
loadModelFromOldDB(old_db.get_Tipodesala, app.models.Tipodesala, LOG_CREATE),
loadModelFromOldDB(old_db.get_professores, app.models.Professor, LOG_CREATE),
loadModelFromOldDB(old_db.get_departamentos, app.models.Departamento, LOG_CREATE),
loadModelFromOldDB(old_db.get_setores, app.models.Setor, LOG_CREATE),
criaUsuario,
criaSecretario,
criaRoles,
atribuiRoles,
criaRecursodesala,
criaTipodesala,
criaEnsalamento,
criaSemestre,
criaTurmas,
criaHorarios,
loadModelFromOldDB(old_db.get_disciplinas, app.models.Disciplina, LOG_CREATE),
loadModelFromOldDB(old_db.get_equivalenciasDisciplinas, app.models.Equivalenciadisciplina, LOG_CREATE),
loadModelFromOldDB(old_db.get_cursos, app.models.Curso, LOG_CREATE),
loadRelationsFromOldDB(old_db.get_cursoDisciplina, app.models.Curso, "disciplinas", LOG_CREATE),
],
function(err) {
if (err) throw err;
ds.disconnect();
})
});
// Returns a function that populate a DB model with data loaded from
// old database (see migrate-old-schema.js and load-old-dabase.js codes)
function loadModelFromOldDB(oldDataAccess, model, create_log){
return (cb) => {
oldDataAccess.then(data => {
async.each(data, (instance, callback) => {
if(create_log) console.log('Trying to insert:', instance);
model.upsert(instance, (err, instanceCreated) => {
callback(err);
if(create_log) console.log('Created:', instanceCreated);
});
}, (err) => {
if (err) throw err;
cb(err);
});
});
}
}
function addRelationBetweenModels(model, modelRelationName,
relationInstance, cb, create_log){
var query = {where: {}};
query.where[relationInstance.pkey_name] = relationInstance.pkeys[0];
model.findOne(query, (err,data) => {
if (err ) throw err;
if(data)
data[modelRelationName].add(relationInstance.pkeys[1], (err,data) => {
cb(err,data);
});
});
}
// Returns a function that populate a relation DB model with data loaded from
// old database (see migrate-old-schema.js and load-old-dabase.js codes)
function loadRelationsFromOldDB(oldDataAccess, model, modelRelationName, create_log){
return function(cb){
oldDataAccess.then(data => {
async.each(data, (instance, callback) => {
if(create_log){
console.log('Trying to insert relation on ',
modelRelationName,':', instance
);
}
addRelationBetweenModels(
model,
modelRelationName,
instance,
(err, instanceCreated) => {
callback(err);
if(create_log) console.log('Created:', instanceCreated);
});
}, (err) => {
if (err) throw err;
cb(err);
});
});
}
}
function criaSemestre(cb) {
app.models.Semestre.create({"semestre":"2017/1"},(err,obj)=>{
cb(err);
});
}
function criaTurmas(cb){
app.models.Turma.create([
{
"disciplinaCod":"ci055",
"data_inicio":"2019-02-26T13:58:50.150Z",
"data_fim":"2019-02-26T13:58:50.150Z",
"semestre": "2017/1",
"codigo": "t1",
"organizador":"a",
"departamentoCod":"informatica",
"vagas":49,
"ano":2019,
"periodo": 1
},
{
"disciplinaCod":"ci055",
"data_inicio":"2019-02-26T13:58:50.150Z",
"departamentoCod":"informatica",
"data_fim":"2019-02-26T13:58:50.150Z",
"semestre": "2018/1",
"codigo": "t2",
"organizador":"a",
"vagas":49,
"ano":2019,
"periodo": 1
},
{
"disciplinaCod":"ci055",
"data_inicio":"2019-02-26T13:58:50.150Z",
"semestre": "2017/1",
"data_fim":"2019-02-26T13:58:50.150Z",
"codigo": "t3",
"organizador":"a",
"departamentoCod":"informatica",
"vagas":49,
"ano":2019,
"periodo": 1
},
{
"disciplinaCod":"ci055",
"data_inicio":"2019-02-26T13:58:50.150Z",
"data_fim":"2019-02-26T13:58:50.150Z",
"semestre": "2017/1",
"codigo": "t4",
"organizador":"a",
"vagas":49,
"ano":2019,
"departamentoCod":"informatica",
"periodo": 1
},
], function(err, turmas){
var _professores = ["CI065A","elias","albini","agregio"]
var _cursos = ["21A","96A","23A","21A"]
for(var i=0; i<turmas.length; i++) {
turmas[i].horarios.add(i+1)
turmas[i].professores.add(_professores[i])
turmas[i].cursos.add(_cursos[i])
}
cb(err);
}.bind(this));
}
function criaHorarios(cb){
app.models.Horario.create([
{
livre: false,
dia:2,
horario_inicial:"15:30:00",
horario_final:"17:30:00",
ensalamentoId:1
},
{
livre: false,
dia:3,
horario_inicial:"15:30:00",
horario_final:"17:30:00",
ensalamentoId:1
},
{
livre: false,
dia:4,
horario_inicial:"15:30:00",
horario_final:"17:30:00",
ensalamentoId:1
},
{
livre: false,
dia:2,
horario_inicial:"15:30:00",
horario_final:"17:30:00",
ensalamentoId:1
}
], function(err, horarios){
cb(err);
}.bind(this));
}
function criaEnsalamento(cb){
app.models.Ensalamento.create({}, function(err){
cb(err);
}.bind(this));
}
function criaRecursodesala(cb){
var recursos = [
{descricao: 'recurso1'},
{descricao: 'recurso2'}
];
async.each(recursos, function(recurso, callback) {
app.models.Recursodesala.upsert(recurso, function(err, model) {
callback(err);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaTipodesala(cb){
var tipos = [
{nome: 'tipo1'},
{nome: 'tipo2'}
];
async.each(tipos, function(tipo, callback) {
app.models.Tipodesala.upsert(tipo, function(err, model) {
callback(err);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaSecretario(cb){
var secretarios = [
{email:'bcc@secretario.com',vinculo: 'curso',valor_vinculo:"21A"},
{email:'informatica@secretario.com',vinculo: 'departamento',valor_vinculo:"informatica"},
{email:'exatas@secretario.com',vinculo: 'setor',valor_vinculo:"exatas",}
]
async.each(secretarios, function(secretario, callback) {
app.models.Secretario.create(secretario, (err,s)=>{
app.models.Usuario.findOne({where:{email: secretario.email}}, ( err,user)=>{
if (err && !user ) throw err;
user.updateAttribute("secretarioCod",s.id,(err)=>{
if (err) throw err;
if(LOG_CREATE) console.log('Created Secretario:', secretario);
callback(err);
})
})
})
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaRoles(cb){
var roles = [
{name: 'admin'},
{name: 'comissao'},
{name: 'secretario_setor'},
{name: 'secretario_dpto'},
{name: 'secretario_curso'}
];
async.each(roles, function(role, callback) {
app.models.Role.create(role, function(err, model) {
if (err) throw err;
if(LOG_CREATE) console.log('Created role:', model);
callback(err);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function atribuiRoles(cb){
var atribuicoes = [
{email:'admin@admin.com',role: 'admin'},
{email:'comissao@comissao.com',role: 'comissao'},
{email:'exatas@secretario.com',role: 'secretario_setor'},
{email:'informatica@secretario.com',role: 'secretario_dpto'},
{email:'bcc@secretario.com',role: 'secretario_curso'}
]
async.each(atribuicoes, function(atribuicao, callback) {
app.models.Usuario.findOne({where:{email: atribuicao.email}}, function(err, user){
user.setRole(atribuicao.role,function(err,data){
if (err) throw err;
if(LOG_CREATE) console.log('Assign '+atribuicao.role+ ' Role to initial User:', user);
callback(err);
});
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaUsuario(cb){
var usuarios = [
{username: 'admin',nome:'Administrador do Sistema', email: 'admin@admin.com', password: '123mudar'},
{username: 'comissao',nome:'Comissão de Ensalamento', email: 'comissao@comissao.com', password: '123mudar'},
{username: 'exatas',nome:'Secretário do Setor', email: 'exatas@secretario.com', password: '123mudar'},
{username: 'informatica',nome:'Secretário de Departamento,', email: 'informatica@secretario.com', password: '123mudar'},
{username: 'bcc',nome:'Secretário de Curso', email: 'bcc@secretario.com', password: '123mudar'}
];
async.each(usuarios, function(usuario, callback) {
app.models.Usuario.create(usuario, function(err, model) {
if (err) throw err;
callback(err);
if(LOG_CREATE) console.log('Created user:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
function criaEquivalencia(cb){
app.models.Disciplina.find({where:{id:1}}, function(err, disc){
disc[0].addEquivalencia(2,function(err,data){
if (err) throw err;
if(LOG_CREATE) console.log('Created Equivalenciadisciplina:', disc);
cb(err);
});
});
}
function criaDisciplina(cb){
var disciplinas = [
{"codigo": "d1", "nome": "disciplina1", "carga_horaria": 0,"duracao": "semestral","modalidade": "presencial"},
{"codigo": "d2", "nome": "disciplina2", "carga_horaria": 1,"duracao": "semestral","modalidade": "distância"},
{"codigo": "d3", "nome": "disciplina3", "carga_horaria": 2,"duracao": "anual","modalidade": "presencial"}
];
async.each(disciplinas, function(disciplina, callback) {
app.models.Disciplina.upsert(disciplina, function(err, model) {
if (err) throw err;
callback(err);
if(LOG_CREATE) console.log('Created:', model);
});
}, function(err) {
if (err) throw err;
cb(err);
});
}
var path = require('path');
var async = require('async');
var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.ensalamento;
var models = require(path.resolve(__dirname,'../common/models/models.js'))
var lbTables = models.models_lower;
var count = lbTables.length;
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
lbTables.forEach(function(table) {
ds.discoverAndBuildModels(table, {schema: 'public'}, function(err, models) {
if (err) throw err;
models[table.capitalize()].find(function(err, model) {
if (err) return console.log(err);
console.log(model);
});
});
count--;
if (count === 0)
ds.disconnect();
});
var path = require('path');
var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.ensalamento;
var models = require(path.resolve(__dirname,'../common/models/models.js'))
var lbTables = models.models_lower;
var count = lbTables.length;
lbTables.forEach(function(table) {
ds.discoverSchema(table, {schema: "public"}, function(err, schema) {
if (err) throw err;
var json = JSON.stringify(schema, null, ' ');
console.log(json);
});
count--;
if (count === 0)
ds.disconnect();
});
Subproject commit ac1b7c80fc9984fbf4798880ae82c89308d88cf0
var path = require("path");
var fs = require("fs");
var LOG_QUERIES = false;
const { Client } = require('pg')