Author: vbriand Date: 2011-04-22 15:20:52 +0200 (Fri, 22 Apr 2011) New Revision: 107 Url: http://chorem.org/repositories/revision/chorem/107 Log: The quotation can now be modified Added: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-modifyQuotation-validation.xml Modified: trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/CompanyAction.java trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java trunk/chorem-web/src/main/resources/struts.xml trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/quotationDetails.jsp 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-22 12:36:51 UTC (rev 106) +++ trunk/chorem-web/src/main/java/org/chorem/billy/action/QuotationAction.java 2011-04-22 13:20:52 UTC (rev 107) @@ -101,11 +101,13 @@ Quotation quotation = proxy.restore(Quotation.class, quotationId); if (quotation != null) { //If the quotationId exists + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + setReference(quotation.getReference()); setDescription(quotation.getDescription()); setAmount(String.valueOf(quotation.getAmount())); setVta(String.valueOf(quotation.getVTA())); - setPostedDate(quotation.getPostedDate().toString()); + setPostedDate(formatter.format(quotation.getPostedDate())); setProjectId(quotation.getProject()); } else { result = ERROR; @@ -118,6 +120,41 @@ return result; } + /** + * Modifies the quotation's information + * + * @return SUCCESS if the quotation has been successfully modified, + * INPUT if the date format is incorrect, + * ERROR if the id is invalid + */ + public String modify() { + String result = SUCCESS; + Quotation quotation; + ChoremProxy proxy = getChoremProxy(); + SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); + + quotation = proxy.restore(Quotation.class, quotationId); + if (quotation != null) { //If the id exists + quotation.setDescription(description); + quotation.setAmount(Double.parseDouble(amount)); + quotation.setVTA(Double.parseDouble(vta)); + + formatter.setLenient(false); + try { + quotation.setPostedDate(formatter.parse(postedDate)); + } catch (ParseException e) { + result = INPUT; + addFieldError("postedDate", getText(n_("chorem.date.wrongFormat"))); + } + if (result.equals(SUCCESS)) { + proxy.store(quotation); + } + } else { + result = ERROR; + } + return result; + } + protected String projectId; protected String projectName; protected String reference; Modified: trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/CompanyAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/CompanyAction.java 2011-04-22 12:36:51 UTC (rev 106) +++ trunk/chorem-web/src/main/java/org/chorem/bonzoms/action/CompanyAction.java 2011-04-22 13:20:52 UTC (rev 107) @@ -108,10 +108,10 @@ } /** - * Modifies the company information + * Modifies the company's information * - * @return SUCCESS if the modification was successful, - * ERROR otherwise + * @return SUCCESS if the company has been modified, + * ERROR if the id is invalid */ public String modify() { String result = SUCCESS; @@ -119,58 +119,63 @@ Company company; company = proxy.restore(Company.class, companyId); - company.setType(type); - proxy.store(company); - List<ContactDetails> contactDetailsList = ChoremProxy. - getContactDetails(companyId); - boolean newPhone = true, newWebsite = true; - - //Modification of existing contact details - for (ContactDetails contactDetails : contactDetailsList) { - if (contactDetails.getName().equals( + if (company != null) { //If the id exists + company.setType(type); + proxy.store(company); + + List<ContactDetails> contactDetailsList = ChoremProxy. + getContactDetails(companyId); + boolean newPhone = true, newWebsite = true; + + //Modification of existing contact details + for (ContactDetails contactDetails : contactDetailsList) { + if (contactDetails.getName().equals( CONTACT_DETAILS_POSTAL_ADDRESS + " of company \"" + company.getName() + "\"")) { - contactDetails.setValue(address); - } else if (contactDetails.getName().equals( - CONTACT_DETAILS_PHONE + " of company \"" + - company.getName() + "\"")) { - contactDetails.setValue(phoneNb); - newPhone = false; - } else if (contactDetails.getName().equals( - CONTACT_DETAILS_WEBSITE + " of company \"" + - company.getName() + "\"")) { - contactDetails.setValue(website); - newWebsite = false; + contactDetails.setValue(address); + } else if (contactDetails.getName().equals( + CONTACT_DETAILS_PHONE + " of company \"" + + company.getName() + "\"")) { + contactDetails.setValue(phoneNb); + newPhone = false; + } else if (contactDetails.getName().equals( + CONTACT_DETAILS_WEBSITE + " of company \"" + + company.getName() + "\"")) { + contactDetails.setValue(website); + newWebsite = false; + } + proxy.store(contactDetails); } - proxy.store(contactDetails); - } - - //Phone number added - if (newPhone && !phoneNb.isEmpty()) { - ContactDetailsImpl newContactDetails = new ContactDetailsImpl(); - newContactDetails = new ContactDetailsImpl(); - newContactDetails.setName(CONTACT_DETAILS_PHONE + - " of company \"" + company.getName() + "\""); - newContactDetails.setType(CONTACT_DETAILS_PHONE); - newContactDetails.setValue(phoneNb); - newContactDetails.setTarget(company.getWikittyId()); - proxy.store(newContactDetails); - System.out.println(newContactDetails); - } - - //Website added - if (newWebsite && !website.isEmpty()) { - ContactDetailsImpl newContactDetails = new ContactDetailsImpl(); + //Phone number added + if (newPhone && !phoneNb.isEmpty()) { + ContactDetailsImpl newContactDetails = new ContactDetailsImpl(); + + newContactDetails = new ContactDetailsImpl(); + newContactDetails.setName(CONTACT_DETAILS_PHONE + + " of company \"" + company.getName() + "\""); + newContactDetails.setType(CONTACT_DETAILS_PHONE); + newContactDetails.setValue(phoneNb); + newContactDetails.setTarget(company.getWikittyId()); + proxy.store(newContactDetails); + System.out.println(newContactDetails); + } - newContactDetails = new ContactDetailsImpl(); - newContactDetails.setName(CONTACT_DETAILS_WEBSITE + - " of company \"" + company.getName() + "\""); - newContactDetails.setType(CONTACT_DETAILS_WEBSITE); - newContactDetails.setValue(website); - newContactDetails.setTarget(company.getWikittyId()); - proxy.store(newContactDetails); + //Website added + if (newWebsite && !website.isEmpty()) { + ContactDetailsImpl newContactDetails = new ContactDetailsImpl(); + + newContactDetails = new ContactDetailsImpl(); + newContactDetails.setName(CONTACT_DETAILS_WEBSITE + + " of company \"" + company.getName() + "\""); + newContactDetails.setType(CONTACT_DETAILS_WEBSITE); + newContactDetails.setValue(website); + newContactDetails.setTarget(company.getWikittyId()); + proxy.store(newContactDetails); + } + } else { + result = ERROR; } return result; } 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-22 12:36:51 UTC (rev 106) +++ trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectAction.java 2011-04-22 13:20:52 UTC (rev 107) @@ -124,14 +124,24 @@ return result; } + /** + * Modifies the project's information + * + * @return SUCCESS if the project has been successfully modified, + * ERROR if the id is invalid + */ public String modify() { String result = SUCCESS; Project project; ChoremProxy proxy = getChoremProxy(); project = proxy.restore(Project.class, projectId); - project.setDescription(description); - proxy.store(project); + if (project != null) { //If the id exists + project.setDescription(description); + proxy.store(project); + } else { + result = ERROR; + } return result; } Added: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-modifyQuotation-validation.xml =================================================================== --- trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-modifyQuotation-validation.xml (rev 0) +++ trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-modifyQuotation-validation.xml 2011-04-22 13:20:52 UTC (rev 107) @@ -0,0 +1,38 @@ +<!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="description"> + <field-validator type="requiredstring"> + <message key="chorem.field.required" /> + </field-validator> + </field> + <field name="amount"> + <field-validator type="requiredstring"> + <message key="chorem.field.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.field.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.field.required" /> + </field-validator> + <field-validator type="regex"> + <param name="expression"><![CDATA[([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})]]></param> + <message key="chorem.date.wrongFormat" /> + </field-validator> + </field> +</validators> Property changes on: trunk/chorem-web/src/main/resources/org/chorem/billy/action/QuotationAction-modifyQuotation-validation.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/chorem-web/src/main/resources/struts.xml =================================================================== --- trunk/chorem-web/src/main/resources/struts.xml 2011-04-22 12:36:51 UTC (rev 106) +++ trunk/chorem-web/src/main/resources/struts.xml 2011-04-22 13:20:52 UTC (rev 107) @@ -154,6 +154,15 @@ <result name="error" type="redirectAction">home</result> <result>/WEB-INF/jsp/billy/quotationDetails.jsp</result> </action> + <action name="modifyQuotation" class="org.chorem.billy.action.QuotationAction" method="modify"> + <result name="input">/WEB-INF/jsp/billy/quotationDetails.jsp</result> + <result name="error" type="redirectAction">home</result> + <result type="redirectAction"> + <param name="actionName">quotationDetails</param> + <param name="namespace">/billy</param> + <param name="quotationId">${quotationId}</param> + </result> + </action> </package> <!--<package name="cash" namespace="/cash" extends="struts-default"> Modified: trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/quotationDetails.jsp =================================================================== --- trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/quotationDetails.jsp 2011-04-22 12:36:51 UTC (rev 106) +++ trunk/chorem-web/src/main/webapp/WEB-INF/jsp/billy/quotationDetails.jsp 2011-04-22 13:20:52 UTC (rev 107) @@ -19,17 +19,26 @@ <s:param><%= QuotationAction.getAction().getReference() %></s:param> </s:text> </h2> + <s:url action="modifyQuotation" var="modifyQuotation"> + <s:param name="quotationId"><%= QuotationAction.getAction().getQuotationId() %></s:param> + </s:url> + <form action="${modifyQuotation}" method="post"> + <p> + <s:textarea name="description" key="chorem.billy.quotation.description" cols="50" rows="10" labelposition="top" labelSeparator=": " /> + <br /> + <br /> + <s:textfield name="amount" key="chorem.billy.quotation.amount" labelSeparator=": " size="5" /> + <br /> + <s:textfield name="vta" key="chorem.billy.quotation.vta" labelSeparator=": " size="2" />% + <br /> + <s:textfield name="postedDate" key="chorem.billy.quotation.postedDate" labelSeparator=": " /> + <br /> + <s:submit key="chorem.misc.modify" name="modify" /> + </p> + </form> <p> - <s:textarea readonly="true" name="description" key="chorem.billy.quotation.description" cols="50" rows="10" labelposition="top" labelSeparator=": " /> <br /> <br /> - <s:textfield readonly="true" name="amount" key="chorem.billy.quotation.amount" labelSeparator=": " /> - <br /> - <s:textfield readonly="true" name="vta" key="chorem.billy.quotation.vta" labelSeparator=": " /> - <br /> - <s:textfield readonly="true" name="postedDate" key="chorem.billy.quotation.postedDate" labelSeparator=": " /> - <br /> - <br /> <% ProjectOrder projectOrder = QuotationAction.getAction().getProjectOrder();