Allow to include or exclude DerivedDayAssignments
It's now possible to specify if derived assignments are included or not when retrieving day assignments from a Task, Order and so on.
This commit is contained in:
parent
856eab4a79
commit
825bae5f2b
10 changed files with 67 additions and 17 deletions
|
|
@ -44,6 +44,7 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
|||
import org.libreplan.business.externalcompanies.entities.ExternalCompany;
|
||||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.planner.entities.TaskGroup;
|
||||
|
|
@ -348,22 +349,23 @@ public class Order extends OrderLineGroup implements Comparable {
|
|||
return true;
|
||||
}
|
||||
|
||||
public List<DayAssignment> getDayAssignments() {
|
||||
public List<DayAssignment> getDayAssignments(FilterType filter) {
|
||||
List<DayAssignment> dayAssignments = new ArrayList<DayAssignment>();
|
||||
for (OrderElement orderElement : getAllOrderElements()) {
|
||||
Set<TaskElement> taskElements = orderElement.getTaskElements();
|
||||
for (TaskElement taskElement : taskElements) {
|
||||
if (taskElement instanceof Task) {
|
||||
dayAssignments.addAll(taskElement.getDayAssignments());
|
||||
dayAssignments
|
||||
.addAll(taskElement.getDayAssignments(filter));
|
||||
}
|
||||
}
|
||||
}
|
||||
return dayAssignments;
|
||||
return DayAssignment.filter(dayAssignments, filter);
|
||||
}
|
||||
|
||||
public Set<Resource> getResources() {
|
||||
public Set<Resource> getResources(FilterType filter) {
|
||||
Set<Resource> resources = new HashSet<Resource>();
|
||||
for (DayAssignment dayAssignment : getDayAssignments()) {
|
||||
for (DayAssignment dayAssignment : getDayAssignments(filter)) {
|
||||
resources.add(dayAssignment.getResource());
|
||||
}
|
||||
return resources;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,38 @@ import org.libreplan.business.workingday.EffortDuration;
|
|||
|
||||
public abstract class DayAssignment extends BaseEntity {
|
||||
|
||||
public enum FilterType {
|
||||
KEEP_ALL {
|
||||
@Override
|
||||
public boolean accepts(DayAssignment each) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
WITHOUT_DERIVED {
|
||||
@Override
|
||||
public boolean accepts(DayAssignment each) {
|
||||
return !(each instanceof DerivedDayAssignment);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean accepts(DayAssignment each);
|
||||
}
|
||||
|
||||
public static List<DayAssignment> filter(
|
||||
Collection<? extends DayAssignment> assignments,
|
||||
FilterType filter) {
|
||||
if (filter == null || filter.equals(FilterType.KEEP_ALL)) {
|
||||
return new ArrayList<DayAssignment>(assignments);
|
||||
}
|
||||
List<DayAssignment> result = new ArrayList<DayAssignment>();
|
||||
for (DayAssignment each : assignments) {
|
||||
if (filter.accepts(each)) {
|
||||
result.add(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T extends DayAssignment> List<T> getAtInterval(
|
||||
List<T> orderedAssignments, LocalDate startInclusive,
|
||||
LocalDate endExclusive) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.TreeMap;
|
|||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.advance.entities.AdvanceMeasurement;
|
||||
import org.libreplan.business.advance.entities.DirectAdvanceAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportLineDAO;
|
||||
import org.libreplan.business.workreports.entities.WorkReportLine;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -106,8 +107,8 @@ public class HoursCostCalculator implements ICostCalculator {
|
|||
|
||||
SortedMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
|
||||
|
||||
List<DayAssignment> dayAssignments = task.getDayAssignments();
|
||||
|
||||
List<DayAssignment> dayAssignments = task
|
||||
.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
if (dayAssignments.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -548,13 +548,18 @@ public abstract class TaskElement extends BaseEntity {
|
|||
result.put(date, current.plus(duration));
|
||||
}
|
||||
|
||||
public List<DayAssignment> getDayAssignments() {
|
||||
public List<DayAssignment> getDayAssignments(DayAssignment.FilterType filter) {
|
||||
List<DayAssignment> dayAssignments = new ArrayList<DayAssignment>();
|
||||
Set<ResourceAllocation<?>> resourceAllocations = getSatisfiedResourceAllocations();
|
||||
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
|
||||
dayAssignments.addAll(resourceAllocation.getAssignments());
|
||||
Set<DerivedAllocation> derivedAllocations = resourceAllocation
|
||||
.getDerivedAllocations();
|
||||
for (DerivedAllocation each : derivedAllocations) {
|
||||
dayAssignments.addAll(each.getAssignments());
|
||||
}
|
||||
}
|
||||
return dayAssignments;
|
||||
return DayAssignment.filter(dayAssignments, filter);
|
||||
}
|
||||
|
||||
public boolean isSubcontracted() {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportLineDAO;
|
||||
|
|
@ -74,7 +75,7 @@ public class CompletedEstimatedHoursPerTaskDTO {
|
|||
public Integer calculatePlannedHours(Task task, LocalDate date) {
|
||||
Integer result = new Integer(0);
|
||||
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments();
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
if (dayAssignments.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.libreplan.business.common.Registry;
|
|||
import org.libreplan.business.orders.daos.IOrderDAO;
|
||||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportLineDAO;
|
||||
|
|
@ -177,7 +178,8 @@ realHours
|
|||
}
|
||||
|
||||
public Integer calculatePlannedHours(Task task, LocalDate date) {
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments();
|
||||
final List<DayAssignment> dayAssignments = task
|
||||
.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
return DayAssignment.sum(removeAfterDate(dayAssignments, date))
|
||||
.roundToHours();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.libreplan.business.common.Registry;
|
|||
import org.libreplan.business.orders.entities.Order;
|
||||
import org.libreplan.business.orders.entities.OrderElement;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
|
|
@ -185,7 +186,7 @@ public class WorkingArrangementsPerOrderDTO {
|
|||
}
|
||||
|
||||
public Integer calculatePlannedHours(Task task, final LocalDate date) {
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments();
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
return DayAssignment.sum(removeAfterDate(dayAssignments, date))
|
||||
.roundToHours();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import org.joda.time.LocalDate;
|
||||
import org.libreplan.business.common.Registry;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.workingday.EffortDuration;
|
||||
import org.libreplan.business.workreports.daos.IWorkReportLineDAO;
|
||||
|
|
@ -109,7 +110,7 @@ realHours
|
|||
public Integer calculatePlannedHours(Task task, LocalDate date) {
|
||||
Integer result = new Integer(0);
|
||||
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments();
|
||||
final List<DayAssignment> dayAssignments = task.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
if (dayAssignments.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import org.libreplan.business.planner.chart.ContiguousDaysLine;
|
|||
import org.libreplan.business.planner.chart.ContiguousDaysLine.OnDay;
|
||||
import org.libreplan.business.planner.chart.ResourceLoadChartData;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.ICostCalculator;
|
||||
import org.libreplan.business.planner.entities.Task;
|
||||
import org.libreplan.business.planner.entities.TaskElement;
|
||||
|
|
@ -1141,7 +1142,8 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
|
||||
@Override
|
||||
protected Plotinfo[] getPlotInfos(Interval interval) {
|
||||
List<DayAssignment> orderDayAssignments = order.getDayAssignments();
|
||||
List<DayAssignment> orderDayAssignments = order
|
||||
.getDayAssignments(FilterType.WITHOUT_DERIVED);
|
||||
ContiguousDaysLine<List<DayAssignment>> orderAssignments = ContiguousDaysLine
|
||||
.byDay(orderDayAssignments);
|
||||
ContiguousDaysLine<List<DayAssignment>> allAssignments = allAssignments(orderAssignments);
|
||||
|
|
@ -1249,7 +1251,8 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
AvailabilityTimeLine.Interval interval = AvailabilityTimeLine.Interval
|
||||
.create(startInclusive, endExclusive);
|
||||
List<DayAssignment> resourcesDayAssignments = new ArrayList<DayAssignment>();
|
||||
for (Resource resource : order.getResources()) {
|
||||
for (Resource resource : order
|
||||
.getResources(FilterType.WITHOUT_DERIVED)) {
|
||||
resourcesDayAssignments.addAll(insideInterval(interval,
|
||||
planningState.getAssignmentsCalculator()
|
||||
.getAssignments(resource)));
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.libreplan.business.planner.daos.ITaskElementDAO;
|
|||
import org.libreplan.business.planner.daos.ITaskSourceDAO;
|
||||
import org.libreplan.business.planner.entities.AssignmentFunction;
|
||||
import org.libreplan.business.planner.entities.DayAssignment;
|
||||
import org.libreplan.business.planner.entities.DayAssignment.FilterType;
|
||||
import org.libreplan.business.planner.entities.Dependency;
|
||||
import org.libreplan.business.planner.entities.DerivedAllocation;
|
||||
import org.libreplan.business.planner.entities.GenericResourceAllocation;
|
||||
|
|
@ -259,7 +260,8 @@ public class PlanningStateCreator {
|
|||
TaskGroup rootTask = orderReloaded.getAssociatedTaskElement();
|
||||
if (rootTask != null) {
|
||||
forceLoadOf(rootTask);
|
||||
forceLoadDayAssignments(orderReloaded.getResources());
|
||||
forceLoadDayAssignments(orderReloaded
|
||||
.getResources(FilterType.WITHOUT_DERIVED));
|
||||
forceLoadOfDepedenciesCollections(rootTask);
|
||||
forceLoadOfLabels(Arrays.asList((TaskElement) rootTask));
|
||||
}
|
||||
|
|
@ -396,7 +398,7 @@ public class PlanningStateCreator {
|
|||
return new UsingOwnerScenario(currentScenario, orderReloaded);
|
||||
}
|
||||
final List<DayAssignment> previousAssignments = orderReloaded
|
||||
.getDayAssignments();
|
||||
.getDayAssignments(DayAssignment.FilterType.KEEP_ALL);
|
||||
|
||||
OrderVersion newVersion = OrderVersion
|
||||
.createInitialVersion(currentScenario);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue