Fix issue when moving a task with an assignment function.
Now assignment function is applied again in destination. For StretchesFunction a new method was needed in order to update stretches dates in destination. Actually, dates shouldn't be stored in Stretch class. This should be changed in the future. FEA: ItEr75S23FixAllocationModel
This commit is contained in:
parent
a893c303a4
commit
95d210b39b
3 changed files with 46 additions and 1 deletions
|
|
@ -23,6 +23,8 @@ package org.navalplanner.business.planner.entities;
|
|||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
|
||||
/**
|
||||
|
|
@ -36,6 +38,24 @@ public class AssignmentFunction extends BaseEntity {
|
|||
return create(new AssignmentFunction());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method goes over the {@link ResourceAllocation} list and apply the
|
||||
* assignment function if it is defined.
|
||||
*
|
||||
* @param resourceAllocations
|
||||
* List of {@link ResourceAllocation}
|
||||
*/
|
||||
public static void applyAssignmentFunctionsIfAny(
|
||||
List<ResourceAllocation<?>> resourceAllocations) {
|
||||
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
|
||||
AssignmentFunction assignmentFunction = resourceAllocation
|
||||
.getAssignmentFunction();
|
||||
if (assignmentFunction != null) {
|
||||
assignmentFunction.applyTo(resourceAllocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AssignmentFunction() {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import java.math.RoundingMode;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -375,6 +374,7 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
if (resourceAllocation.getFirstNonConsolidatedDate() == null) {
|
||||
return;
|
||||
}
|
||||
updateStretchesDates(resourceAllocation);
|
||||
taskEndDate = getTaskEndDate(resourceAllocation);
|
||||
getDesiredType().applyTo(resourceAllocation, this);
|
||||
type = getDesiredType();
|
||||
|
|
@ -453,4 +453,27 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
this.taskEndDate = taskEndDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Stretch} is storing date in an attribute. When a task is moved
|
||||
* these dates have to be updated.
|
||||
*
|
||||
* FIXME: Maybe in the future we could remove these dates as they could be
|
||||
* calculated from task information.
|
||||
*/
|
||||
private void updateStretchesDates(ResourceAllocation<?> resourceAllocation) {
|
||||
Task task = resourceAllocation.getTask();
|
||||
|
||||
long startDate = task.getStartDate().getTime();
|
||||
long endDate = task.getEndDate().getTime();
|
||||
|
||||
for (Stretch stretch : stretches) {
|
||||
// startDate + (percentage * (endDate - startDate))
|
||||
long stretchDate = startDate
|
||||
+ stretch.getLengthPercentage()
|
||||
.multiply(new BigDecimal(endDate - startDate))
|
||||
.longValue();
|
||||
stretch.setDate(new LocalDate(stretchDate));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -825,6 +825,8 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
|
|||
default:
|
||||
throw new RuntimeException("cant handle: " + calculatedValue);
|
||||
}
|
||||
|
||||
AssignmentFunction.applyAssignmentFunctionsIfAny(toBeModified);
|
||||
}
|
||||
|
||||
private void markAsUnsatisfied(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue