Commit 89cda4b2 authored by didonet's avatar didonet

Added verifications when creating transcripts.

parent e180cb75
package br.ufpr.c3sl.sapos.models.customization;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -9,12 +8,12 @@ import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
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.Committee;
import br.ufpr.c3sl.sapos.models.scholar.Registration;
import br.ufpr.c3sl.sapos.models.scholar.SectionPos;
import br.ufpr.c3sl.sapos.models.scholar.StudentGrant;
import br.ufpr.c3sl.sapos.models.scholar.Transcript;
import br.ufpr.c3sl.sapos.models.scholar.TravelRequisition;
......@@ -81,12 +80,27 @@ public class Configuration {
"and sg.registration = r.id and t.student=r.id and t.situation='Reprovado' and r.student = p.id order by p.name"*/
//- Avisar que o aluno com duas reprovações deve ter o status de desligado
public static Object findIrregularRegistration(){
return entityManager().createNativeQuery("select * from (select distinct r.id as identidade from registration r, transcript t1, transcript t2, " +
public static Object findIrregularRegistration(String registrationId){
String query = "select * from (select distinct r.id as identidade from registration r, transcript t1, transcript t2, " +
"person p where t1.id <> t2.id and t1.student=r.id and t2.student=r.id and t1.situation='Reprovado' and t2.situation='Reprovado' and" +
" NOT reg_status = 'Desligada') as temp, registration r where temp.identidade = r.id and r.reg_status = 'Ativa'", Registration.class).getResultList();
" NOT reg_status = 'Desligada') as temp, registration r where temp.identidade = r.id and r.reg_status = 'Ativa'";
if (registrationId != null) {
query = query + "and r.id = "+registrationId;
}
return entityManager().createNativeQuery(query, Registration.class).getResultList();
}
public static Object findActiveDuplicatedCodes(){
return entityManager().createNativeQuery("select c.code, e.name, count(*) from transcript a, " +
"section_pos b, course c, registration d, person e where a.transcript_section = b.id " +
"and b.course = c.id and a.student = d.id and d.student = e.id and " +
"d.reg_status='Ativa' group by c.code, e.name having count(*) > 1 order by 2,1",
SectionPos.class).getResultList();
}
//- show students that are not subscribed into any course and that are not writing the thesis neither ("unregistered")
public static Object findUnregisteredStudents(){
return entityManager().createNativeQuery(
......@@ -114,52 +128,68 @@ public class Configuration {
}
//- mostrar data de proposta expirada
public static Object findExpiredProposalRegistration(){
public static Object findExpiredProposalRegistration(String registrationId){
int expireMaster = Integer.valueOf(Configuration.findConfigValueByName(MONTHS_MASTER_PROPOSAL_EXPIRATION));
int expirePhd = Integer.valueOf(Configuration.findConfigValueByName(MONTHS_PHD_PROPOSAL_EXPIRATION));
String query = " select * from registration a, person b, person c where a.student = b.id and "+
" proposal_date is null and deferral_date is null and reg_kind = '"+RegistrationKind.Mestrado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and c.id = a.advisor and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * "+
" 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expireMaster + " + case when quali_extension_period is null then 0 else quali_extension_period end )";
if (registrationId != null) {
query = query + "and a.id = "+registrationId;
}
query = query +
" UNION "+
" select * from registration a, person b, person c where a.student = b.id and "+
" proposal_date is null and deferral_date is null and reg_kind = '"+RegistrationKind.Doutorado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and c.id = a.advisor and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * "+
" 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expirePhd + " + case when quali_extension_period is null then 0 else quali_extension_period end )";
if (registrationId != null) {
query = query + "and a.id = "+registrationId;
}
return entityManager().createNativeQuery(
" select * from registration a, person b, person c where a.student = b.id and "+
" proposal_date is null and deferral_date is null and reg_kind = '"+RegistrationKind.Mestrado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and c.id = a.advisor and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * "+
" 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expireMaster + " + case when quali_extension_period is null then 0 else quali_extension_period end )"+
" UNION "+
" select * from registration a, person b, person c where a.student = b.id and "+
" proposal_date is null and deferral_date is null and reg_kind = '"+RegistrationKind.Doutorado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and c.id = a.advisor and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * "+
" 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expirePhd + " + case when quali_extension_period is null then 0 else quali_extension_period end )"
,
Registration.class).getResultList();
return entityManager().createNativeQuery(query, Registration.class).getResultList();
}
//- mostrar data de defesa expirada
public static Object findExpiredDefenseRegistration(){
public static Object findExpiredDefenseRegistration(String registrationId){
int expireMaster = Integer.valueOf(Configuration.findConfigValueByName(MONTHS_MASTER)) -
Integer.valueOf(Configuration.findConfigValueByName(MONTHS_DEFENSE_DATE_EXPIRES_MASTER));
int expirePhd = Integer.valueOf(Configuration.findConfigValueByName(MONTHS_PHD)) -
Integer.valueOf(Configuration.findConfigValueByName(MONTHS_DEFENSE_DATE_EXPIRES_PHD));
String query = " select * from registration where " +
" defense_date is null and reg_kind = '"+RegistrationKind.Mestrado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expireMaster + " + case when thesis_extension_period is null then 0 else thesis_extension_period end )";
if (registrationId != null) {
query = query + "and id = "+registrationId;
}
query = query + " UNION "+
" select * from registration where " +
" defense_date is null and reg_kind = '"+RegistrationKind.Doutorado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > " +
" ("+ expirePhd + " + case when thesis_extension_period is null then 0 else thesis_extension_period end )";
if (registrationId != null) {
query = query + "and id = "+registrationId;
}
return entityManager().createNativeQuery(
// " (extract ( month from age (current_date, start_date)) + extract (year from age (current_date, start_date)) * 12) > "+
//(y2 - y1) * 12 + (m2 - m1) + 1;
" select * from registration where " +
" defense_date is null and reg_kind = '"+RegistrationKind.Mestrado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > "+
" ("+ expireMaster + " + case when thesis_extension_period is null then 0 else thesis_extension_period end )"+
" UNION "+
" select * from registration where " +
" defense_date is null and reg_kind = '"+RegistrationKind.Doutorado+"' and reg_status = '"+RegistrationStatus.Ativa+"' and "+
" ( (date_part('year',current_date) - date_part('year',start_date)) * 12 + (date_part('month',current_date) - date_part('month',start_date)) +1) > " +
" ("+ expirePhd + " + case when thesis_extension_period is null then 0 else thesis_extension_period end )"
,
//(y2 - y1) * 12 + (m2 - m1) + 1;
query,
Registration.class).getResultList();
}
......
......@@ -600,5 +600,16 @@ public class Transcript {
}
}
public static boolean hasDuplicatedTranscript(long studentId, String courseCode) {
return (entityManager().createNativeQuery("select * from transcript a, section_pos b, course c " +
"where a.transcript_section = b.id and b.course = c.id and " +
"student = "+studentId+" and c.code like '"+courseCode.toUpperCase().trim()+"%'", Transcript.class).getResultList().size() > 0);
}
}
\ No newline at end of file
......@@ -32,13 +32,14 @@ public class ConfigurationController {
model.addAttribute("activeMaster", cMaster);
model.addAttribute("activePhd", cPhd);
model.addAttribute("irregularGrants", Configuration.findActiveStudentIrregularGrants());
model.addAttribute("irregularRegistrations", Configuration.findIrregularRegistration());
model.addAttribute("expiredDefense", Configuration.findExpiredDefenseRegistration());
model.addAttribute("irregularRegistrations", Configuration.findIrregularRegistration(null));
model.addAttribute("expiredDefense", Configuration.findExpiredDefenseRegistration(null));
model.addAttribute("unregisteredStudents", Configuration.findUnregisteredStudents());
model.addAttribute("expiredProposal", Configuration.findExpiredProposalRegistration());
model.addAttribute("expiredProposal", Configuration.findExpiredProposalRegistration(null));
model.addAttribute("registeredWithDefense", Configuration.findRegisteredStudentsWithDefense());
model.addAttribute("endGrant", Configuration.findNearEndGrants());
model.addAttribute("gradeEmpty", Configuration.findLastPeriodBlankConcepts());
// model.addAttribute("duplicatedCodes", Configuration.findActiveDuplicatedCodes());
model.addAttribute("travelrequisition", Configuration.findAllOpenTravelRequisitions());
return "configurations/alert";
}
......
......@@ -11,11 +11,13 @@ import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ModelAttribute;
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.customization.Configuration;
import br.ufpr.c3sl.sapos.models.people.Professor;
import br.ufpr.c3sl.sapos.models.scholar.Registration;
import br.ufpr.c3sl.sapos.models.scholar.SectionPos;
......@@ -111,13 +113,64 @@ public class TranscriptController {
//return "registrations/liststudentssimple";
}
private String duplicateTranscriptMsg (long registrationId, String address) {
//TODO: internationalize
return "Codigo da disciplina duplicada. Verificar em "+
"http://"+address+":8080/sapos/transcripts/transcriptsstatementlist?registration="+registrationId;
}
private boolean verifyValidTranscript (Transcript transcript, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest){
if (Transcript.hasDuplicatedTranscript(transcript.getStudent().getId(), transcript.getTranscriptSection().getCourse().getCode())) {
bindingResult.addError(new ObjectError("Transcript", duplicateTranscriptMsg(transcript.getStudent().getId(), httpServletRequest.getServerName())));
return false;
}
if ( ((List)Configuration.findExpiredProposalRegistration(transcript.getStudent().getId().toString())).size() > 0) {
bindingResult.addError(new ObjectError("Transcript", "Proposta expirada ou não entregue"));
return false;
}
if ( ((List)Configuration.findExpiredDefenseRegistration(transcript.getStudent().getId().toString())).size() > 0) {
bindingResult.addError(new ObjectError("Transcript", "Defesa expirada"));
return false;
}
if ( ((List)Configuration.findIrregularRegistration(transcript.getStudent().getId().toString())).size() > 0) {
bindingResult.addError(new ObjectError("Transcript", "Aluno com duas reprovacoes"));
return false;
}
return true;
}
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Transcript transcript, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
//bindingResult.addError(new Obj)
if (bindingResult.hasErrors()) {
uiModel.addAttribute("transcript", transcript);
addDateTimeFormatPatterns(uiModel);
return "transcripts/create";
} else {
if (! verifyValidTranscript(transcript, bindingResult, uiModel, httpServletRequest)) {
uiModel.addAttribute("transcript", transcript);
addDateTimeFormatPatterns(uiModel);
return "transcripts/create";
}
}
uiModel.asMap().clear();
transcript.persist();
return "redirect:/transcripts/" + encodeUrlPathSegment(transcript.getId().toString(), httpServletRequest);
}
@RequestMapping(method = RequestMethod.PUT)
public String update(@Valid Transcript transcript, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("transcript", transcript);
addDateTimeFormatPatterns(uiModel);
return "transcripts/update";
}
}
uiModel.asMap().clear();
transcript.merge();
......
......@@ -3,23 +3,14 @@
package br.ufpr.c3sl.sapos.web;
import br.ufpr.c3sl.sapos.models.scholar.Registration;
import br.ufpr.c3sl.sapos.models.scholar.SectionPos;
import br.ufpr.c3sl.sapos.models.scholar.Transcript;
import br.ufpr.c3sl.sapos.models.scholar.enums.ConceptTranscript;
import br.ufpr.c3sl.sapos.models.scholar.enums.SituationTranscript;
import java.io.UnsupportedEncodingException;
import java.lang.Integer;
import java.lang.Long;
import java.lang.String;
import java.util.Arrays;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.joda.time.format.DateTimeFormat;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -28,21 +19,13 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.WebUtils;
import br.ufpr.c3sl.sapos.models.scholar.Transcript;
import br.ufpr.c3sl.sapos.models.scholar.enums.ConceptTranscript;
import br.ufpr.c3sl.sapos.models.scholar.enums.SituationTranscript;
privileged aspect TranscriptController_Roo_Controller {
@RequestMapping(method = RequestMethod.POST)
public String TranscriptController.create(@Valid Transcript transcript, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("transcript", transcript);
addDateTimeFormatPatterns(uiModel);
return "transcripts/create";
}
uiModel.asMap().clear();
transcript.persist();
return "redirect:/transcripts/" + encodeUrlPathSegment(transcript.getId().toString(), httpServletRequest);
}
@RequestMapping(params = "form", method = RequestMethod.GET)
public String TranscriptController.createForm(Model uiModel) {
......
......@@ -145,8 +145,7 @@
<table:column id="c_br_ufpr_c3sl_sapos_models_scholar_Registration_proposalDate" property="proposalDate" z="OzadopRNBpgDF6fS6fKmBx3EPhA="/>
<table:column id="c_br_ufpr_c3sl_sapos_models_scholar_Registration_regStatus" property="regStatus" z="ZylPJo9HTwXXaEuXJAnOaZPfxQw="/>
</table:table>
</page:list>
</page:list>
<br/><br/>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment