From e93f59c1bfa581df79b82227a0653f7340a8d3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Tue, 1 Dec 2009 23:36:09 +0100 Subject: [PATCH] ItEr37S08CUCreacionUnidadesPlanificacionItEr36S11: Adding new factory method to create an AllocationResult from a list of AllocationRow --- .../planner/allocation/AllocationResult.java | 19 ++++++++++++++ .../web/planner/allocation/AllocationRow.java | 25 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java index 7a94a8cf4..ab6242438 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationResult.java @@ -92,6 +92,25 @@ public class AllocationResult { calculateNew(translation), calculateModified(translation)); } + public static AllocationResult create(Task task, + CalculatedValue calculatedValue, List rows) { + List> newAllocations = AllocationRow + .getNewFrom(rows); + List modified = AllocationRow.getModifiedFrom(rows); + return new AllocationResult(task, calculatedValue, createAggregate( + newAllocations, modified), + newAllocations, modified); + } + + private static AggregateOfResourceAllocations createAggregate( + List> newAllocations, + List modified) { + List> all = new ArrayList>(); + all.addAll(newAllocations); + all.addAll(ModifiedAllocation.modified(modified)); + return new AggregateOfResourceAllocations(all); + } + public static AllocationResult createCurrent(Task task) { Set> resourceAllocations = task .getResourceAllocations(); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java index 881f6e389..32b758882 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java @@ -30,6 +30,7 @@ import org.navalplanner.business.planner.entities.CalculatedValue; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.ResourcesPerDay; import org.navalplanner.business.planner.entities.Task; +import org.navalplanner.business.planner.entities.Task.ModifiedAllocation; import org.navalplanner.business.planner.entities.allocationalgorithms.ResourcesPerDayModification; import org.navalplanner.business.resources.entities.Resource; import org.navalplanner.web.common.Util; @@ -46,6 +47,30 @@ import org.zkoss.zul.SimpleConstraint; */ public abstract class AllocationRow { + public static List getModifiedFrom( + Collection rows) { + List result = new ArrayList(); + for (AllocationRow each : rows) { + Validate.notNull(each.last); + if (each.origin != null) { + result.add(new ModifiedAllocation(each.origin, each.last)); + } + } + return result; + } + + public static List> getNewFrom( + List rows) { + List> result = new ArrayList>(); + for (AllocationRow each : rows) { + Validate.notNull(each.last); + if (each.origin == null) { + result.add(each.last); + } + } + return result; + } + public static List getGeneric( Collection all) { List result = new ArrayList();