From ddb28627945c38abbda79a286aab93def20b005f Mon Sep 17 00:00:00 2001 From: Susana Montes Pedreira Date: Wed, 23 Nov 2011 17:32:32 +0100 Subject: [PATCH] Avoid to subcontract a task if there are subcontractor progresses incompatible with receiving progress reporting from the provider FEA: ItEr75S31PreventingSubcontractorProgresses --- .../taskedition/TaskPropertiesController.java | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java index 63743d0cf..1a5f2c6a1 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/taskedition/TaskPropertiesController.java @@ -29,7 +29,13 @@ import java.util.Iterator; import java.util.List; import org.joda.time.LocalDate; +import org.libreplan.business.advance.bootstrap.PredefinedAdvancedTypes; +import org.libreplan.business.advance.entities.AdvanceType; +import org.libreplan.business.advance.entities.DirectAdvanceAssignment; +import org.libreplan.business.advance.exceptions.DuplicateAdvanceAssignmentForOrderElementException; +import org.libreplan.business.orders.daos.IOrderElementDAO; import org.libreplan.business.orders.entities.Order; +import org.libreplan.business.orders.entities.OrderElement; import org.libreplan.business.planner.entities.ITaskPositionConstrained; import org.libreplan.business.planner.entities.PositionConstraintType; import org.libreplan.business.planner.entities.Task; @@ -42,6 +48,7 @@ import org.libreplan.web.common.Util; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; +import org.springframework.transaction.annotation.Transactional; import org.zkoss.ganttz.TaskEditFormComposer; import org.zkoss.ganttz.TaskEditFormComposer.TaskDTO; import org.zkoss.ganttz.data.TaskContainer; @@ -158,6 +165,12 @@ public class TaskPropertiesController extends GenericForwardComposer { return topTask.getParent().getOrderElement().getOrder(); } + private OrderElement findOrderElementIn(IContextWithPlannerTask context) { + TaskElement topTask = context.getMapper().findAssociatedDomainObject( + findTopMostTask(context)); + return topTask.getOrderElement(); + } + private org.zkoss.ganttz.data.Task findTopMostTask( IContextWithPlannerTask context) { List parents = context.getMapper().getParents( @@ -316,9 +329,20 @@ public class TaskPropertiesController extends GenericForwardComposer { restoreOldState(); editTaskController.showNonPermitChangeResourceAllocationType(); } else { - changeResourceAllocationType(oldState, newState); - editTaskController.selectAssignmentTab(lbResourceAllocationType + if(newState.equals(ResourceAllocationTypeEnum.SUBCONTRACT) && checkCompatibleAllocation()){ + changeResourceAllocationType(oldState, newState); + editTaskController.selectAssignmentTab(lbResourceAllocationType .getSelectedIndex() + 1); + }else{ + try { + restoreOldState(); + Messagebox.show(_("This resource allocation type is incompatible. The task has an associated order element which has a progress that is of type subcontractor. "), + _("Error"), Messagebox.OK , Messagebox.ERROR); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } } if (oldState == null) { @@ -340,6 +364,30 @@ public class TaskPropertiesController extends GenericForwardComposer { } + private boolean checkCompatibleAllocation(){ + OrderElement orderElement = null; + AdvanceType advanceType = PredefinedAdvancedTypes.SUBCONTRACTOR.getType(); + + if (this.currentContext != null) { + orderElement = findOrderElementIn(this.currentContext ); + } else { + orderElement = this.currentTaskElement.getOrderElement(); + } + if(orderElement.getAdvanceAssignmentByType(advanceType) != null){ + return false; + } + try { + DirectAdvanceAssignment newAdvanceAssignment = DirectAdvanceAssignment + .create(); + newAdvanceAssignment.setAdvanceType(advanceType); + orderElement.checkAncestorsNoOtherAssignmentWithSameAdvanceType( + orderElement.getParent(), newAdvanceAssignment); + } catch (DuplicateAdvanceAssignmentForOrderElementException e) { + return false; + } + return true; + } + private boolean thereIsTransition(ResourceAllocationTypeEnum newState) { return getOldState() != null && !getOldState().equals(newState); } @@ -630,4 +678,5 @@ public class TaskPropertiesController extends GenericForwardComposer { .toDate(); Util.reloadBindings(startDateBox); } + }