ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: Connecting form binder and ResourceAllocationsBeingEdited
This commit is contained in:
parent
9509482cf1
commit
1b44fdcce6
4 changed files with 84 additions and 40 deletions
|
|
@ -88,8 +88,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
allocationsBeingEdited = resourceAllocationModel.initAllocationsFor(
|
||||
task, ganttTask,
|
||||
planningState);
|
||||
formBinder = new ResourceAllocationFormBinder(
|
||||
getCurrentCalculatedValue(task), resourceAllocationModel);
|
||||
formBinder = allocationsBeingEdited.createFormBinder();
|
||||
formBinder.setAssignedHoursComponent(assignedHoursComponent);
|
||||
Util.reloadBindings(window);
|
||||
try {
|
||||
|
|
@ -101,11 +100,6 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
private CalculatedValue getCurrentCalculatedValue(Task task) {
|
||||
// TODO retrieve the calculated value from task
|
||||
return CalculatedValue.NUMBER_OF_HOURS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows WorkerSearch window, add picked workers as
|
||||
* {@link SpecificResourceAllocation} to {@link ResourceAllocation} list
|
||||
|
|
|
|||
|
|
@ -1,29 +1,27 @@
|
|||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.zkoss.zul.Intbox;
|
||||
|
||||
public class ResourceAllocationFormBinder {
|
||||
|
||||
private CalculatedValue calculatedValue;
|
||||
private final IResourceAllocationModel resourceAllocationModel;
|
||||
private Intbox assignedHoursComponent;
|
||||
private final ResourceAllocationsBeingEdited resourceAllocationsBeingEdited;
|
||||
private AggregateOfResourceAllocations aggregate;
|
||||
|
||||
public ResourceAllocationFormBinder(CalculatedValue calculatedValue,
|
||||
IResourceAllocationModel resourceAllocationModel) {
|
||||
Validate.notNull(resourceAllocationModel);
|
||||
Validate.notNull(resourceAllocationModel);
|
||||
this.calculatedValue = calculatedValue;
|
||||
this.resourceAllocationModel = resourceAllocationModel;
|
||||
public ResourceAllocationFormBinder(
|
||||
ResourceAllocationsBeingEdited resourceAllocationsBeingEdited) {
|
||||
this.resourceAllocationsBeingEdited = resourceAllocationsBeingEdited;
|
||||
this.aggregate = this.resourceAllocationsBeingEdited
|
||||
.getInitialAggregate();
|
||||
}
|
||||
|
||||
public void setAssignedHoursComponent(Intbox assignedHoursComponent) {
|
||||
this.assignedHoursComponent = assignedHoursComponent;
|
||||
this.assignedHoursComponent
|
||||
.setDisabled(calculatedValue == CalculatedValue.NUMBER_OF_HOURS);
|
||||
this.assignedHoursComponent.setValue(resourceAllocationModel.getTask()
|
||||
.getAssignedHours());
|
||||
this.assignedHoursComponent.setDisabled(resourceAllocationsBeingEdited
|
||||
.getCalculatedValue() == CalculatedValue.NUMBER_OF_HOURS);
|
||||
this.assignedHoursComponent.setValue(aggregate.getTotalHours());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,8 +95,10 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
}
|
||||
|
||||
private void mergeDTOsToTask() {
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> resourceAllocations = resourceAllocationsBeingEdited
|
||||
.asResourceAllocationsFor(task);
|
||||
ResourceAllocationsBeingEdited taskModifying = resourceAllocationsBeingEdited
|
||||
.taskModifying();
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> resourceAllocations = taskModifying
|
||||
.asResourceAllocations();
|
||||
if (task.isFixedDuration()) {
|
||||
ResourceAllocation.allocating(resourceAllocations).withResources(
|
||||
getResourcesMatchingCriterions()).allocateOnTaskLength();
|
||||
|
|
@ -127,8 +129,9 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
reattachCriterions(this.task.getHoursGroup().getCriterions());
|
||||
List<AllocationDTO> currentAllocations = addDefaultGenericIfNeeded(AllocationDTO.toDTOs(this.task
|
||||
.getResourceAllocations()));
|
||||
resourceAllocationsBeingEdited = new ResourceAllocationsBeingEdited(
|
||||
currentAllocations, resourceDAO);
|
||||
resourceAllocationsBeingEdited = ResourceAllocationsBeingEdited
|
||||
.noTaskModifying(
|
||||
task, currentAllocations, resourceDAO);
|
||||
return resourceAllocationsBeingEdited;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +139,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
Set<ResourceAllocation<?>> resourceAllocations) {
|
||||
resourceAllocations.size();
|
||||
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
|
||||
resourceAllocation.getResourcesPerDay();
|
||||
resourceAllocation.getAssignments();
|
||||
if (resourceAllocation instanceof SpecificResourceAllocation) {
|
||||
reattachSpecificResourceAllocation((SpecificResourceAllocation) resourceAllocation);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
|
|
@ -18,15 +20,30 @@ import org.navalplanner.business.resources.entities.Worker;
|
|||
|
||||
public class ResourceAllocationsBeingEdited {
|
||||
|
||||
public static ResourceAllocationsBeingEdited noTaskModifying(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO) {
|
||||
return new ResourceAllocationsBeingEdited(task, initialAllocations,
|
||||
resourceDAO, false);
|
||||
}
|
||||
|
||||
private final List<AllocationDTO> currentAllocations;
|
||||
|
||||
private final Set<ResourceAllocation<?>> requestedToRemove = new HashSet<ResourceAllocation<?>>();
|
||||
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
public ResourceAllocationsBeingEdited(
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO) {
|
||||
private final Task task;
|
||||
|
||||
private final boolean modifyTask;
|
||||
|
||||
private ResourceAllocationFormBinder formBinder = null;
|
||||
|
||||
private ResourceAllocationsBeingEdited(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO,
|
||||
boolean modifyTask) {
|
||||
this.task = task;
|
||||
this.resourceDAO = resourceDAO;
|
||||
this.modifyTask = modifyTask;
|
||||
this.currentAllocations = new ArrayList<AllocationDTO>(
|
||||
initialAllocations);
|
||||
}
|
||||
|
|
@ -67,24 +84,32 @@ public class ResourceAllocationsBeingEdited {
|
|||
return requestedToRemove;
|
||||
}
|
||||
|
||||
public List<ResourceAllocationWithDesiredResourcesPerDay> asResourceAllocationsFor(
|
||||
Task task) {
|
||||
public List<ResourceAllocationWithDesiredResourcesPerDay> asResourceAllocations() {
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> result = new ArrayList<ResourceAllocationWithDesiredResourcesPerDay>();
|
||||
for (AllocationDTO allocation : currentAllocations) {
|
||||
result
|
||||
.add(createOrModify(allocation, task)
|
||||
.withDesiredResourcesPerDay(
|
||||
result.add(createOrModify(allocation).withDesiredResourcesPerDay(
|
||||
allocation.getResourcesPerDay()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ResourceAllocation<?> createOrModify(AllocationDTO allocation,
|
||||
Task task) {
|
||||
private List<ResourceAllocation<?>> stripResourcesPerDay(
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> withResourcesPerDay) {
|
||||
List<ResourceAllocation<?>> result = new ArrayList<ResourceAllocation<?>>();
|
||||
for (ResourceAllocationWithDesiredResourcesPerDay r : withResourcesPerDay) {
|
||||
result.add(r.getResourceAllocation());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ResourceAllocation<?> createOrModify(AllocationDTO allocation) {
|
||||
if (!modifyTask) {
|
||||
return createAllocation(allocation);
|
||||
}
|
||||
if (allocation.isModifying()) {
|
||||
return reloadResourceIfNeeded(allocation.getOrigin());
|
||||
} else {
|
||||
ResourceAllocation<?> result = createAllocation(allocation, task);
|
||||
ResourceAllocation<?> result = createAllocation(allocation);
|
||||
task.addResourceAllocation(result);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -103,22 +128,46 @@ public class ResourceAllocationsBeingEdited {
|
|||
return resourceDAO.findExistingEntity(resource.getId());
|
||||
}
|
||||
|
||||
private ResourceAllocation<?> createAllocation(AllocationDTO allocation,
|
||||
Task task) {
|
||||
private ResourceAllocation<?> createAllocation(AllocationDTO allocation) {
|
||||
if (allocation instanceof SpecificAllocationDTO) {
|
||||
SpecificAllocationDTO specific = (SpecificAllocationDTO) allocation;
|
||||
return createSpecific(specific.getResource(), task);
|
||||
return createSpecific(specific.getResource());
|
||||
} else {
|
||||
return GenericResourceAllocation.create(task);
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceAllocation<?> createSpecific(Resource resource, Task task) {
|
||||
resource = getFromDB(resource);
|
||||
private ResourceAllocation<?> createSpecific(Resource resource) {
|
||||
SpecificResourceAllocation result = SpecificResourceAllocation
|
||||
.create(task);
|
||||
result.setResource(resource);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResourceAllocationsBeingEdited taskModifying() {
|
||||
return new ResourceAllocationsBeingEdited(task, currentAllocations,
|
||||
resourceDAO, true);
|
||||
}
|
||||
|
||||
public ResourceAllocationFormBinder createFormBinder() {
|
||||
if (formBinder != null)
|
||||
throw new IllegalStateException(
|
||||
"there is already a binder associated with this object");
|
||||
formBinder = new ResourceAllocationFormBinder(this);
|
||||
return formBinder;
|
||||
}
|
||||
|
||||
private CalculatedValue getCurrentCalculatedValue(Task task) {
|
||||
// TODO retrieve the calculated value from task
|
||||
return CalculatedValue.NUMBER_OF_HOURS;
|
||||
}
|
||||
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return getCurrentCalculatedValue(task);
|
||||
}
|
||||
|
||||
public AggregateOfResourceAllocations getInitialAggregate() {
|
||||
return new AggregateOfResourceAllocations(task.getResourceAllocations());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue