r50 - in trunk/chorem-web/src/main: java/org/chorem/action java/org/chorem/billy/action java/org/chorem/gepeto/action resources resources/i18n resources/org/chorem/billy/action webapp/WEB-INF/jsp/billy webapp/WEB-INF/jsp/common/inc webapp/WEB-INF/jsp/gepeto
Author: vbriand Date: 2011-04-01 15:50:42 +0200 (Fri, 01 Apr 2011) New Revision: 50 Url: http://chorem.org/repositories/revision/chorem/50 Log: A quotation can now be linked with its project Added: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-addQuotation-validation.xml Removed: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml Modified: trunk/chorem-web/src/main/java/org/chorem/action/BaseAction.java trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 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/billy/addQuotation.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/common/inc/header.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp Modified: trunk/chorem-web/src/main/java/org/chorem/action/BaseAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/action/BaseAction.java 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/java/org/chorem/action/BaseAction.java 2011-04-01 13:50:42 UTC (rev 50) @@ -28,6 +28,8 @@ public static final String UNTRANSLATED_MARKER = "???"; + protected static final String MISSING_PARAM = "param"; + protected Map<String, Object> session; public ChoremSession getChoremSession() { Modified: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-01 13:50:42 UTC (rev 50) @@ -2,13 +2,17 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.UUID; 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.Project; import org.chorem.entities.QuotationImpl; +import com.opensymphony.xwork2.ActionContext; + import static org.nuiton.i18n.I18n.n_; /** @@ -22,6 +26,10 @@ private static final Log log = LogFactory.getLog(BaseAction.class); + static public QuotationAction getAction() { + return (QuotationAction)ActionContext.getContext().get(CONTEXT_ACTION_KEY); + } + /** * Adds a new quotation * @@ -31,19 +39,40 @@ */ public String add() { String result = INPUT; + ChoremProxy proxy = getChoremProxy(); - if (reference != null && description != null && amount != null && - vta != null && postedDate != null) { - //If the quotation has been created successfully - if (addQuotation()) { - result = SUCCESS; + try { + if (projectId == null) { + result = ERROR; } else { - result = ERROR; + //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 doesn't exist + result = ERROR; + } else { + projectName = project.getName(); + 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; + } + } + } } + } catch (IllegalArgumentException e) { + result = ERROR; } return result; } + protected String projectId; + protected String projectName; protected String reference; protected String description; protected String amount; @@ -68,6 +97,7 @@ newQuotation.setDescription(description); newQuotation.setAmount(Double.parseDouble(amount)); newQuotation.setVTA(Double.parseDouble(vta)); + newQuotation.setProject(projectId); //Lenient mode disabled because results may be very odd formatter.setLenient(false); @@ -159,4 +189,32 @@ public void setPostedDate(String postedDate) { this.postedDate = postedDate; } + + /** + * @return the projectId + */ + public String getProjectId() { + return projectId; + } + + /** + * @param projectId the projectId to set + */ + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + /** + * @return the projectName + */ + public String getProjectName() { + return projectName; + } + + /** + * @param projectName the projectName to set + */ + public void setProjectName(String projectName) { + this.projectName = projectName; + } } 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-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-04-01 13:50:42 UTC (rev 50) @@ -69,16 +69,20 @@ 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()); + if (projectId == null) { + result = ERROR; } else { - result = ERROR; + //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()); + } else { + result = ERROR; + } } } catch (IllegalArgumentException e) { result = ERROR; @@ -115,10 +119,14 @@ return result; } - public List<Project> getProjectsByYear() { - //TODO: change + /** + * Gets all existing projects + * + * @return all projects in database + */ + public List<Project> getAllProjects() { ChoremProxy proxy = getChoremProxy(); - Criteria criteria = Search.query().isNotNull(Project.FQ_FIELD_PROJECT_NAME).criteria(); + Criteria criteria = Search.query().isNotNull(Project.EXT_PROJECT).criteria(); PagedResult<Project> result = proxy.findAllByCriteria(Project.class, criteria); List<Project> projects = result.getAll(); return projects; 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-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_en_GB.properties 2011-04-01 13:50:42 UTC (rev 50) @@ -2,6 +2,7 @@ chorem.billy.home=Home chorem.billy.quotation=Quotation chorem.billy.quotation.add=Add a new quotation +chorem.billy.quotation.addToProject=Add a new quotation to the project "{0}" 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 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-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/resources/i18n/chorem-web_fr_FR.properties 2011-04-01 13:50:42 UTC (rev 50) @@ -2,6 +2,7 @@ chorem.billy.home=Accueil chorem.billy.quotation=Devis chorem.billy.quotation.add=Ajouter un nouveau devis +chorem.billy.quotation.addToProject=Ajouter un nouveau devis au projet "{0}" 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 Copied: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-addQuotation-validation.xml (from rev 49, trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml) =================================================================== --- trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-addQuotation-validation.xml (rev 0) +++ trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-addQuotation-validation.xml 2011-04-01 13:50:42 UTC (rev 50) @@ -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.quotation.reference.required" /> + </field-validator> + </field> + <field name="description"> + <field-validator type="requiredstring"> + <message key="chorem.billy.quotation.description.required" /> + </field-validator> + </field> + <field name="amount"> + <field-validator type="requiredstring"> + <message key="chorem.billy.quotation.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.quotation.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.quotation.postedDate.required" /> + </field-validator> + </field> +</validators> Property changes on: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-addQuotation-validation.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: 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 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-validation.xml 2011-04-01 13:50:42 UTC (rev 50) @@ -1,39 +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="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> Modified: trunk/chorem-web/src/main/resources/struts.xml =================================================================== --- trunk/chorem-web/src/main/resources/struts.xml 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/resources/struts.xml 2011-04-01 13:50:42 UTC (rev 50) @@ -98,11 +98,12 @@ <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 name="addQuotationInput" class="org.chorem.billy.action.QuotationAction" method="add"> + <result name="input">/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 name="error" type="redirectAction">home</result> <result type="redirectAction">home</result> </action> </package> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/addQuotation.jsp 2011-04-01 13:50:42 UTC (rev 50) @@ -1,4 +1,5 @@ <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@page import="org.chorem.billy.action.QuotationAction" %> <%@taglib prefix="s" uri="/struts-tags" %> <html xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" @@ -8,9 +9,16 @@ <s:head /> </head> <body> - <h2><s:text name="chorem.billy.quotation.add" /></h2> + <h2> + <s:text name="chorem.billy.quotation.addToProject"> + <s:param><%= QuotationAction.getAction().getProjectName() %></s:param> + </s:text> + </h2> <s:actionerror /> - <s:form action="addQuotation" method="post"> + <s:url action="addQuotation" var="addQuotation"> + <s:param name="projectId"><%= QuotationAction.getAction().getProjectId() %></s:param> + </s:url> + <form action="${addQuotation}" method="post"> <fieldset> <legend> <s:text name="chorem.billy.quotation" /> @@ -27,6 +35,6 @@ <br /> <s:submit key="chorem.billy.quotation.add" name="submit" /> </fieldset> - </s:form> + </form> </body> </html> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/common/inc/header.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/common/inc/header.jsp 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/common/inc/header.jsp 2011-04-01 13:50:42 UTC (rev 50) @@ -1,7 +1,8 @@ <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> +<%@taglib prefix="s" uri="/struts-tags" %> <div id="header" xmlns:s="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" xmlns:jsp="http://java.sun.com/JSP/Page"> - Bonzoms - Ca$h - billy - gepeto + <s:a namespace="/bonzoms" action="home">Bonzoms</s:a> - <s:a namespace="/cash" action="home">Ca$h</s:a> - <s:a namespace="/billy" action="home">billy</s:a> - <s:a namespace="/gepeto" action="home">gepeto</s:a> </div> \ No newline at end of file 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-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectDetails.jsp 2011-04-01 13:50:42 UTC (rev 50) @@ -20,6 +20,12 @@ </h2> <p> <s:textarea readonly="true" name="description" key="chorem.gepeto.project.description" cols="50" rows="10" labelposition="top" /> + <br /> + <br /> + <s:url namespace="/billy" action="addQuotation_input" var="addQuotation"> + <s:param name="projectId"><%= ProjectAction.getAction().getProjectId() %></s:param> + </s:url> + <a href="${addQuotation}"><s:text name="chorem.billy.quotation.add" /></a> </p> </body> </html> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp 2011-04-01 12:14:10 UTC (rev 49) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/gepeto/projectsByYear.jsp 2011-04-01 13:50:42 UTC (rev 50) @@ -28,7 +28,7 @@ <tr> </thead> <tbody> - <s:iterator value="projectsByYear"> + <s:iterator value="allProjects"> <tr> <s:url action="projectDetails" var="projectDetails"> <s:param name="projectId"><s:property value="wikittyId" /></s:param>
participants (1)
-
vbriand@users.chorem.org