Avoid to subcontract a task if there are subcontractor progresses

incompatible with receiving progress reporting from the provider

FEA: ItEr75S31PreventingSubcontractorProgresses
This commit is contained in:
Susana Montes Pedreira 2011-11-23 17:32:32 +01:00
parent 47e6533022
commit ddb2862794

View file

@ -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<TaskElement> context) {
TaskElement topTask = context.getMapper().findAssociatedDomainObject(
findTopMostTask(context));
return topTask.getOrderElement();
}
private org.zkoss.ganttz.data.Task findTopMostTask(
IContextWithPlannerTask<TaskElement> context) {
List<? extends TaskContainer> 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);
}
}