Commit e20b2257 authored by didonet's avatar didonet

Added functionality for including validated sections (aproveitamento).

Added beta code for better pop-up select (not yet finished).
parent bdb894c5
......@@ -231,7 +231,7 @@ public class Professor extends Person {
phr = new Phrase("como orientador(a) ",ReportUtil.getNormalTextFont());
p.add(phr);
}
phr = new Phrase("da banca examinadora da "+c.getKind()+" de Dissertação de ",ReportUtil.getNormalTextFont());
phr = new Phrase("da banca examinadora da "+c.getKind()+" do Trabalho de Conclusão de ",ReportUtil.getNormalTextFont());
p.add(phr);
if (r.getRegKind() == RegistrationKind.Mestrado)
phr = new Phrase(Configuration.findConfigValueByName(Configuration.MASTER_COURSE_NAME),ReportUtil.getNormalTextFont());
......
package br.ufpr.c3sl.sapos.models.scholar;
import java.io.IOException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
......@@ -63,10 +63,12 @@ public class Transcript {
@ManyToOne
private SectionPos transcriptSection;
public static List<Transcript> findAllTranscripts() {
return entityManager().createNativeQuery("select * from transcript a, person b, registration c where a.student = c.id and c.student=b.id order by b.name",Transcript.class).getResultList();
}
public static List<Transcript> findTranscriptByRegInYearAndPeriodOrder(Registration r, Boolean onlyValidTranscripts) {
String sql = "select * from transcript t, section_pos sp" +
" where t.student = "+r.getId()+" and t.transcript_section = sp.id ";
......@@ -127,7 +129,7 @@ public class Transcript {
try {
ReportUtil.getPdfWriter(document,response);
//PdfWriter writer = ReportUtil.getPdfWriter(document,response);
} catch (IOException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -243,6 +245,7 @@ public class Transcript {
}
public static void historyPdf(Registration reg, HttpServletResponse response) {
response.setContentType("application/pdf");
//left,right,top,bottom margins
Document document = new Document(PageSize.A4, 80, 80, 80, 80);
......@@ -258,16 +261,19 @@ public class Transcript {
try {
try {
ReportUtil.getPdfWriter(document, response);
//PdfWriter writer = ReportUtil.getPdfWriter(document, response);
} catch (IOException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.open();
ReportUtil.makeHeader(document, "HISTÓRICO ESCOLAR");
document.open();
ReportUtil.makeHeader(document, "HISTÓRICO ESCOLAR");
Phrase phr = new Phrase("Curso: ", ReportUtil.getTitleTextFont());
document.add(phr);
if (reg.getRegKind() == RegistrationKind.Doutorado)
......@@ -403,11 +409,53 @@ public class Transcript {
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
}
Collection<ValidatedSection> vss = ValidatedSection.findValidatedSectionsPerRegistration(reg.getId());
for(ValidatedSection vs:vss){
if (checkTeachingPractice) {
for (int i = 0; i < teachingCourses.length; i++){
if (teachingCourses[i].trim().equals(vs.getCode() ) ){
hasTeachingPractice = true;
break;
}
}
}
cell = new PdfPCell(new Paragraph(vs.getPeriod().toString()+"/"+vs.getSectionYear().toString(), ReportUtil.getTableTextFont()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vs.getCode(), ReportUtil.getTableTextFont()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vs.getName(), ReportUtil.getTableTextFont()));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vs.getConcept(), ReportUtil.getTableTextFont()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vs.getCredits().toString(), ReportUtil.getTableTextFont()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vs.getWorkload().toString(), ReportUtil.getTableTextFont()));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
document.add(table);
ReportUtil.makeConceptsTableFooter(document);
if (checkTeachingPractice && ! hasTeachingPractice){
if (StudentGrant.studentGrantTimeInMonths(reg.getId()) >= 12) {
......@@ -432,7 +480,7 @@ public class Transcript {
if (reg.getDefenseDate() != null) {
phr = new Phrase("Dissertação aprovada em: ", ReportUtil.getTitleTextFont());
phr = new Phrase("Trabalho de conclusão aprovados em: ", ReportUtil.getTitleTextFont());
document.add(phr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(reg.getDefenseDate());
......@@ -519,8 +567,9 @@ public class Transcript {
document.add(p);
ReportUtil.makeFooter(document);
document.close();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -554,7 +603,7 @@ public class Transcript {
try {
ReportUtil.getPdfWriter(document, response);
//PdfWriter writer = ReportUtil.getPdfWriter(document, response);
} catch (IOException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......
......@@ -68,4 +68,5 @@ privileged aspect Transcript_Roo_JavaBean {
this.transcriptSection = transcriptSection;
}
}
package br.ufpr.c3sl.sapos.models.scholar;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
import org.springframework.roo.addon.tostring.RooToString;
import br.ufpr.c3sl.sapos.models.scholar.enums.ConceptTranscript;
@RooJavaBean
@RooToString
@RooJpaEntity
public class ValidatedSection {
@NotNull
private String code;
@NotNull
private String name;
private Integer period;
private Integer sectionYear;
private Integer credits;
public String concept;
private Integer grade;
private Integer workload;
@Column(columnDefinition="text")
private String program;
private String professorName;
@ManyToOne
private Registration student;
public static Collection<ValidatedSection> findValidatedSectionsPerRegistration(long registration) {
return entityManager().createNativeQuery(
"SELECT * FROM validated_section " +
" WHERE student ="+ registration,
ValidatedSection.class).getResultList();
}
}
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package br.ufpr.c3sl.sapos.models.scholar;
import org.springframework.beans.factory.annotation.Configurable;
privileged aspect ValidatedSection_Roo_Configurable {
declare @type: ValidatedSection: @Configurable;
}
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package br.ufpr.c3sl.sapos.models.scholar;
import br.ufpr.c3sl.sapos.models.scholar.ValidatedSection;
import java.lang.Integer;
import java.lang.Long;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PersistenceContext;
import javax.persistence.Version;
import org.springframework.transaction.annotation.Transactional;
privileged aspect ValidatedSection_Roo_Entity {
declare @type: ValidatedSection: @Entity;
@PersistenceContext
transient EntityManager ValidatedSection.entityManager;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long ValidatedSection.id;
@Version
@Column(name = "version")
private Integer ValidatedSection.version;
public Long ValidatedSection.getId() {
return this.id;
}
public void ValidatedSection.setId(Long id) {
this.id = id;
}
public Integer ValidatedSection.getVersion() {
return this.version;
}
public void ValidatedSection.setVersion(Integer version) {
this.version = version;
}
@Transactional
public void ValidatedSection.persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
@Transactional
public void ValidatedSection.remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
ValidatedSection attached = ValidatedSection.findValidatedSection(this.id);
this.entityManager.remove(attached);
}
}
@Transactional
public void ValidatedSection.flush() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.flush();
}
@Transactional
public void ValidatedSection.clear() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.clear();
}
@Transactional
public ValidatedSection ValidatedSection.merge() {
if (this.entityManager == null) this.entityManager = entityManager();
ValidatedSection merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
public static final EntityManager ValidatedSection.entityManager() {
EntityManager em = new ValidatedSection().entityManager;
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
return em;
}
public static List<ValidatedSection> ValidatedSection.findAllValidatedSections() {
return entityManager().createQuery("SELECT o FROM ValidatedSection o", ValidatedSection.class).getResultList();
}
public static long ValidatedSection.countValidatedSectiones() {
return entityManager().createQuery("SELECT COUNT(o) FROM ValidatedSection o", Long.class).getSingleResult();
}
public static ValidatedSection ValidatedSection.findValidatedSection(Long id) {
if (id == null) return null;
return entityManager().find(ValidatedSection.class, id);
}
public static List<ValidatedSection> ValidatedSection.findValidatedSectionEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM ValidatedSection o", ValidatedSection.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
}
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package br.ufpr.c3sl.sapos.models.scholar;
import java.lang.Integer;
import java.lang.String;
privileged aspect ValidatedSection_Roo_JavaBean {
public String ValidatedSection.getCode() {
return this.code;
}
public void ValidatedSection.setCode(String code) {
this.code = code;
}
public String ValidatedSection.getName() {
return this.name;
}
public void ValidatedSection.setName(String name) {
this.name = name;
}
public Integer ValidatedSection.getPeriod() {
return this.period;
}
public void ValidatedSection.setPeriod(Integer period) {
this.period = period;
}
public Integer ValidatedSection.getSectionYear() {
return this.sectionYear;
}
public void ValidatedSection.setSectionYear(Integer sectionYear) {
this.sectionYear = sectionYear;
}
public Integer ValidatedSection.getCredits() {
return this.credits;
}
public void ValidatedSection.setCredits(Integer credits) {
this.credits = credits;
}
public String ValidatedSection.getConcept() {
return this.concept;
}
public void ValidatedSection.setConcept(String concept) {
this.concept = concept;
}
public Integer ValidatedSection.getGrade() {
return this.grade;
}
public void ValidatedSection.setGrade(Integer grade) {
this.grade = grade;
}
public Integer ValidatedSection.getWorkload() {
return this.workload;
}
public void ValidatedSection.setWorkload(Integer workload) {
this.workload = workload;
}
public String ValidatedSection.getProgram() {
return this.program;
}
public void ValidatedSection.setProgram(String program) {
this.program = program;
}
public String ValidatedSection.getProfessorName() {
return this.professorName;
}
public void ValidatedSection.setProfessorName(String professorName) {
this.professorName = professorName;
}
public Registration ValidatedSection.getStudent() {
return this.student;
}
public void ValidatedSection.setStudent(Registration student) {
this.student = student;
}
}
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package br.ufpr.c3sl.sapos.models.scholar;
import java.lang.String;
privileged aspect ValidatedSection_Roo_ToString {
public String ValidatedSection.toString() {
StringBuilder sb = new StringBuilder();
sb.append("Code: ").append(getCode()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("Period: ").append(getPeriod()).append(", ");
sb.append("SectionYear: ").append(getSectionYear()).append(", ");
sb.append("Credits: ").append(getCredits()).append(", ");
sb.append("Concept: ").append(getGrade()).append(", ");
sb.append("Grade: ").append(getGrade()).append(", ");
sb.append("Workload: ").append(getWorkload()).append(", ");
sb.append("Program: ").append(getProgram()).append(", ");
sb.append("ProfessorName: ").append(getProfessorName()).append(", ");
sb.append("Student: ").append(getStudent()).append(", ");
return sb.toString();
}
}
......@@ -22,7 +22,9 @@ import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class ReportUtil {
public static final String LOGO_UFPR = "https://sapos:8443/sapos/resources/images/logo_ufpr.jpg";
public static final String LOGO_UFPR = "https://localhost:8443/sapos/resources/images/logo_ufpr.jpg";
// public static final String LOGO_UFPR = "http://localhost:8080/sapos/resources/images/logo_ufpr.jpg";
public static PdfWriter getPdfWriter(Document document, HttpServletResponse response) throws IOException, DocumentException {
return PdfWriter.getInstance(document, response.getOutputStream());
......
package br.ufpr.c3sl.sapos.web;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import br.ufpr.c3sl.sapos.models.people.Professor;
import br.ufpr.c3sl.sapos.models.scholar.Committee;
......@@ -13,6 +25,7 @@ import br.ufpr.c3sl.sapos.models.scholar.Registration;
@RequestMapping("/committees")
@Controller
public class CommitteeController {
private Committee committeeGlobal;
@ModelAttribute("professors")
public java.util.Collection<Professor> populateProfessors() {
return Professor.findAllProfessors();
......@@ -22,4 +35,195 @@ public class CommitteeController {
public java.util.Collection<Registration> populateRegistrations() {
return Registration.findAllRegistrations();
}
private int getIndexProfessor(Professor professor , List<Professor> professors){
for(int i=0; i < professors.size();i++){
if(professor.getId().equals(professors.get(i).getId())){
return i;
}
}
return -1;
}
// , produces = "text/html"
// public String selectForm(@Valid Committee committee, @RequestParam(value = "tipo", required = false)
// String tipo, @RequestParam(value = "op", required = false) Integer op,
// BindingResult bindingResult, Model uiModel) {
@RequestMapping(value = "selecionar", method = {RequestMethod.GET, RequestMethod.PUT})
public String selectForm(@Valid Committee committee, @RequestParam(value = "tipo", required = false)
String tipo, @RequestParam(value = "op", required = true) String opt,
Model uiModel) {
Integer op = new Integer(opt);
if(committeeGlobal == null){
committeeGlobal = committee;
}
if (op == 0) {
uiModel.addAttribute("remover", false);
if (tipo.equals("participants")) {
if (committee.getParticipants() == null){
uiModel.addAttribute("participants", Professor.findAllProfessors());
}else {
List<Professor> t = Professor.findAllProfessors();
for(Professor professor : committee.getParticipants()){
int index = getIndexProfessor(professor, t);
if(index != -1){
t.remove(index);
}
}
//t.removeAll(programa.getTematicas());
uiModel.addAttribute("participants", t);
}
ProfessorController tc = new ProfessorController();
tc.addDateTimeFormatPatterns(uiModel);
return "professors/select";
}
}
else if (op == 1) {
uiModel.addAttribute("remover", true);
if (tipo.equals("participants")) {
if (committee.getParticipants() != null) {
uiModel.addAttribute("participants", committee.getParticipants());
ProfessorController tc = new ProfessorController();
tc.addDateTimeFormatPatterns(uiModel);
return "professors/select";
}
else {
populateEditForm(uiModel, committeeGlobal);
committeeGlobal = null;
return "committee/create";
}
}
}
return "uncaughtException";
}
@RequestMapping(value = "/form/{ids}", method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html")
public String treatSelected(@Valid Committee programa, @PathVariable("ids") String ids, Model uiModel, HttpServletRequest httpServletRequest) {
System.out.println("estah no form");
committeeGlobal = programa;
refreshRelations();
for(String idString : ids.split("\\+")){
Long id = Long.parseLong(idString);
if (Professor.findProfessor(id) != null) {
if (committeeGlobal.getParticipants() == null) {
Set<Professor> participants = new HashSet<Professor>();
participants.add(Professor.findProfessor(id));
committeeGlobal.setParticipants(participants);
}
else {
List<Professor> professorNew = new ArrayList<Professor>(committeeGlobal.getParticipants());
int index = getIndexProfessor(Professor.findProfessor(id), professorNew);
if (index != -1){
professorNew.remove(index);
}
else{
professorNew.add(Professor.findProfessor(id));
}
committeeGlobal.setParticipants(new HashSet<Professor>(professorNew));
}
}
}
populateEditForm(uiModel, committeeGlobal);
if (committeeGlobal.getId() == null) {
committeeGlobal = null;
return "committees/create";
}
else {
committeeGlobal = null;
return "committees/update";
}
}
void populateEditForm(Model uiModel, Committee programa) {
System.out.println("abc");
// uiModel.addAttribute("programa", programa);
//
// if(!uiModel.asMap().containsKey("Itinerante")){
// uiModel.addAttribute("Itinerante", false);
// }
// if((Boolean)uiModel.asMap().get("Itinerante")){
// uiModel.addAttribute("Itinerante", false);
// }
//
// uiModel.addAttribute("create", true);
// addDateTimeFormatPatterns(uiModel);
//
// //List<Programa> lp = Programa.findAllProgramas();
// List<Programa> lp = Programa.findAllProgramasEfetivos();
// Programa p = new Programa();