Author: vbriand Date: 2011-04-08 11:11:46 +0200 (Fri, 08 Apr 2011) New Revision: 68 Url: http://chorem.org/repositories/revision/chorem/68 Log: Added a test to forbid access to the project order's page for a quotation if it is already linked with another project order Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectOrderAction.java Modified: trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectOrderAction.java =================================================================== --- trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectOrderAction.java 2011-04-08 08:51:36 UTC (rev 67) +++ trunk/chorem-web/src/main/java/org/chorem/gepeto/action/ProjectOrderAction.java 2011-04-08 09:11:46 UTC (rev 68) @@ -9,8 +9,11 @@ import org.apache.commons.logging.LogFactory; import org.chorem.ChoremProxy; import org.chorem.action.BaseAction; +import org.chorem.entities.ProjectOrder; import org.chorem.entities.ProjectOrderImpl; import org.chorem.entities.Quotation; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.Search; import com.opensymphony.xwork2.ActionContext; import static org.nuiton.i18n.I18n.n_; @@ -50,7 +53,8 @@ Quotation quotation = proxy.restore(Quotation.class, quotationId); - if (quotation == null) { //If the quotationId doesn't exist + //If the quotationId doesn't exist or if the quotation already has a project order + if (quotation == null || quotationHasProjectOrder(quotation)) { result = ERROR; } else { quotationReference = quotation.getReference(); @@ -138,6 +142,23 @@ } return result; } + + /** + * Tests if a quotation already has a project order + * + * @param quotation + * @return true if the quotation already has a project order, false otherwise + */ + protected boolean quotationHasProjectOrder(Quotation quotation) { + ChoremProxy proxy = getChoremProxy(); + Search search = Search.query(); + Criteria criteria = search.eq(ProjectOrder.FQ_FIELD_PROJECTORDER_QUOTATION, + quotationId).criteria(); + ProjectOrder result = proxy.findByCriteria(ProjectOrder.class, criteria); + boolean hasProjectOrder = (result != null); + + return hasProjectOrder; + } /** * @return the type