r49 - in trunk/chorem-web/src/main: java/org/chorem java/org/chorem/billy java/org/chorem/billy/action java/org/chorem/gepeto/action resources resources/i18n resources/org/chorem resources/org/chorem/billy resources/org/chorem/billy/action resources/org/chorem/gepeto/action webapp/WEB-INF/jsp webapp/WEB-INF/jsp/billy webapp/WEB-INF/jsp/gepeto
Author: vbriand Date: 2011-04-01 14:14:10 +0200 (Fri, 01 Apr 2011) New Revision: 49 Url: http://chorem.org/repositories/revision/chorem/49 Log: New class with validation for adding a quotation. The project details can now displayed properly (only name and description) The "every method returns INPUT" bug has been resolved by renaming ProjectAction-validation.xml to ProjectAction-addProject-validation.xml Added: trunk/chorem-web/src/main/java/org/chorem/billy/ trunk/chorem-web/src/main/java/org/chorem/billy/action/ trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java trunk/chorem-web/src/main/resources/org/chorem/billy/ trunk/chorem-web/src/main/resources/org/chorem/billy/action/ trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-addProject-validation.xml trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/home.jsp Removed: trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-validation.xml Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties trunk/chorem-web/src/main/resources/struts.xml trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp Added: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java (rev 0) +++ trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-01 12:14:10 UTC (rev 49) @@ -0,0 +1,162 @@ +package org.chorem.billy.action; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +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.QuotationImpl; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Quotation management class + * + * @author vbriand + */ +public class QuotationAction extends BaseAction { + + private static final long serialVersionUID = -8773692389143447193L; + + private static final Log log = LogFactory.getLog(BaseAction.class); + + /** + * Adds a new quotation + * + * @return INPUT if the mandatory fields haven't all been filled in + * @return SUCCESS if the quotation has been added + * @return ERROR if an error occurred + */ + public String add() { + String result = INPUT; + + if (reference != null && description != null && amount != null && + vta != null && postedDate != null) { + //If the quotation has been created successfully + if (addQuotation()) { + result = SUCCESS; + } else { + result = ERROR; + } + } + return result; + } + + protected String reference; + protected String description; + protected String amount; + protected String vta; + protected String postedDate; + + /** + * Stores the new quotation through the proxy + * + * @return true if the quotation has been stored properly + * @return false if a problem occurred + */ + protected boolean addQuotation() { + boolean result = true; + + try { + ChoremProxy proxy = getChoremProxy(); + QuotationImpl newQuotation = new QuotationImpl(); + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + + newQuotation.setReference(reference); + newQuotation.setDescription(description); + newQuotation.setAmount(Double.parseDouble(amount)); + newQuotation.setVTA(Double.parseDouble(vta)); + + //Lenient mode disabled because results may be very odd + formatter.setLenient(false); + try { + newQuotation.setPostedDate(formatter.parse(postedDate)); + } catch (ParseException e) { + result = false; + addActionError(getText(n_("chorem.date.wrongFormat"))); + } + + //If everything went smoothly + if (result) { + proxy.store(newQuotation); + } + } catch (Exception e) { + result = false; + addActionError(getText(n_("chorem.billy.quotation.create.error"))); + log.error("An error occurred while creating a new quotation", e); + } + return result; + } + + /** + * @return the reference + */ + public String getReference() { + return reference; + } + + /** + * @param reference the reference to set + */ + public void setReference(String reference) { + this.reference = reference; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the amount + */ + public String getAmount() { + return amount; + } + + /** + * @param amount the amount to set + */ + public void setAmount(String amount) { + this.amount = amount; + } + + /** + * @return the vta + */ + public String getVta() { + return vta; + } + + /** + * @param vta the vta to set + */ + public void setVta(String vta) { + this.vta = vta; + } + + /** + * @return the postedDate + */ + public String getPostedDate() { + return postedDate; + } + + /** + * @param postedDate the postedDate to set + */ + public void setPostedDate(String postedDate) { + this.postedDate = postedDate; + } +} Property changes on: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-04-01 12:14:10 UTC (rev 49) @@ -1,6 +1,7 @@ package org.chorem.gepeto.action; import java.util.List; +import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -53,43 +54,37 @@ } } return result; - } - public String execute() throws Exception { - log.info("execute"); - return super.execute(); - } + } - public String input() throws Exception { - log.info("input"); - return super.input(); - } - + /** + * Retrieves the name and the description of the project referenced by the + * projectId + * + * @return SUCCESS if the name and the description have been retrieved + * @return ERROR either if the UUID is invalid or the projectId doesn't + * exist + */ public String projectDetails() { - System.out.println("TOTOTOTOTO"); - /*ChoremProxy proxy = getChoremProxy(); - Criteria criteria = Search.query().eq(element, value)*/ - /*List<Project> projects = getProjectsByYear(); - System.out.println("ID:"+projectId); - for (Project project : projects) { - System.out.println("[[["+project.getWikittyId() + "]]]"); - if (project.getWikittyId().equals(projectId)) { + String result = SUCCESS; + ChoremProxy proxy = getChoremProxy(); + + try { + //If projectId isn't a valid UUID, an exception is thrown + UUID.fromString(projectId); + + Project project = proxy.restore(Project.class, projectId); + + if (project != null) { //If the projectId exists setName(project.getName()); setDescription(project.getDescription()); - break; + } else { + result = ERROR; } - }*/ - return SUCCESS; + } catch (IllegalArgumentException e) { + result = ERROR; + } + return result; } - - /** - * Removes a project - * - * @return - */ - public String remove() { - //TODO: implement - return SUCCESS; - } protected String year; protected String name; Modified: trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties =================================================================== --- trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties 2011-04-01 12:14:10 UTC (rev 49) @@ -1,4 +1,13 @@ chorem.beginDate.beforeToday=The date cannot be set before today''s date +chorem.billy.home=Home +chorem.billy.quotation=Quotation +chorem.billy.quotation.add=Add a new quotation +chorem.billy.quotation.amount=Amount +chorem.billy.quotation.create.error=An error occurred while creating your new quotation, please try again. If the problem persists, please contact an administrator +chorem.billy.quotation.description=Description +chorem.billy.quotation.postedDate=Posted date +chorem.billy.quotation.reference=Reference +chorem.billy.quotation.vta=VTA chorem.bonzoms.company=Company {0} chorem.bonzoms.company.add=Add a new company chorem.bonzoms.company.addressLine1=Address @@ -77,7 +86,7 @@ chorem.gepeto.project.description.required=You must describe the project chorem.gepeto.project.name=Project''s name chorem.gepeto.project.name.required=You must enter the project''s name -chorem.gepeto.projectDetails.title=Details of project {0} +chorem.gepeto.projectDetails.title=Details of project "{0}" chorem.gepeto.projectOrder=Project order chorem.gepeto.projectOrder.add=Add a new project order chorem.gepeto.projectOrder.beginDate=Begin date (dd/mm/yyyy) Modified: trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties =================================================================== --- trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties 2011-04-01 12:14:10 UTC (rev 49) @@ -1,4 +1,13 @@ chorem.beginDate.beforeToday=La date entr\u00E9e ne peut \u00EAtre ant\u00E9rieure \u00E0 la date du jour +chorem.billy.home=Accueil +chorem.billy.quotation=Devis +chorem.billy.quotation.add=Ajouter un nouveau devis +chorem.billy.quotation.amount=Montant +chorem.billy.quotation.create.error=Une erreur s''est produite lors de la cr\u00E9ation de votre nouveau devis, merci d''essayer \u00E0 nouveau. Si le probl\u00E8me se reproduit, merci de contacter un administrateur +chorem.billy.quotation.description=Description +chorem.billy.quotation.postedDate=Date de d\u00E9p\u00F4t +chorem.billy.quotation.reference=R\u00E9f\u00E9rence +chorem.billy.quotation.vta=TVA chorem.bonzoms.company=Soci\u00E9t\u00E9 chorem.bonzoms.company.add=Ajouter une nouvelle soci\u00E9t\u00E9 chorem.bonzoms.company.addressLine1=Adresse @@ -73,7 +82,7 @@ chorem.gepeto.project.description.required=Vous devez d\u00E9crire le projet chorem.gepeto.project.name=Nom du projet chorem.gepeto.project.name.required=Vous devez renseigner un nom pour le projet -chorem.gepeto.projectDetails.title=D\u00E9tails du projet {0} +chorem.gepeto.projectDetails.title=D\u00E9tails du projet "{0}" chorem.gepeto.projectOrder=Contrat de commande d''un projet chorem.gepeto.projectOrder.add=Ajouter le contrat d''un projet chorem.gepeto.projectOrder.beginDate=Date de d\u00E9but Added: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml =================================================================== --- trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml (rev 0) +++ trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml 2011-04-01 12:14:10 UTC (rev 49) @@ -0,0 +1,39 @@ +<!DOCTYPE validators PUBLIC + "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="reference"> + <field-validator type="requiredstring"> + <message key="chorem.billy.reference.required" /> + </field-validator> + </field> + <field name="description"> + <field-validator type="requiredstring"> + <message key="chorem.billy.description.required" /> + </field-validator> + </field> + <field name="amount"> + <field-validator type="requiredstring"> + <message key="chorem.billy.amount.required" /> + </field-validator> + <field-validator type="regex"> + <param name="expression"><![CDATA[([0-9]+)([\.,][0-9]+)?]]></param> + <message key="chorem.billy.quotation.amount.wrongFormat" /> + </field-validator> + </field> + <field name="vta"> + <field-validator type="requiredstring"> + <message key="chorem.billy.vta.required" /> + </field-validator> + <field-validator type="regex"> + <param name="expression"><![CDATA[([0-9]+)([\.,][0-9]+)?]]></param> + <message key="chorem.billy.quotation.vta.wrongFormat" /> + </field-validator> + </field> + <field name="postedDate"> + <field-validator type="requiredstring"> + <message key="chorem.billy.postedDate.required" /> + </field-validator> + </field> +</validators> Property changes on: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-addProject-validation.xml (from rev 48, trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-validation.xml) =================================================================== --- trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-addProject-validation.xml (rev 0) +++ trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-addProject-validation.xml 2011-04-01 12:14:10 UTC (rev 49) @@ -0,0 +1,16 @@ +<!DOCTYPE validators PUBLIC + "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="name"> + <field-validator type="requiredstring"> + <message key="chorem.gepeto.project.name.required" /> + </field-validator> + </field> + <field name="description"> + <field-validator type="requiredstring"> + <message key="chorem.gepeto.project.description.required" /> + </field-validator> + </field> +</validators> Property changes on: trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-addProject-validation.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-validation.xml =================================================================== --- trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-validation.xml 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/resources/org/chorem/gepeto/action/ProjectAction-validation.xml 2011-04-01 12:14:10 UTC (rev 49) @@ -1,16 +0,0 @@ -<!DOCTYPE validators PUBLIC - "-//OpenSymphony Group//XWork Validator 1.0.2//EN" - "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> - -<validators> - <field name="name"> - <field-validator type="requiredstring"> - <message key="chorem.gepeto.project.name.required" /> - </field-validator> - </field> - <field name="description"> - <field-validator type="requiredstring"> - <message key="chorem.gepeto.project.description.required" /> - </field-validator> - </field> -</validators> Modified: trunk/chorem-web/src/main/resources/struts.xml =================================================================== --- trunk/chorem-web/src/main/resources/struts.xml 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/resources/struts.xml 2011-04-01 12:14:10 UTC (rev 49) @@ -54,7 +54,6 @@ <package name="gepeto" namespace="/gepeto" extends="struts-default"> <default-action-ref name="home" /> - <action name="home"> <result>/WEB-INF/jsp/gepeto/home.jsp</result> </action> @@ -86,22 +85,29 @@ <result type="redirectAction">home</result> </action> <action name="getProjectsByYear" class="org.chorem.gepeto.action.ProjectAction"> - <result name="input">/WEB-INF/jsp/gepeto/projectsByYear.jsp</result> + <result>/WEB-INF/jsp/gepeto/projectsByYear.jsp</result> </action> <action name="projectDetails" class="org.chorem.gepeto.action.ProjectAction" method="projectDetails"> - - <result name="success">/WEB-INF/jsp/gepeto/projectDetails.jsp</result> + <result name="error" type="redirectAction">home</result> + <result>/WEB-INF/jsp/gepeto/projectDetails.jsp</result> </action> </package> -<!--<package name="billy" namespace="/billy" extends="struts-default"> + <package name="billy" namespace="/billy" extends="struts-default"> <default-action-ref name="home" /> <action name="home"> <result>/WEB-INF/jsp/billy/home.jsp</result> </action> + <action name="addQuotation_input"> + <result>/WEB-INF/jsp/billy/addQuotation.jsp</result> + </action> + <action name="addQuotation" class="org.chorem.billy.action.QuotationAction" method="add"> + <result name="input">/WEB-INF/jsp/billy/addQuotation.jsp</result> + <result type="redirectAction">home</result> + </action> </package> - <package name="cash" namespace="/cash" extends="struts-default"> +<!--<package name="cash" namespace="/cash" extends="struts-default"> <default-action-ref name="home" /> <action name="home"> <result>/WEB-INF/jsp/cash/home.jsp</result> Added: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp (rev 0) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp 2011-04-01 12:14:10 UTC (rev 49) @@ -0,0 +1,32 @@ +<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@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><s:text name="chorem.billy.quotation.add" /></title> + <s:head /> + </head> + <body> + <h2><s:text name="chorem.billy.quotation.add" /></h2> + <s:actionerror /> + <s:form action="addQuotation" method="post"> + <fieldset> + <legend> + <s:text name="chorem.billy.quotation" /> + </legend> + <s:textfield key="chorem.billy.quotation.reference" name="reference" labelSeparator=": " /> + <br /> + <s:textfield key="chorem.billy.quotation.description" name="description" labelSeparator=": " /> + <br /> + <s:textfield key="chorem.billy.quotation.amount" name="amount" labelSeparator=": " /> + <br /> + <s:textfield key="chorem.billy.quotation.vta" name="vta" labelSeparator=": " /> + <br /> + <s:textfield key="chorem.billy.quotation.postedDate" name="postedDate" labelSeparator=": " /> + <br /> + <s:submit key="chorem.billy.quotation.add" name="submit" /> + </fieldset> + </s:form> + </body> +</html> Property changes on: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/home.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/home.jsp (rev 0) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/home.jsp 2011-04-01 12:14:10 UTC (rev 49) @@ -0,0 +1,13 @@ +<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@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><s:text name="chorem.billy.home" /></title> + <s:head /> + </head> + <body> + <s:a action="addQuotation_input"><s:text name="chorem.billy.quotation.add" /></s:a><br /> + </body> +</html> Property changes on: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/home.jsp ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp 2011-03-31 16:20:53 UTC (rev 48) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp 2011-04-01 12:14:10 UTC (rev 49) @@ -10,16 +10,16 @@ <s:param><%= ProjectAction.getAction().getName() %></s:param> </s:text> </title> - <s:head /> + <!--<s:head />--> </head> <body> <h2> <s:text name="chorem.gepeto.project"> - <%= ProjectAction.getAction().getName() %> + <s:param><%= ProjectAction.getAction().getName() %></s:param> </s:text> </h2> <p> - <s:textarea readonly="true" value="projectDescription" key="chorem.gepeto.project.description" cols="50" rows="10" labelposition="top" /> + <s:textarea readonly="true" name="description" key="chorem.gepeto.project.description" cols="50" rows="10" labelposition="top" /> </p> </body> </html>
participants (1)
-
vbriand@users.chorem.org