Commit 14147c61 authored by Fabiano Sluzarski's avatar Fabiano Sluzarski
Browse files

New class Staff and login information from database

parent ea33298f
......@@ -24,6 +24,7 @@ import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.location.FederalState;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
import br.ufpr.c3sl.sapos.models.scholar.ResearchField;
@RooJavaBean
......@@ -57,6 +58,12 @@ public class Person {
private String fatherName;
private String userName;
private String password;
@Enumerated(EnumType.STRING)
private UserKind userKind;
@Temporal(TemporalType.DATE)
@DateTimeFormat(style = "S-")
......
......@@ -3,19 +3,43 @@
package br.ufpr.c3sl.sapos.models.people;
import java.util.Date;
import java.util.Set;
import br.ufpr.c3sl.sapos.models.entities.Bank;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.location.FederalState;
import br.ufpr.c3sl.sapos.models.people.Title;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
import br.ufpr.c3sl.sapos.models.scholar.ResearchField;
import java.lang.String;
import java.util.Date;
import java.util.Set;
privileged aspect Person_Roo_JavaBean {
public String Person.getUserName() {
return this.userName;
}
public void Person.setUserName(String userName) {
this.userName = userName;
}
public String Person.getPassword() {
return this.password;
}
public void Person.setPassword(String password) {
this.password = password;
}
public UserKind Person.getUserKind() {
return this.userKind;
}
public void Person.setUserKind(UserKind userKind) {
this.userKind = userKind;
}
public String Person.getName() {
return this.name;
}
......
......@@ -26,6 +26,9 @@ privileged aspect Person_Roo_ToString {
sb.append("MaritalStatus: ").append(getMaritalStatus()).append(", ");
sb.append("MotherName: ").append(getMotherName()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("UserName: ").append(getUserName()).append(", ");
sb.append("Password: ").append(getPassword()).append(", ");
sb.append("UserKind: ").append(getUserKind()).append(", ");
sb.append("Nationality: ").append(getNationality()).append(", ");
sb.append("Num: ").append(getNum()).append(", ");
sb.append("Observation: ").append(getObservation()).append(", ");
......
package br.ufpr.c3sl.sapos.models.people;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
@RooJavaBean
@RooToString
@RooEntity
public class Staff extends Person {
}
// 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.people;
import org.springframework.beans.factory.annotation.Configurable;
privileged aspect Staff_Roo_Configurable {
declare @type: Staff: @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.people;
import br.ufpr.c3sl.sapos.models.people.Staff;
import java.lang.Long;
import java.util.List;
import javax.persistence.Entity;
privileged aspect Staff_Roo_Entity {
declare @type: Staff: @Entity;
public static long Staff.countStaffs() {
return entityManager().createQuery("SELECT COUNT(o) FROM Staff o", Long.class).getSingleResult();
}
public static List<Staff> Staff.findAllStaffs() {
return entityManager().createQuery("SELECT o FROM Staff o", Staff.class).getResultList();
}
public static Staff Staff.findStaff(Long id) {
if (id == null) return null;
return entityManager().find(Staff.class, id);
}
public static List<Staff> Staff.findStaffEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM Staff o", Staff.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.people;
import java.lang.String;
privileged aspect Staff_Roo_ToString {
public String Staff.toString() {
StringBuilder sb = new StringBuilder();
sb.append("Bank: ").append(getBank()).append(", ");
sb.append("BankAccount: ").append(getBankAccount()).append(", ");
sb.append("CellPhone: ").append(getCellPhone()).append(", ");
sb.append("City: ").append(getCity()).append(", ");
sb.append("CityOfBirth: ").append(getCityOfBirth()).append(", ");
sb.append("Country: ").append(getCountry()).append(", ");
sb.append("Cpf: ").append(getCpf()).append(", ");
sb.append("DateOfBirth: ").append(getDateOfBirth()).append(", ");
sb.append("Email: ").append(getEmail()).append(", ");
sb.append("EmitterRg: ").append(getEmitterRg()).append(", ");
sb.append("FatherName: ").append(getFatherName()).append(", ");
sb.append("Fax: ").append(getFax()).append(", ");
sb.append("FederalState: ").append(getFederalState()).append(", ");
sb.append("Gender: ").append(getGender()).append(", ");
sb.append("Id: ").append(getId()).append(", ");
sb.append("MaritalStatus: ").append(getMaritalStatus()).append(", ");
sb.append("MotherName: ").append(getMotherName()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("Nationality: ").append(getNationality()).append(", ");
sb.append("Num: ").append(getNum()).append(", ");
sb.append("Observation: ").append(getObservation()).append(", ");
sb.append("Phone: ").append(getPhone()).append(", ");
sb.append("ResearchFields: ").append(getResearchFields() == null ? "null" : getResearchFields().size()).append(", ");
sb.append("Rg: ").append(getRg()).append(", ");
sb.append("ShortName: ").append(getShortName()).append(", ");
sb.append("Square: ").append(getSquare()).append(", ");
sb.append("StateOfBirth: ").append(getStateOfBirth()).append(", ");
sb.append("Street: ").append(getStreet()).append(", ");
sb.append("Titles: ").append(getTitles() == null ? "null" : getTitles().size()).append(", ");
sb.append("Version: ").append(getVersion()).append(", ");
sb.append("ZipCode: ").append(getZipCode());
return sb.toString();
}
}
package br.ufpr.c3sl.sapos.models.people.enums;
public enum UserKind {
Professor, Aluno, Funcionario, Administrador
}
......@@ -157,9 +157,12 @@ public class Registration {
public static Object findAllCandidatesToGrant() {
return entityManager().createNativeQuery(
"SELECT * FROM registration r, person p where"+
" reg_status = 'Ativa' and grant_candidate = 'true' and r.student = p.id"+
" order by p.name" , Registration.class).getResultList();
"select * from registration r, person p where grant_candidate = 't' and reg_status='Ativa' and"+
" not exists ( select * from student_grant sg where sg.registration = r.id and end_date is null )"+
" and r.student = p.id order by p.name", Registration.class).getResultList();
// "SELECT * FROM registration r, person p where"+
// " reg_status = 'Ativa' and grant_candidate = 'true' and r.student = p.id"+
// " order by p.name" falta verificar se ele tem uma bolsa ativa, query acima tenta solucionar isso
}
public static Registration getAtiveRegistration(Student s) {
......
......@@ -11,6 +11,7 @@ import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.location.FederalState;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.people.Professor;
import br.ufpr.c3sl.sapos.models.people.Staff;
import br.ufpr.c3sl.sapos.models.people.Student;
import br.ufpr.c3sl.sapos.models.people.Title;
import br.ufpr.c3sl.sapos.models.scholar.ClassSchedule;
......@@ -60,7 +61,16 @@ public class ApplicationConversionServiceFactoryBean extends FormattingConversio
}
};
}
org.springframework.core.convert.converter.Converter<Staff, String> getStaffConverter() {
return new org.springframework.core.convert.converter.Converter<Staff, String>() {
public String convert(Staff staff) {
return new StringBuilder().append(staff.getName()).toString();
}
};
}
org.springframework.core.convert.converter.Converter<Professor, String> getProfessorConverter() {
return new org.springframework.core.convert.converter.Converter<Professor, String>() {
public String convert(Professor professor) {
......
......@@ -25,6 +25,7 @@ privileged aspect ApplicationConversionServiceFactoryBean_Roo_ConversionService
registry.addConverter(getSectionPosConverter());
registry.addConverter(getStudentGrantConverter());
registry.addConverter(getTranscriptConverter());
registry.addConverter(getStaffConverter());
}
public void ApplicationConversionServiceFactoryBean.afterPropertiesSet() {
......
package br.ufpr.c3sl.sapos.web;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.people.Person;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
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.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.Staff;
import br.ufpr.c3sl.sapos.models.people.Student;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
@RooWebScaffold(path = "people", formBackingObject = Person.class)
@RequestMapping("/people")
......@@ -15,5 +24,38 @@ public class PersonController {
public java.util.Collection<City> populateCities() {
return City.findAllCitys();
}
@RequestMapping(value = "changepassword", method = RequestMethod.GET)
public String chancePassword() {
return "people/changepassword";
}
@RequestMapping(value = "accepted", method = RequestMethod.GET)
public String accepted() {
return "people/accepted";
}
@RequestMapping(value = "error", method = RequestMethod.GET)
public String error() {
return "people/error";
}
@RequestMapping(value = "updatepassword", method = RequestMethod.GET)
public String updatePassword(@RequestParam(value = "oldpassword", required = true) String opass,
@RequestParam(value = "newpassword", required = true) String npass) {
Person p = (Person) Person.entityManager().createNativeQuery("select * from person where user_name='"
+SecurityContextHolder.getContext().getAuthentication().getName()+"'",
Person.class).getSingleResult();
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
if (!(p.getPassword().equals(encoder.encodePassword(opass, ""))))
return "redirect:error";
p.setPassword(encoder.encodePassword(npass, ""));
p.merge();
return "redirect:accepted";
}
}
......@@ -3,11 +3,16 @@ package br.ufpr.c3sl.sapos.web;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
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;
......@@ -15,8 +20,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.people.Professor;
import br.ufpr.c3sl.sapos.models.people.Staff;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
import br.ufpr.c3sl.sapos.models.scholar.Committee;
import br.ufpr.c3sl.sapos.models.scholar.Registration;
import br.ufpr.c3sl.sapos.models.scholar.SectionPos;
......@@ -26,6 +33,30 @@ import br.ufpr.c3sl.sapos.models.scholar.enums.RegistrationKind;
@RequestMapping("/professors")
@Controller
public class ProfessorController {
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Professor professor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
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/create";
}
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
professor.setPassword(encoder.encodePassword(professor.getPassword(), ""));
uiModel.asMap().clear();
professor.persist();
return "redirect:/professors/" + encodeUrlPathSegment(professor.getId().toString(), httpServletRequest);
}
@ModelAttribute("userkinds")
public java.util.Collection<UserKind> populateUserKinds() {
return Arrays.asList(UserKind.Professor, UserKind.Administrador);
}
@ModelAttribute("genders")
public java.util.Collection<GenderKind> populateGenderKinds() {
return Arrays.asList(GenderKind.class.getEnumConstants());
......
......@@ -37,18 +37,6 @@ import org.springframework.web.util.WebUtils;
privileged aspect ProfessorController_Roo_Controller {
@RequestMapping(method = RequestMethod.POST)
public String ProfessorController.create(@Valid Professor professor, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("professor", professor);
addDateTimeFormatPatterns(uiModel);
return "professors/create";
}
uiModel.asMap().clear();
professor.persist();
return "redirect:/professors/" + encodeUrlPathSegment(professor.getId().toString(), httpServletRequest);
}
@RequestMapping(params = "form", method = RequestMethod.GET)
public String ProfessorController.createForm(Model uiModel) {
uiModel.addAttribute("professor", new Professor());
......
package br.ufpr.c3sl.sapos.web;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
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 br.ufpr.c3sl.sapos.models.people.Staff;
import br.ufpr.c3sl.sapos.models.people.enums.UserKind;
@RooWebScaffold(path = "staffs", formBackingObject = Staff.class)
@RequestMapping("/staffs")
@Controller
public class StaffController {
@ModelAttribute("userkinds")
public java.util.Collection<UserKind> populateUserKinds() {
return Arrays.asList(UserKind.Funcionario, UserKind.Administrador);
}
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Staff staff, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (Staff.entityManager().createNativeQuery("select id, user_name from person where user_name='"+staff.getUserName()+"'", Staff.class).getResultList().size() > 0){
bindingResult.addError(new ObjectError("staff.user_name","Staff "+staff.getUserName()+" already exists."));
}
if (bindingResult.hasErrors()) {
uiModel.addAttribute("staff", staff);
addDateTimeFormatPatterns(uiModel);
return "staffs/create";
}
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
staff.setPassword(encoder.encodePassword(staff.getPassword(), ""));
uiModel.asMap().clear();
staff.persist();
return "redirect:/staffs/" + encodeUrlPathSegment(staff.getId().toString(), httpServletRequest);
}
}
// 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.web;
import br.ufpr.c3sl.sapos.models.entities.Bank;
import br.ufpr.c3sl.sapos.models.location.City;
import br.ufpr.c3sl.sapos.models.location.FederalState;
import br.ufpr.c3sl.sapos.models.people.Staff;
import br.ufpr.c3sl.sapos.models.people.Title;
import br.ufpr.c3sl.sapos.models.people.enums.GenderKind;
import br.ufpr.c3sl.sapos.models.people.enums.MaritalStatus;
import br.ufpr.c3sl.sapos.models.scholar.ResearchField;
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;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.util.UriUtils;
import org.springframework.web.util.WebUtils;
privileged aspect StaffController_Roo_Controller {
@RequestMapping(params = "form", method = RequestMethod.GET)
public String StaffController.createForm(Model uiModel) {
uiModel.addAttribute("staff", new Staff());
addDateTimeFormatPatterns(uiModel);
return "staffs/create";
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String StaffController.show(@PathVariable("id") Long id, Model uiModel) {
addDateTimeFormatPatterns(uiModel);
uiModel.addAttribute("staff", Staff.findStaff(id));
uiModel.addAttribute("itemId", id);
return "staffs/show";
}
@RequestMapping(method = RequestMethod.GET)
public String StaffController.list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
if (page != null || size != null) {
int sizeNo = size == null ? 10 : size.intValue();
uiModel.addAttribute("staffs", Staff.findStaffEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));
float nrOfPages = (float) Staff.countStaffs() / sizeNo;
uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
} else {
uiModel.addAttribute("staffs", Staff.findAllStaffs());
}
addDateTimeFormatPatterns(uiModel);
return "staffs/list";
}
@RequestMapping(method = RequestMethod.PUT)
public String StaffController.update(@Valid Staff staff, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("staff", staff);
addDateTimeFormatPatterns(uiModel);
return "staffs/update";
}
uiModel.asMap().clear();
staff.merge();
return "redirect:/staffs/" + encodeUrlPathSegment(staff.getId().toString(), httpServletRequest);
}
@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
public String StaffController.updateForm(@PathVariable("id") Long id, Model uiModel) {
uiModel.addAttribute("staff", Staff.findStaff(id));
addDateTimeFormatPatterns(uiModel);
return "staffs/update";
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String StaffController.delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
Staff.findStaff(id).remove();
uiModel.asMap().clear();
uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
return "redirect:/staffs";
}
@ModelAttribute("banks")
public Collection<Bank> StaffController.populateBanks() {
return Bank.findAllBanks();
}
@ModelAttribute("citys")
public Collection<City> StaffController.populateCitys() {
return City.findAllCitys();
}
@ModelAttribute("federalstates")
public Collection<FederalState> StaffController.populateFederalStates() {
return FederalState.findAllFederalStates();
}
@ModelAttribute("staffs")
public Collection<Staff> StaffController.populateStaffs() {
return Staff.findAllStaffs();