From 2e26bc7c307b178d0987c1355f965adef0cfdc6e Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Fri, 28 Oct 2011 17:44:21 +0200 Subject: [PATCH] [Bug #1232] Fix problem in load chart filtering all assignments taking into account order resources The problem was that it was using all the assignments to calculate external load and overload. However, for capability line it was using just the resources assigned each day. Then I've added a new method to filter all the assignments taking into account the order resources assigned each day. FEA: ItEr75S04BugFixing --- .../web/planner/order/OrderPlanningModel.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/OrderPlanningModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/OrderPlanningModel.java index 55bbabae6..c4ea06937 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/OrderPlanningModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/order/OrderPlanningModel.java @@ -34,6 +34,7 @@ import java.util.Date; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -58,6 +59,7 @@ import org.libreplan.business.orders.entities.Order; import org.libreplan.business.orders.entities.OrderElement; import org.libreplan.business.orders.entities.OrderStatusEnum; 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.ICostCalculator; @@ -1143,17 +1145,19 @@ public class OrderPlanningModel implements IOrderPlanningModel { ContiguousDaysLine> orderAssignments = ContiguousDaysLine .byDay(orderDayAssignments); ContiguousDaysLine> allAssignments = allAssignments(orderAssignments); + ContiguousDaysLine> filteredAssignments = filterAllAssignmentsByOrderResources( + allAssignments, orderAssignments); ContiguousDaysLine maxCapacityOnResources = orderAssignments .transform(ResourceLoadChartData .extractAvailabilityOnAssignedResources()); ContiguousDaysLine orderLoad = orderAssignments .transform(ResourceLoadChartData.extractLoad()); - ContiguousDaysLine allLoad = allAssignments + ContiguousDaysLine allLoad = filteredAssignments .transform(ResourceLoadChartData.extractLoad()); ContiguousDaysLine orderOverload = orderAssignments .transform(ResourceLoadChartData.extractOverload()); - ContiguousDaysLine allOverload = allAssignments + ContiguousDaysLine allOverload = filteredAssignments .transform(ResourceLoadChartData.extractOverload()); Plotinfo plotOrderLoad = createPlotinfoFromDurations( @@ -1196,6 +1200,41 @@ public class OrderPlanningModel implements IOrderPlanningModel { plotMaxCapacity, plotOtherLoad, plotOrderLoad }; } + private ContiguousDaysLine> filterAllAssignmentsByOrderResources( + ContiguousDaysLine> allAssignments, + ContiguousDaysLine> orderAssignments) { + List filteredAssignments = new ArrayList(); + + Iterator>> iterator = orderAssignments + .iterator(); + while (iterator.hasNext()) { + ONDay> onDay = iterator.next(); + Set resources = getResources(onDay.getValue()); + filteredAssignments.addAll(filterAssignmentsByResource( + allAssignments.get(onDay.getDay()), resources)); + } + return ContiguousDaysLine.byDay(filteredAssignments); + } + + private List filterAssignmentsByResource( + List list, Set resources) { + List result = new ArrayList(); + for (DayAssignment each : list) { + if (resources.contains(each.getResource())) { + result.add(each); + } + } + return result; + } + + private Set getResources(List dayAssignments) { + Set resources = new HashSet(); + for (DayAssignment each : dayAssignments) { + resources.add(each.getResource()); + } + return resources; + } + private ContiguousDaysLine> allAssignments( ContiguousDaysLine> orderAssignments) { if (orderAssignments.isNotValid()) {