Author: vbriand Date: 2011-04-29 12:18:43 +0200 (Fri, 29 Apr 2011) New Revision: 116 Url: http://chorem.org/repositories/revision/chorem/116 Log: Added the possibility to add / modify the employee details of a person Added: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/EmployeeAction.java trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp Modified: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/PersonAction.java trunk/chorem-web/src/main/resources/struts.xml trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetails.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmploymentContract.jsp Added: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/EmployeeAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/EmployeeAction.java (rev 0) +++ trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/EmployeeAction.java 2011-04-29 10:18:43 UTC (rev 116) @@ -0,0 +1,169 @@ +package org.chorem.bonzoms.action; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.ChoremProxy; +import org.chorem.action.BaseAction; +import org.chorem.entities.Employee; +import org.chorem.entities.EmployeeImpl; +import org.chorem.entities.Person; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.Search; + +import com.opensymphony.xwork2.ActionContext; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Employee management class + * + * @author vbriand + */ +public class EmployeeAction extends BaseAction { + + private static final long serialVersionUID = -5757750975509965421L; + + private static final Log log = LogFactory.getLog(PersonAction.class); + + static public EmployeeAction getAction() { + return (EmployeeAction)ActionContext.getContext().get(CONTEXT_ACTION_KEY); + } + + /** + * Modifies the employee's information (or add them if they don't exist) + * + * @return SUCCESS if the employee has been modified successfully, + * ERROR if the id is invalid + */ + public String modify() { + String result = SUCCESS; + Person person; + Employee employee; + ChoremProxy proxy = getChoremProxy(); + + person = proxy.restore(Person.class, personId); + employee = proxy.restore(Employee.class, employeeId); + if (person != null && employee != null) { + //If the user wants to update the employee's details + employee.setDiploma(diploma); + try { + employee.setPaidLeave(Float.parseFloat(paidLeave)); + } catch (NumberFormatException e) { + result = INPUT; + addActionError( + getText(n_("chorem.bonzoms.employee.paidLeave.wrongFormat"))); + } + try { + employee.setRtt(Float.parseFloat(rtt)); + } catch (NumberFormatException e) { + result = INPUT; + addActionError( + getText(n_("chorem.bonzoms.employee.rtt.wrongFormat"))); + } + proxy.store(employee); + } else if (person != null && employee == null) { + //If the user wants to enter the employee's details + employee = new EmployeeImpl(); + + employee.setPerson(personId); + employee.setDiploma(diploma); + employee.setPaidLeave(Float.parseFloat(paidLeave)); + employee.setRtt(Float.parseFloat(rtt)); + proxy.store(employee); + } else { + result = ERROR; + } + return result; + } + + protected String personId; + protected String employeeId; + protected String diploma; + protected String paidLeave; + protected String rtt; + + /** + * Gets the employee's information + * + * @return the employee's information + */ + public Employee getEmployee() { + ChoremProxy proxy = getChoremProxy(); + Search search = Search.query(); + Criteria criteria = search.eq(Employee.FQ_FIELD_EMPLOYEE_PERSON, + personId).criteria(); + Employee employee = proxy.findByCriteria(Employee.class, criteria); + + return employee; + } + + /** + * @return the personId + */ + public String getPersonId() { + return personId; + } + + /** + * @param personId the personId to set + */ + public void setPersonId(String personId) { + this.personId = personId; + } + + /** + * @return the employeeId + */ + public String getEmployeeId() { + return employeeId; + } + + /** + * @param employeeId the employeeId to set + */ + public void setEmployeeId(String employeeId) { + this.employeeId = employeeId; + } + + /** + * @return the diploma + */ + public String getDiploma() { + return diploma; + } + + /** + * @param diploma the diploma to set + */ + public void setDiploma(String diploma) { + this.diploma = diploma; + } + + /** + * @return the paidLeave + */ + public String getPaidLeave() { + return paidLeave; + } + + /** + * @param paidLeave the paidLeave to set + */ + public void setPaidLeave(String paidLeave) { + this.paidLeave = paidLeave; + } + + /** + * @return the rtt + */ + public String getRtt() { + return rtt; + } + + /** + * @param rtt the rtt to set + */ + public void setRtt(String rtt) { + this.rtt = rtt; + } +} Property changes on: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/EmployeeAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/PersonAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/PersonAction.java 2011-04-29 08:05:06 UTC (rev 115) +++ trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/PersonAction.java 2011-04-29 10:18:43 UTC (rev 116) @@ -359,7 +359,7 @@ } /** - * Gets the employments contracts of the employee + * Gets the employee's employments contracts * * @return a list containing all employment contracts */ @@ -405,6 +405,21 @@ } /** + * Gets the employee's information + * + * @return the employee's information + */ + public Employee getEmployee() { + ChoremProxy proxy = getChoremProxy(); + Search search = Search.query(); + Criteria criteria = search.eq(Employee.FQ_FIELD_EMPLOYEE_PERSON, + personId).criteria(); + Employee employee = proxy.findByCriteria(Employee.class, criteria); + + return employee; + } + + /** * @return the firstName */ public String getFirstName() { Modified: trunk/chorem-web/src/main/resources/struts.xml =================================================================== --- trunk/chorem-web/src/main/resources/struts.xml 2011-04-29 08:05:06 UTC (rev 115) +++ trunk/chorem-web/src/main/resources/struts.xml 2011-04-29 10:18:43 UTC (rev 116) @@ -85,6 +85,14 @@ <param name="personId">${personId}</param> </result> </action> + <action name="modifyEmployee" class="org.chorem.bonzoms.action.EmployeeAction" method="modify"> + <result name="input">/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp</result> + <result type="redirectAction"> + <param name="actionName">personDetails</param> + <param name="namespace">/bonzoms</param> + <param name="personId">${personId}</param> + </result> + </action> </package> <package name="gepeto" namespace="/gepeto" extends="struts-default"> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetails.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetails.jsp 2011-04-29 08:05:06 UTC (rev 115) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetails.jsp 2011-04-29 10:18:43 UTC (rev 116) @@ -2,38 +2,75 @@ <%@page import="org.chorem.bonzoms.action.PersonAction" %> <%@page import="org.chorem.gepeto.EmploymentContractFull" %> <%@page import="org.chorem.entities.EmploymentContract" %> +<%@page import="org.chorem.entities.Employee" %> <%@page import="java.util.List" %> <%@taglib prefix="s" uri="/struts-tags" %> <html xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" xmlns:jsp="http://java.sun.com/JSP/Page"> + <% PersonAction person = PersonAction.getAction(); %> <head> <title> <s:text name="chorem.bonzoms.personDetails.title"> - <s:param><%= PersonAction.getAction().getFirstName() %> <%= PersonAction.getAction().getLastName() %></s:param> + <s:param><%= person.getFirstName() %> <%= person.getLastName() %></s:param> </s:text> </title> <s:head /> </head> <body> - <h2><%= PersonAction.getAction().getFirstName() %> <%= PersonAction.getAction().getLastName() %></h2> + <h2><%= person.getFirstName() %> <%= person.getLastName() %></h2> <s:actionerror /> <s:url action="modifyPerson" var="modifyPerson"> - <s:param name="personId"><%= PersonAction.getAction().getPersonId() %></s:param> + <s:param name="personId"><%= person.getPersonId() %></s:param> </s:url> <form action="${modifyPerson}" method="post"> <p> - <s:text name="chorem.bonzoms.person.birthDate" />: <%= PersonAction.getAction().getBirthDate() %> + <s:text name="chorem.bonzoms.person.birthDate" />: <%= person.getBirthDate() %> <br /> <s:textfield key="chorem.bonzoms.person.email" name="email" labelSeparator=": " /> <br /> <s:submit key="chorem.misc.modify" name="submit" /> </p> </form> - <s:text name="chorem.bonzoms.person.employmentContracts" /> - <br /> + <% Employee employee = person.getEmployee(); %> + <h3><s:text name="chorem.bonzoms.employee" /></h3> + <p> + <s:url action="modifyEmployee" var="modifyEmployee"> + <s:param name="personId"><%= person.getPersonId() %></s:param> + <% + if (employee != null) { + %> + <s:param name="employeeId"><%= employee.getWikittyId() %></s:param> + <% } %> + </s:url> + <form action="${modifyEmployee}" method="post"> + <label for="diploma"><s:text name="chorem.bonzoms.employee.diploma" /></label>: + <% if (employee != null) { %> + <input type="text" name="diploma" id="diploma" value="<%= employee.getDiploma() %>" /> + <% } else { %> + <input type="text" name="diploma" id="diploma" /> + <% } %> + <br /> + <label for="paidLeave"><s:text name="chorem.bonzoms.employee.paidLeave" /></label>: + <% if (employee != null) { %> + <input type="text" name="paidLeave" id="paidLeave" value="<%= employee.getPaidLeave() %>" /> + <% } else { %> + <input type="text" name="paidLeave" id="paidLeave" /> + <% } %> + <br /> + <label for="rtt"><s:text name="chorem.bonzoms.employee.rtt" /></label>: + <% if (employee != null) { %> + <input type="text" name="rtt" id="rtt" value="<%= employee.getRtt() %>" /> + <% } else { %> + <input type="text" name="rtt" id="rtt" /> + <% } %> + <br /> + <s:submit key="chorem.misc.modify" name="modify" /> + </form> + </p> + <h3><s:text name="chorem.bonzoms.person.employmentContracts" /></h3> <% - List<EmploymentContractFull> employmentContractsFull = PersonAction.getAction().getEmploymentContracts(); + List<EmploymentContractFull> employmentContractsFull = person.getEmploymentContracts(); EmploymentContract employmentContract; for (EmploymentContractFull employmentContractFull : employmentContractsFull) { @@ -65,5 +102,11 @@ </p> </form> <% } %> + <p> + <s:url action="addEmploymentContractInput" var="addEmploymentContract"> + <s:param name="personId"><%= person.getPersonId() %></s:param> + </s:url> + <a href="${addEmploymentContract}"><s:text name="chorem.bonzoms.employmentContract.add" /></a> + </p> </body> </html> Added: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp (rev 0) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp 2011-04-29 10:18:43 UTC (rev 116) @@ -0,0 +1,51 @@ +<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@page import="org.chorem.bonzoms.action.EmployeeAction" %> +<%@page import="org.chorem.entities.Employee" %> +<%@taglib prefix="s" uri="/struts-tags" %> + +<html xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" + xmlns:jsp="http://java.sun.com/JSP/Page"> + <head> + <title></title> + <s:head /> + </head> + <body> + <s:actionerror /> + <% Employee employee = EmployeeAction.getAction().getEmployee(); %> + <h3><s:text name="chorem.bonzoms.employee" /></h3> + <p> + <s:url action="modifyEmployee" var="modifyEmployee"> + <s:param name="personId"><%= employee.getPerson() %></s:param> + <% + if (employee != null) { + %> + <s:param name="employeeId"><%= employee.getWikittyId() %></s:param> + <% } %> + </s:url> + <form action="${modifyEmployee}" method="post"> + <label for="diploma"><s:text name="chorem.bonzoms.employee.diploma" /></label>: + <% if (employee != null) { %> + <input type="text" name="diploma" id="diploma" value="<%= employee.getDiploma() %>" /> + <% } else { %> + <input type="text" name="diploma" id="diploma" /> + <% } %> + <br /> + <label for="paidLeave"><s:text name="chorem.bonzoms.employee.paidLeave" /></label>: + <% if (employee != null) { %> + <input type="text" name="paidLeave" id="paidLeave" value="<%= employee.getPaidLeave() %>" /> + <% } else { %> + <input type="text" name="paidLeave" id="paidLeave" /> + <% } %> + <br /> + <label for="rtt"><s:text name="chorem.bonzoms.employee.rtt" /></label>: + <% if (employee != null) { %> + <input type="text" name="rtt" id="rtt" value="<%= employee.getRtt() %>" /> + <% } else { %> + <input type="text" name="rtt" id="rtt" /> + <% } %> + <br /> + <s:submit key="chorem.misc.modify" name="modify" /> + </form> + </p> + </body> +</html> Property changes on: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmployee.jsp ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmploymentContract.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmploymentContract.jsp 2011-04-29 08:05:06 UTC (rev 115) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/bonzoms/personDetailsEmploymentContract.jsp 2011-04-29 10:18:43 UTC (rev 116) @@ -46,7 +46,7 @@ <label for="workingTime"><s:text name="chorem.bonzoms.employmentContract.workingTime" /></label>: <input type="text" name="workingTime" id="workingTime" value="<%= employmentContract.getWorkingTime() %>" size="2" /> <br /> - <input type="submit" name="modify" /> + <s:submit key="chorem.misc.modify" name="modify" /> </p> </form> <% } %>