ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: Implementing apply action
This commit is contained in:
parent
474a326478
commit
112e9f0e8b
3 changed files with 81 additions and 10 deletions
|
|
@ -55,10 +55,14 @@ class FormBinder {
|
|||
public void setAssignedHoursComponent(Intbox assignedHoursComponent) {
|
||||
this.assignedHoursComponent = assignedHoursComponent;
|
||||
assignedHoursComponentDisabilityRule();
|
||||
this.assignedHoursComponent.setValue(aggregate.getTotalHours());
|
||||
loadValueForAssignedHoursComponent();
|
||||
onChangeEnableApply(assignedHoursComponent);
|
||||
}
|
||||
|
||||
private void loadValueForAssignedHoursComponent() {
|
||||
this.assignedHoursComponent.setValue(aggregate.getTotalHours());
|
||||
}
|
||||
|
||||
private void assignedHoursComponentDisabilityRule() {
|
||||
this.assignedHoursComponent.setDisabled(resourceAllocationsBeingEdited
|
||||
.getCalculatedValue() == CalculatedValue.NUMBER_OF_HOURS);
|
||||
|
|
@ -90,9 +94,13 @@ class FormBinder {
|
|||
public void setTaskStartDateBox(Datebox taskStartDateBox) {
|
||||
this.taskStartDateBox = taskStartDateBox;
|
||||
this.taskStartDateBox.setDisabled(true);
|
||||
loadValueForTaskStartDateBox();
|
||||
onChangeEnableApply(taskStartDateBox);
|
||||
}
|
||||
|
||||
private void loadValueForTaskStartDateBox() {
|
||||
this.taskStartDateBox.setValue(resourceAllocationsBeingEdited.getTask()
|
||||
.getStartDate());
|
||||
onChangeEnableApply(taskStartDateBox);
|
||||
}
|
||||
|
||||
private void onChangeEnableApply(InputElement inputElement) {
|
||||
|
|
@ -102,17 +110,28 @@ class FormBinder {
|
|||
public void setTaskElapsedDays(Intbox taskElapsedDays) {
|
||||
this.taskElapsedDays = taskElapsedDays;
|
||||
taskElapsedDaysDisabilityRule();
|
||||
this.taskElapsedDays.setValue(resourceAllocationsBeingEdited.getTask()
|
||||
.getDaysDuration());
|
||||
loadValuesForElapsedDays();
|
||||
onChangeEnableApply(taskElapsedDays);
|
||||
}
|
||||
|
||||
private void loadValuesForElapsedDays() {
|
||||
this.taskElapsedDays.setValue(resourceAllocationsBeingEdited
|
||||
.getDaysDuration());
|
||||
}
|
||||
|
||||
private void taskElapsedDaysDisabilityRule() {
|
||||
this.taskElapsedDays.setDisabled(true);
|
||||
}
|
||||
|
||||
private void doApply() {
|
||||
// TODO implement
|
||||
aggregate = resourceAllocationsBeingEdited.doAllocation();
|
||||
reloadValues();
|
||||
}
|
||||
|
||||
private void reloadValues() {
|
||||
loadValueForAssignedHoursComponent();
|
||||
loadValueForTaskStartDateBox();
|
||||
loadValuesForElapsedDays();
|
||||
}
|
||||
|
||||
public void setApplyButton(Button applyButton) {
|
||||
|
|
@ -134,4 +153,8 @@ class FormBinder {
|
|||
onChangeEnableApply(decimalbox);
|
||||
}
|
||||
|
||||
public int getAssignedHours() {
|
||||
return assignedHoursComponent.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,8 +130,8 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
List<AllocationDTO> currentAllocations = addDefaultGenericIfNeeded(AllocationDTO.toDTOs(this.task
|
||||
.getResourceAllocations()));
|
||||
resourceAllocationsBeingEdited = ResourceAllocationsBeingEdited
|
||||
.noTaskModifying(
|
||||
task, currentAllocations, resourceDAO);
|
||||
.noTaskModifying(task, currentAllocations, resourceDAO,
|
||||
reattachResources(getResourcesMatchingCriterions()));
|
||||
return resourceAllocationsBeingEdited;
|
||||
}
|
||||
|
||||
|
|
@ -172,9 +172,18 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
|
|||
criterionType.getName();
|
||||
}
|
||||
|
||||
private List<Resource> reattachResources(
|
||||
List<Resource> resourcesMatchingCriterions) {
|
||||
for (Resource resource : resourcesMatchingCriterions) {
|
||||
reattachResource(resource);
|
||||
}
|
||||
return resourcesMatchingCriterions;
|
||||
}
|
||||
|
||||
private void reattachResource(Resource resource) {
|
||||
resourceDAO.save(resource);
|
||||
reattachCriterionSatisfactions(resource.getCriterionSatisfactions());
|
||||
resource.getAssignments();
|
||||
}
|
||||
|
||||
private void reattachCriterionSatisfactions(
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ package org.navalplanner.web.planner.allocation;
|
|||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.Days;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
|
|
@ -21,9 +24,10 @@ import org.navalplanner.business.resources.entities.Worker;
|
|||
public class ResourceAllocationsBeingEdited {
|
||||
|
||||
public static ResourceAllocationsBeingEdited noTaskModifying(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO) {
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO,
|
||||
List<Resource> resourcesBeingEdited) {
|
||||
return new ResourceAllocationsBeingEdited(task, initialAllocations,
|
||||
resourceDAO, false);
|
||||
resourceDAO, resourcesBeingEdited, false);
|
||||
}
|
||||
|
||||
private final List<AllocationDTO> currentAllocations;
|
||||
|
|
@ -40,15 +44,22 @@ public class ResourceAllocationsBeingEdited {
|
|||
|
||||
private CalculatedValue calculatedValue;
|
||||
|
||||
private Integer daysDuration;
|
||||
|
||||
private final List<Resource> resourcesMatchingCriterions;
|
||||
|
||||
private ResourceAllocationsBeingEdited(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO,
|
||||
List<Resource> resourcesMatchingCriterions,
|
||||
boolean modifyTask) {
|
||||
this.task = task;
|
||||
this.resourceDAO = resourceDAO;
|
||||
this.resourcesMatchingCriterions = resourcesMatchingCriterions;
|
||||
this.modifyTask = modifyTask;
|
||||
this.currentAllocations = new ArrayList<AllocationDTO>(
|
||||
initialAllocations);
|
||||
this.calculatedValue = getCurrentCalculatedValue(task);
|
||||
this.daysDuration = task.getDaysDuration();
|
||||
}
|
||||
|
||||
private CalculatedValue getCurrentCalculatedValue(Task task) {
|
||||
|
|
@ -101,6 +112,30 @@ public class ResourceAllocationsBeingEdited {
|
|||
return result;
|
||||
}
|
||||
|
||||
public AggregateOfResourceAllocations doAllocation() {
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> allocations = asResourceAllocations();
|
||||
switch (calculatedValue) {
|
||||
case NUMBER_OF_HOURS:
|
||||
ResourceAllocation.allocating(allocations).withResources(
|
||||
resourcesMatchingCriterions).allocateOnTaskLength();
|
||||
break;
|
||||
case END_DATE:
|
||||
LocalDate end = ResourceAllocation.allocating(allocations)
|
||||
.withResources(resourcesMatchingCriterions)
|
||||
.untilAllocating(formBinder.getAssignedHours());
|
||||
daysDuration = from(task.getStartDate(), end);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("cant handle: " + calculatedValue);
|
||||
}
|
||||
return new AggregateOfResourceAllocations(stripResourcesPerDay(allocations));
|
||||
}
|
||||
|
||||
private Integer from(Date startDate, LocalDate end) {
|
||||
LocalDate start = new LocalDate(startDate.getTime());
|
||||
return Days.daysBetween(start, end).getDays();
|
||||
}
|
||||
|
||||
private List<ResourceAllocation<?>> stripResourcesPerDay(
|
||||
List<ResourceAllocationWithDesiredResourcesPerDay> withResourcesPerDay) {
|
||||
List<ResourceAllocation<?>> result = new ArrayList<ResourceAllocation<?>>();
|
||||
|
|
@ -154,7 +189,7 @@ public class ResourceAllocationsBeingEdited {
|
|||
|
||||
public ResourceAllocationsBeingEdited taskModifying() {
|
||||
return new ResourceAllocationsBeingEdited(task, currentAllocations,
|
||||
resourceDAO, true);
|
||||
resourceDAO, resourcesMatchingCriterions, true);
|
||||
}
|
||||
|
||||
public FormBinder createFormBinder() {
|
||||
|
|
@ -181,4 +216,8 @@ public class ResourceAllocationsBeingEdited {
|
|||
return task;
|
||||
}
|
||||
|
||||
public Integer getDaysDuration() {
|
||||
return daysDuration;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue