Skip to content

Commit

Permalink
issue-218: crete migrations for default assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
¨caiovelp¨ committed Dec 20, 2024
1 parent f12e42f commit 14086d3
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 3 deletions.
3 changes: 1 addition & 2 deletions app/helpers/assertions_pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ def replace_placeholders(template, values, records = [])

record_template = template.scan(/<% records.each do \|record\| %>(.*?)<% end %>/m).flatten.first
unless record_template.nil?
record_template = template.scan(/<% records.each do \|record\| %>(.*?)<% end %>/m).flatten.first
record_text = records.map do |record|
record_content = record_template.dup
record.each do |key, value|
record_content.gsub!("<%= var('#{key}') %>", value.to_s)
record_content.gsub!("<%= record['#{key}'] %>", value.to_s)
end
record_content
end.join("")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class AddQueryAndAssertionForExternalParticipant < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
INSERT INTO queries (name, sql, description, created_at, updated_at)
VALUES (
'DECLARAÇÃO - Participante externo em defesa de tese',
'SELECT
s.name as nome_aluno,
l.name as nivel_aluno,
e.thesis_defense_date as data,
p.name as nome_professor
FROM
thesis_defense_committee_participations tdcp, enrollments e, students s, professors p, levels l
WHERE
tdcp.enrollment_id = e.id AND
e.student_id = s.id AND
tdcp.professor_id = p.id AND
e.level_id = l.id AND
e.enrollment_number = :matricula_aluno AND
p.cpf = :cpf_professor',
'Declaração de participante externo em defesa de dissertação.',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL

query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()']

execute <<-SQL
INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at)
VALUES
(#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(#{query_id}, 'cpf_professor', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
SQL

execute <<-SQL
INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at)
VALUES (
'Declaração de participante externo em defesa de tese',
#{query_id},
'A quem possa interessar, Declaramos que o professor <%= var(''nome_professor'') %> participou da banca de defesa da dissertação de <%= var(''nivel_aluno'') %> de <%= var(''nome_aluno'') %>, no dia <%= var(''data'') %>.',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL
end

def down
execute <<-SQL
DELETE FROM assertions
WHERE name = 'Declaração de participante externo em defesa de tese';
SQL

execute <<-SQL
DELETE FROM query_params
WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Participante externo em defesa de tese');
SQL

execute <<-SQL
DELETE FROM queries
WHERE name = 'DECLARAÇÃO - Participante externo em defesa de tese';
SQL
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class AddQueryAndAssertionForExaminingBoard < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
INSERT INTO queries (name, sql, description, created_at, updated_at)
VALUES (
'DECLARAÇÃO - Banca examinadora de defesa',
'SELECT
s.name as nome_aluno,
l.name as nivel_aluno,
e.thesis_title as titulo_tese,
e.thesis_defense_date as data,
p.name as nome_professor,
i.code as codigo_instituicao
FROM
thesis_defense_committee_participations tdcp, enrollments e, students s, professors p, levels l, institutions i
WHERE
tdcp.enrollment_id = e.id AND
e.student_id = s.id AND
tdcp.professor_id = p.id AND
e.level_id = l.id AND
i.id = p.institution_id AND
e.enrollment_number = :matricula_aluno',
'Recupera informações necessárias para a declaração de banca examinadora de defesa de um determinado aluno',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL

query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()']

execute <<-SQL
INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at)
VALUES
(#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
SQL

execute <<-SQL
INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at)
VALUES (
'Declaração da ata de defesa',
#{query_id},
'Declaro, para os devidos fins, que a Banca Examinadora da Defesa de Dissertação de Mestrado intitulada “<%= var(''titulo_tese'') %>”, apresentada pelo aluno <%= var(''nome_aluno'') %>, no dia <%= var(''data'') %>, no no Instituto de Computação da Universidade Federal Fluminense, foi composta pelos seguintes membros:
<% records.each do |record| %>
- Prof. <%= record[''nome_professor''] %>, <%= record[''codigo_instituicao''] %>
<% end %>',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL
end

def down
execute <<-SQL
DELETE FROM assertions
WHERE name = 'Declaração da ata de defesa';
SQL

execute <<-SQL
DELETE FROM query_params
WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Banca examinadora de defesa');
SQL

execute <<-SQL
DELETE FROM queries
WHERE name = 'DECLARAÇÃO - Banca examinadora de defesa';
SQL
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class AddQueryAndAssertionForAvulsoStudent < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
INSERT INTO queries (name, sql, description, created_at, updated_at)
VALUES (
'DECLARAÇÃO - Disciplinas de aluno avulso',
'SELECT
s.name as nome_aluno,
s.cpf as cpf_aluno,
c.name as nome_disciplina,
c.workload as carga_horaria,
cs.year as ano_disciplina,
cs.semester as semestre_disciplina,
ce.grade as nota,
ce.situation as situacao
FROM
course_classes cs, class_enrollments ce, enrollments e, courses c, students s
WHERE
cs.id = ce.course_class_id AND
ce.enrollment_id = e.id AND
c.id = cs.course_id AND
e.student_id = s.id AND
cs.year = :ano_semestre_busca AND
cs.semester = :numero_semestre_busca AND
e.enrollment_number = :matricula_aluno',
'Recupera as notas das disciplinas que um avulso obteve num determinado ano/semestre.',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL

query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()']

execute <<-SQL
INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at)
VALUES
(#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(#{query_id}, 'ano_semestre_busca', NULL, 'Integer', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
(#{query_id}, 'numero_semestre_busca', NULL, 'Integer', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
SQL

execute <<-SQL
INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at)
VALUES (
'Declaração de relatório de disciplinas para aluno avulso',
#{query_id},
'DECLARAÇÃO
Declaro, para os devidos fins, que <%= var(''nome_aluno'') %> cursou como Aluno Avulso as seguintes disciplinas do Programa de Pós-Graduação em Computação, nos termos do Art. 15 do Regulamento dos Programas de Pós-Graduação Stricto Sensu da Universidade Federal Fluminense.
<% records.each do |record| %>
<%= record[''counter''] %>. Nome da disciplina: "<%= record[''nome_disciplina''] %>"
Carga horaria total: <%= record[''carga_horaria''] %>
Período: <%= var(''ano_disciplina'') %>/<%= var(''semestre_disciplina'') %>
Nota: <%= record[''nota''] %>
Situação final: <%= record[''situacao''] %>
<% end %>',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
SQL
end

def down
execute <<-SQL
DELETE FROM assertions
WHERE name = 'Declaração de relatório de disciplinas para aluno avulso';
SQL

execute <<-SQL
DELETE FROM query_params
WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Disciplinas de aluno avulso');
SQL

execute <<-SQL
DELETE FROM queries
WHERE name = 'DECLARAÇÃO - Disciplinas de aluno avulso';
SQL
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14086d3

Please sign in to comment.