Commit 87b0d82f authored by Fabiano Sluzarski's avatar Fabiano Sluzarski
Browse files

CPF as key on student, staff and professor. On professor has a

confirmation screen if the cpf is already on the database.
parent d10ae1b2
......@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.people.Professor;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
......@@ -40,6 +41,15 @@ public class ProfessorController {
bindingResult.addError(new ObjectError("professor.user_name","Professor "+professor.getUserName()+" already exists."));
}
}
if (professor.getCpf() != null && professor.getCpf().length() > 0 ) {
if (Person.entityManager().createNativeQuery("select * from person where cpf='"+professor.getCpf()+"'", Person.class).getResultList().size() > 0) {
uiModel.addAttribute("professor", professor);
addDateTimeFormatPatterns(uiModel);
return "professors/confirmation";
}
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("professor", professor);
addDateTimeFormatPatterns(uiModel);
......@@ -58,6 +68,32 @@ public class ProfessorController {
return "redirect:/professors/" + encodeUrlPathSegment(professor.getId().toString(), httpServletRequest);
}
@RequestMapping(value="confirmation", method = RequestMethod.POST)
public String confirmation(@Valid Professor professor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (professor.getUserName() != null && professor.getUserName().length() > 0 ) {
if (Professor.entityManager().createNativeQuery("select id, user_name from person where user_name='"+professor.getUserName()+"'", Professor.class).getResultList().size() > 0){
bindingResult.addError(new ObjectError("professor.user_name","Professor "+professor.getUserName()+" already exists."));
}
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("professor", professor);
addDateTimeFormatPatterns(uiModel);
return "professors/confirmation";
}
if (!professor.getPassword().isEmpty()) {
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
professor.setPassword(encoder.encodePassword(professor.getPassword(), ""));
}
else
professor.setPassword(null);
uiModel.asMap().clear();
professor.persist();
return "redirect:/professors/" + encodeUrlPathSegment(professor.getId().toString(), httpServletRequest);
}
@RequestMapping(method = RequestMethod.PUT)
public String update(@Valid Professor professor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
......
......@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.people.Staff;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
......@@ -44,6 +45,12 @@ public class StaffController {
bindingResult.addError(new ObjectError("staff.user_name","Staff "+staff.getUserName()+" already exists."));
}
}
if (staff.getCpf() != null && staff.getCpf().length() > 0 ) {
if (Person.entityManager().createNativeQuery("select * from person where cpf='"+staff.getCpf()+"'", Person.class).getResultList().size() > 0)
bindingResult.addError(new ObjectError("staff.cpf","Staff cpf "+staff.getCpf()+" already exists."));
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("staff", staff);
addDateTimeFormatPatterns(uiModel);
......
......@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.people.Student;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
......@@ -33,6 +34,12 @@ public class StudentController {
bindingResult.addError(new ObjectError("student.user_name","Student "+student.getUserName()+" already exists."));
}
}
if (student.getCpf() != null && student.getCpf().length() > 0 ) {
if (Person.entityManager().createNativeQuery("select * from person where cpf='"+student.getCpf()+"'", Person.class).getResultList().size() > 0)
bindingResult.addError(new ObjectError("student.cpf","Student cpf "+student.getCpf()+" already exists."));
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("student", student);
addDateTimeFormatPatterns(uiModel);
......
......@@ -70,6 +70,7 @@ field_simple_validation=Enter {0} {1}
field_invalid_email=Please enter a valid email
field_invalid_number=Number with \\'-\\' or \\'.\\' allowed
field_invalid_integer=Integer numbers only
field_invalid_cpf=11 integer numbers only
field_invalid=Please enter valid {0}
field_required=required
......
......@@ -69,6 +69,7 @@ field_simple_validation=Insira {0} {1}
field_invalid_email=Por favor entre um email vlido
field_invalid_number=Numeros com \\'-\\' or \\'.\\' permitidos
field_invalid_integer=Somente nmeros inteiros
field_invalid_cpf=Somente 11 nmeros inteiros
field_invalid=Por favor insira um {0} valido
field_required=requisitado
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Professor" modelAttribute="professor" path="/professors/confirmation" render="${empty dependencies}" z="user-managed">
<b>CPF informado já consta no banco de dados. Deseja mesmo cadastrar outro professor com o mesmo cpf?
<br/><br/>
Sim - clique em 'Save' no final da página
<br/>
Não - volte para página principal do Sapos</b>
<hr/>
<b>Informacoes pessoais</b>
<p/>
<field:input field="name" id="c_br_ufpr_c3sl_sapos_models_people_Professor_name" required="true" z="user-managed"/>
<field:input field="shortName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_shortName" z="user-managed"/>
<field:select field="gender" id="c_br_ufpr_c3sl_sapos_models_people_Professor_gender" items="${genders}" path="genders" z="user-managed"/>
<field:select field="maritalStatus" id="c_br_ufpr_c3sl_sapos_models_people_Professor_maritalStatus" items="${maritalstatuses}" path="maritalstatuses" z="user-managed"/>
<field:datetime dateTimePattern="${professor_dateofbirth_date_format}" field="dateOfBirth" id="c_br_ufpr_c3sl_sapos_models_people_Professor_dateOfBirth" past="true" z="user-managed"/>
<field:input field="fatherName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_fatherName" z="user-managed"/>
<field:input field="motherName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_motherName" z="user-managed"/>
<field:input field="cityOfBirth" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cityOfBirth" z="user-managed"/>
<field:input field="stateOfBirth" id="c_br_ufpr_c3sl_sapos_models_people_Professor_stateOfBirth" z="user-managed"/>
<field:input field="nationality" id="c_br_ufpr_c3sl_sapos_models_people_Professor_nationality" z="user-managed"/>
<hr/>
<b>Contatos</b>
<p/>
<field:input field="cellPhone" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cellPhone" z="user-managed"/>
<field:input field="email" id="c_br_ufpr_c3sl_sapos_models_people_Professor_email" validationMessageCode="field_invalid_email" z="user-managed"/>
<field:input field="phone" id="c_br_ufpr_c3sl_sapos_models_people_Professor_phone" z="user-managed"/>
<field:input field="fax" id="c_br_ufpr_c3sl_sapos_models_people_Professor_fax" z="user-managed"/>
<field:input field="num" id="c_br_ufpr_c3sl_sapos_models_people_Professor_num" z="user-managed"/>
<field:input field="square" id="c_br_ufpr_c3sl_sapos_models_people_Professor_square" z="user-managed"/>
<field:input field="street" id="c_br_ufpr_c3sl_sapos_models_people_Professor_street" z="user-managed"/>
<field:input field="zipCode" id="c_br_ufpr_c3sl_sapos_models_people_Professor_zipCode" z="user-managed"/>
<field:select field="city" id="c_br_ufpr_c3sl_sapos_models_people_Professor_city" itemValue="id" items="${cities}" path="/cities" z="user-managed"/>
<field:input field="country" id="c_br_ufpr_c3sl_sapos_models_people_Professor_country" z="user-managed"/>
<field:select field="federalState" id="c_br_ufpr_c3sl_sapos_models_people_Professor_federalState" itemValue="id" items="${federalstates}" path="/federalstates" z="user-managed"/>
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bank" itemValue="id" items="${banks}" path="/banks" z="user-managed"/>
<field:input field="bankAccount" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bankAccount" z="user-managed"/>
<field:input field="siape" id="c_br_ufpr_c3sl_sapos_models_people_Professor_siape" z="46vmhUS70uUmnCvD2y1O/OXaezk="/>
<field:input field="registrationNumber" id="c_br_ufpr_c3sl_sapos_models_people_Professor_registrationNumber" z="8b6xN4Y3NlFErYwEBMdqSL84eIs="/>
<field:select field="kind" id="c_br_ufpr_c3sl_sapos_models_people_Professor_kind" items="${professorkinds}" path="professorkinds" z="akwmwBDthoVce47msqY5e2/OyEU="/>
<field:select field="institution" id="c_br_ufpr_c3sl_sapos_models_people_Professor_institution" itemValue="id" items="${organizations}" path="/organizations" z="JzUg5ng5MsORRO+w2JE9H265XGY="/>
<field:input field="observation" id="c_br_ufpr_c3sl_sapos_models_people_Professor_observation" z="user-managed"/>
<hr/>
<b>Pesquisa</b>
<p/>
<field:select field="researchFields" id="c_br_ufpr_c3sl_sapos_models_people_Professor_researchFields" itemValue="id" items="${researchfields}" multiple="true" path="/researchfields" z="user-managed"/>
<hr/>
<b>Acesso ao sistema</b>
<p/>
<field:input field="userName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_userName" z="user-managed"/>
<field:input field="password" type="password" id="c_br_ufpr_c3sl_sapos_models_people_Professor_password" z="user-managed"/>
<field:select field="userKind" id="c_br_ufpr_c3sl_sapos_models_people_Professor_userKind" items="${userkinds}" path="userkinds" z="user-managed"/>
</form:create>
<form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_sapos_models_people_Professor" render="${not empty dependencies}" z="pAesv98fzElnjWW+IgcoBacraGc="/>
</div>
......@@ -6,7 +6,7 @@
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Professor" modelAttribute="professor" path="/professors" render="${empty dependencies}" z="user-managed">
<b>Informacoes pessoais</b>
<p/>
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Professor_name" comboboxform="true" items="${professorscombobox}" path="professorscombobox" z="user-managed" disableFormBinding="true" required="true" />
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Professor_name" comboboxform="true" items="${professorscombobox}" path="professorscombobox" z="user-managed" required="true" />
<!-- <field:input field="name" id="c_br_ufpr_c3sl_sapos_models_people_Professor_name" required="true" z="user-managed"/> -->
<field:input field="shortName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_shortName" z="user-managed"/>
......@@ -38,7 +38,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bank" itemValue="id" items="${banks}" path="/banks" z="user-managed"/>
......@@ -63,6 +63,7 @@
<field:input field="userName" id="c_br_ufpr_c3sl_sapos_models_people_Professor_userName" z="user-managed"/>
<field:input field="password" type="password" id="c_br_ufpr_c3sl_sapos_models_people_Professor_password" z="user-managed"/>
<field:select field="userKind" id="c_br_ufpr_c3sl_sapos_models_people_Professor_userKind" items="${userkinds}" path="userkinds" z="user-managed"/>
</form:create>
<form:dependency dependencies="${dependencies}" id="d_br_ufpr_c3sl_sapos_models_people_Professor" render="${not empty dependencies}" z="pAesv98fzElnjWW+IgcoBacraGc="/>
</div>
......@@ -26,4 +26,8 @@
<put-attribute name="body" value="/WEB-INF/views/professors/statementcourses.jspx"/>
</definition>
<definition extends="default" name="professors/confirmation">
<put-attribute name="body" value="/WEB-INF/views/professors/confirmation.jspx"/>
</definition>
</tiles-definitions>
......@@ -6,7 +6,7 @@
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Staff" modelAttribute="staff" path="/staffs" render="${empty dependencies}" z="HxkYlyPVfFyiZavs5v/a75glVwQ=">
<b>Informacoes pessoais</b>
<p/>
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Staff_name" comboboxform="true" items="${staffscombobox}" path="staffscombobox" z="user-managed" disableFormBinding="true" required="true" />
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Staff_name" comboboxform="true" items="${staffscombobox}" path="staffscombobox" z="user-managed" required="true" />
<!-- <field:input field="name" id="c_br_ufpr_c3sl_sapos_models_people_Staff_name" required="true" z="xkG7d3oVk5+5SbEG5yaui2kw1TY="/> -->
<field:input field="shortName" id="c_br_ufpr_c3sl_sapos_models_people_Staff_shortName" z="0/hFxnzFTRW++pePFVY7Ibezjv0="/>
......@@ -37,7 +37,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_rg" z="f0NLxFuMPEVNGVHY15+99p7ctkk="/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_emitterRg" z="CjyoaKC6Jp+qMHN+oJKOyxC/4+Q="/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Staff_bank" itemValue="id" items="${banks}" path="/banks" z="sLkdpqWgvA1pCP3WZweDNB+wkc8="/>
......
......@@ -6,7 +6,7 @@
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Student" modelAttribute="student" path="/students" render="${empty dependencies}" z="pT9DFc0OcoQUfkKXMmvXOutDxdE=">
<b>Informacoes pessoais</b>
<p/>
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Student_name" comboboxform="true" items="${studentscombobox}" path="studentscombobox" z="user-managed" disableFormBinding="true" required="true" />
<field:select field="name" id="c_br_ufpr_c3sl_sapos_models_people_Student_name" comboboxform="true" items="${studentscombobox}" path="studentscombobox" z="user-managed" required="true" />
<!-- <field:input field="name" id="c_br_ufpr_c3sl_sapos_models_people_Student_name" required="true" z="OMlwu3st4np30GQq+cVRQCe1lug=" /> -->
......@@ -39,7 +39,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Student_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Student_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Student_bank" itemValue="id" items="${banks}" path="/banks" z="xPtd01IP0ir3GLKvO0tURJ9m2tc="/>
......
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