diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java index 81aaa5209..ff1a26a49 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationDTO.java @@ -65,4 +65,12 @@ public abstract class AllocationDTO { public abstract boolean isGeneric(); + public static List toDTOs( + Collection> resourceAllocations) { + List result = new ArrayList(); + result.addAll(GenericAllocationDTO.toGenericAllocations(resourceAllocations)); + result.addAll(SpecificAllocationDTO.toSpecificAllocations(resourceAllocations)); + return result; + } + } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java index 6bb9d3ece..c89a27652 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationDTO.java @@ -2,7 +2,11 @@ package org.navalplanner.web.planner.allocation; import static org.navalplanner.web.I18nHelper._; +import java.util.ArrayList; +import java.util.Collection; + import org.navalplanner.business.planner.entities.GenericResourceAllocation; +import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.ResourcesPerDay; /** @@ -30,4 +34,15 @@ public class GenericAllocationDTO extends AllocationDTO { public boolean isGeneric() { return true; } + + public static Collection toGenericAllocations( + Collection> resourceAllocations) { + ArrayList result = new ArrayList(); + for (ResourceAllocation resourceAllocation : resourceAllocations) { + if (resourceAllocation instanceof GenericResourceAllocation) { + result.add(from((GenericResourceAllocation) resourceAllocation)); + } + } + return result; + } } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java index df8a1e54e..664fbbb0d 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java @@ -1,7 +1,6 @@ package org.navalplanner.web.planner.allocation; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -12,7 +11,6 @@ import org.navalplanner.business.orders.daos.IHoursGroupDAO; import org.navalplanner.business.orders.entities.HoursGroup; import org.navalplanner.business.planner.daos.IResourceAllocationDAO; import org.navalplanner.business.planner.daos.ITaskElementDAO; -import org.navalplanner.business.planner.entities.GenericResourceAllocation; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.planner.entities.Task; @@ -142,7 +140,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel { hoursGroupDAO.save(this.task.getHoursGroup()); reattachHoursGroup(this.task.getHoursGroup()); reattachCriterions(this.task.getHoursGroup().getCriterions()); - List currentAllocations = addDefaultGenericIfNeeded(asDTOs(this.task + List currentAllocations = addDefaultGenericIfNeeded(AllocationDTO.toDTOs(this.task .getResourceAllocations())); resourceAllocationsBeingEdited = new ResourceAllocationsBeingEdited( currentAllocations, resourceDAO); @@ -211,36 +209,4 @@ public class ResourceAllocationModel implements IResourceAllocationModel { return dtos; } - private List asDTOs( - Collection> resourceAllocations) { - List result = new ArrayList(); - result.addAll(toGenericAllocations(resourceAllocations)); - result.addAll(toSpecificAllocations(resourceAllocations)); - return result; - } - - private List toSpecificAllocations( - Collection> resourceAllocations) { - List result = new ArrayList(); - for (ResourceAllocation resourceAllocation : resourceAllocations) { - if (resourceAllocation instanceof SpecificResourceAllocation) { - SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation; - result.add(SpecificAllocationDTO.from(specific)); - } - } - return result; - } - - private Collection toGenericAllocations( - Collection> resourceAllocations) { - ArrayList result = new ArrayList(); - for (ResourceAllocation resourceAllocation : resourceAllocations) { - if (resourceAllocation instanceof GenericResourceAllocation) { - result.add(GenericAllocationDTO - .from((GenericResourceAllocation) resourceAllocation)); - } - } - return result; - } - } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java index b702427bf..4ca958155 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationDTO.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.ResourcesPerDay; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.resources.entities.Resource; @@ -75,4 +76,16 @@ public class SpecificAllocationDTO extends AllocationDTO { return false; } + public static List toSpecificAllocations( + Collection> resourceAllocations) { + List result = new ArrayList(); + for (ResourceAllocation resourceAllocation : resourceAllocations) { + if (resourceAllocation instanceof SpecificResourceAllocation) { + SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation; + result.add(from(specific)); + } + } + return result; + } + }