Commit d6e261d1 authored by Fabiano Sluzarski's avatar Fabiano Sluzarski

Email support added, TravelRequisition class added (need to be

reviewed), PDF for the requisition (need to be reviewed) and checks to
avoid duplicates in course and organization.
parent e26c04c2
......@@ -179,6 +179,26 @@
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
......
......@@ -97,7 +97,7 @@ privileged aspect Person_Roo_Entity {
}
public static List<Person> Person.findAllPeople() {
return entityManager().createQuery("SELECT o FROM Person o", Person.class).getResultList();
return entityManager().createQuery("SELECT o FROM Person o ORDER BY name", Person.class).getResultList();
}
public static Person Person.findPerson(Long id) {
......@@ -106,7 +106,7 @@ privileged aspect Person_Roo_Entity {
}
public static List<Person> Person.findPersonEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM Person o", Person.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
return entityManager().createQuery("SELECT o FROM Person o ORDER BY name", Person.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 org.springframework.beans.factory.annotation.Configurable;
privileged aspect TravelRequisition_Roo_Configurable {
declare @type: TravelRequisition: @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.TravelRequisition;
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 TravelRequisition_Roo_Entity {
declare @type: TravelRequisition: @Entity;
@PersistenceContext
transient EntityManager TravelRequisition.entityManager;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long TravelRequisition.id;
@Version
@Column(name = "version")
private Integer TravelRequisition.version;
public Long TravelRequisition.getId() {
return this.id;
}
public void TravelRequisition.setId(Long id) {
this.id = id;
}
public Integer TravelRequisition.getVersion() {
return this.version;
}
public void TravelRequisition.setVersion(Integer version) {
this.version = version;
}
@Transactional
public void TravelRequisition.persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
@Transactional
public void TravelRequisition.remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
TravelRequisition attached = TravelRequisition.findTravelRequisition(this.id);
this.entityManager.remove(attached);
}
}
@Transactional
public void TravelRequisition.flush() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.flush();
}
@Transactional
public void TravelRequisition.clear() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.clear();
}
@Transactional
public TravelRequisition TravelRequisition.merge() {
if (this.entityManager == null) this.entityManager = entityManager();
TravelRequisition merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
public static final EntityManager TravelRequisition.entityManager() {
EntityManager em = new TravelRequisition().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 long TravelRequisition.countTravelRequisitions() {
return entityManager().createQuery("SELECT COUNT(o) FROM TravelRequisition o", Long.class).getSingleResult();
}
public static List<TravelRequisition> TravelRequisition.findAllTravelRequisitions() {
return entityManager().createQuery("SELECT o FROM TravelRequisition o", TravelRequisition.class).getResultList();
}
public static TravelRequisition TravelRequisition.findTravelRequisition(Long id) {
if (id == null) return null;
return entityManager().find(TravelRequisition.class, id);
}
public static List<TravelRequisition> TravelRequisition.findTravelRequisitionEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM TravelRequisition o", TravelRequisition.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.util.Date;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequestStatus;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequesterKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TicketKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TripKind;
privileged aspect TravelRequisition_Roo_JavaBean {
// TODO
public Person TravelRequisition.getPerson() {
return this.person;
}
public void TravelRequisition.setPerson(Person person) {
this.person = person;
}
public RequesterKind TravelRequisition.getRequesterKind() {
return this.requesterKind;
}
public void TravelRequisition.setRequesterKind(RequesterKind requesterKind) {
this.requesterKind = requesterKind;
}
public String TravelRequisition.getJustification() {
return this.justification;
}
public void TravelRequisition.setJustification(String justification) {
this.justification = justification;
}
public String TravelRequisition.getConference() {
return this.conference;
}
public void TravelRequisition.setConference(String conference) {
this.conference = conference;
}
public String TravelRequisition.getPlace() {
return this.place;
}
public void TravelRequisition.setPlace(String place) {
this.place = place;
}
public TripKind TravelRequisition.getTripKind() {
return this.tripKind;
}
public void TravelRequisition.setTripKind(TripKind tripKind) {
this.tripKind = tripKind;
}
public Date TravelRequisition.getStartDate() {
return this.startDate;
}
public void TravelRequisition.setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date TravelRequisition.getEndDate() {
return this.endDate;
}
public void TravelRequisition.setEndDate(Date endDate) {
this.endDate = endDate;
}
public Integer TravelRequisition.getDayNumber() {
return this.dayNumber;
}
public void TravelRequisition.setDayNumber(Integer dayNumber) {
this.dayNumber = dayNumber;
}
public Float TravelRequisition.getTotalValue() {
return this.totalValue;
}
public void TravelRequisition.setTotalValue(Float totalValue) {
this.totalValue = totalValue;
}
public TicketKind TravelRequisition.getTicketKind() {
return this.ticketKind;
}
public void TravelRequisition.setTicketKind(TicketKind ticketKind) {
this.ticketKind = ticketKind;
}
public String TravelRequisition.getDestinations() {
return this.destinations;
}
public void TravelRequisition.setDestinations(String destinations) {
this.destinations = destinations;
}
public String TravelRequisition.getTripStartDate() {
return this.tripStartDate;
}
public void TravelRequisition.setTripStartDate(String tripStartDate) {
this.tripStartDate = tripStartDate;
}
public String TravelRequisition.getTripEndDate() {
return this.tripEndDate;
}
public void TravelRequisition.setTripEndDate(String tripEndDate) {
this.tripEndDate = tripEndDate;
}
public Float TravelRequisition.getTicketValue() {
return this.ticketValue;
}
public void TravelRequisition.setTicketValue(Float ticketValue) {
this.ticketValue = ticketValue;
}
public RequestStatus TravelRequisition.getRequestStatus() {
return this.requestStatus;
}
public void TravelRequisition.setRequestStatus(RequestStatus requestStatus) {
this.requestStatus = requestStatus;
}
public String TravelRequisition.getObservations() {
return this.observations;
}
public void TravelRequisition.setObservations(String observations) {
this.observations = observations;
}
}
// 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;
privileged aspect TravelRequisition_Roo_ToString {
public String TravelRequisition.toString() {
StringBuilder sb = new StringBuilder();
// TODO ?????
sb.append("Conference: ").append(getConference()).append(", ");
sb.append("DayNumber: ").append(getDayNumber()).append(", ");
sb.append("Destinations: ").append(getDestinations()).append(", ");
sb.append("EndDate: ").append(getEndDate()).append(", ");
sb.append("Justification: ").append(getJustification()).append(", ");
sb.append("Observations: ").append(getObservations()).append(", ");
sb.append("Person: ").append(getPerson()).append(", ");
sb.append("Place: ").append(getPlace()).append(", ");
sb.append("RequesterKind: ").append(getRequesterKind()).append(", ");
sb.append("RequestStatus: ").append(getRequestStatus()).append(", ");
sb.append("StartDate: ").append(getStartDate()).append(", ");
sb.append("TicketKind: ").append(getTicketKind()).append(", ");
sb.append("TicketValue: ").append(getTicketValue()).append(", ");
sb.append("TotalValue: ").append(getTotalValue()).append(", ");
sb.append("TripEndDate: ").append(getTripEndDate()).append(", ");
sb.append("TripKind: ").append(getTripKind()).append(", ");
sb.append("TripStartDate: ").append(getTripStartDate());
return sb.toString();
}
}
package br.ufpr.c3sl.sapos.models.scholar.enums;
public enum RequestStatus {
Aberta, Negada, Confirmada, Anulada;
}
package br.ufpr.c3sl.sapos.models.scholar.enums;
public enum RequesterKind {
Servidor, ColaboradorEventual, Convidado, AssessoramentoEspecial;
}
package br.ufpr.c3sl.sapos.models.scholar.enums;
public enum TicketKind {
Aerea, Rodoviaria, Convencional, Executivo, Leito;
}
package br.ufpr.c3sl.sapos.models.scholar.enums;
public enum TripKind {
ConducaoPropria, Aerea, Rodoviaria;
}
......@@ -3,13 +3,14 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -98,4 +99,17 @@ public class ConfigurationController {
return "people/accepted";
}
@Autowired
private transient MailSender mailTemplate;
public void sendMessage(String mailFrom, String subject, String mailTo, String message) {
//USAGE: sendMessage("spring.roo.playground@gmail.com", "[sapos] Teste Email", "arke.fabiano@gmail.com", "Sucesso!!!");
org.springframework.mail.SimpleMailMessage simpleMailMessage = new org.springframework.mail.SimpleMailMessage();
simpleMailMessage.setFrom(mailFrom);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setTo(mailTo);
simpleMailMessage.setText(message);
mailTemplate.send(simpleMailMessage);
}
}
package br.ufpr.c3sl.sapos.web;
import java.util.ArrayList;
import java.util.List;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
......@@ -13,25 +14,25 @@ import br.ufpr.c3sl.sapos.models.scholar.Course;
@RequestMapping("/courses")
@Controller
public class CourseController {
/*@ModelAttribute("name")
public java.util.Collection<Course> populateName() {
Course c = new Course();
List <Course> l = Course.findAllCourses();
c.setName("");
l.add(0, c);
private final List <Course> l = Course.findAllCourses();
@ModelAttribute("name")
public java.util.Collection<String> populateName() {
ArrayList<String> s = new ArrayList<String>();
s.add("");
for (Course co : l)
co.setCode("");
return l;
s.add(co.getName());
return s;
}
@ModelAttribute("code")
public java.util.Collection<Course> populateCode() {
Course c = new Course();
List <Course> l = Course.findAllCourses();
c.setCode("");
l.add(0, c);
public java.util.Collection<String> populateCode() {
ArrayList<String> s = new ArrayList<String>();
s.add("");
for (Course co : l)
co.setName("");
return l;
}*/
s.add(co.getCode());
return s;
}
}
package br.ufpr.c3sl.sapos.web;
import java.util.ArrayList;
import java.util.List;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
......@@ -13,14 +14,14 @@ import br.ufpr.c3sl.sapos.models.entities.Organization;
@RequestMapping("/organizations")
@Controller
public class OrganizationController {
/*@ModelAttribute("organizationscombobox")
public java.util.Collection<Organization> populateName() {
Organization o = new Organization();
List <Organization> l = Organization.findAllOrganizations();
o.setName("");
l.add(0, o);
for (Organization r: l)
r.setAcronym("");
return l;
}*/
@ModelAttribute("organizationscombobox")
public java.util.Collection<String> populateName() {
List <Organization> l = Organization.findAllOrganizations();
ArrayList<String> s = new ArrayList<String>();
s.add("");
for (Organization o : l)
s.add(o.getName());
return s;
}
}
......@@ -20,8 +20,6 @@ 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.Student;
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;
......
package br.ufpr.c3sl.sapos.web;
import javax.servlet.http.HttpServletResponse;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.scholar.TravelRequisition;
@RooWebScaffold( path = "travelrequisitions", formBackingObject = TravelRequisition.class)
@RequestMapping("/travelrequisitions")
@Controller
public class TravelRequisitionController {
@RequestMapping(value="travelrequisitionpdf",method = RequestMethod.GET)
public void travelRequisitionPdf(@RequestParam(value = "id", required = true) String id, Model model, HttpServletResponse response) {
TravelRequisition tr = TravelRequisition.findTravelRequisition(new Long(id));
TravelRequisition.requisitionPdf(tr,response);
}
}
// 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 java.io.UnsupportedEncodingException;
import java.util.Arrays;
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;
import br.ufpr.c3sl.sapos.models.people.Person;
import br.ufpr.c3sl.sapos.models.scholar.TravelRequisition;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequestStatus;
import br.ufpr.c3sl.sapos.models.scholar.enums.RequesterKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TicketKind;
import br.ufpr.c3sl.sapos.models.scholar.enums.TripKind;
privileged aspect TravelRequisitionController_Roo_Controller {
@RequestMapping(method = RequestMethod.POST)
public String TravelRequisitionController.create(@Valid TravelRequisition travelRequisition, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("travelRequisition", travelRequisition);
addDateTimeFormatPatterns(uiModel);
return "travelrequisitions/create";
}
uiModel.asMap().clear();
travelRequisition.persist();
return "redirect:/travelrequisitions/" + encodeUrlPathSegment(travelRequisition.getId().toString(), httpServletRequest);