ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: Moving methods for creating DTOs from ResourceAllocation to the DTO objects

This commit is contained in:
Óscar González Fernández 2009-09-22 14:39:27 +02:00
parent bf0cee74f3
commit 768f92e8f3
4 changed files with 37 additions and 35 deletions

View file

@ -65,4 +65,12 @@ public abstract class AllocationDTO {
public abstract boolean isGeneric();
public static List<AllocationDTO> toDTOs(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
List<AllocationDTO> result = new ArrayList<AllocationDTO>();
result.addAll(GenericAllocationDTO.toGenericAllocations(resourceAllocations));
result.addAll(SpecificAllocationDTO.toSpecificAllocations(resourceAllocations));
return result;
}
}

View file

@ -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<GenericAllocationDTO> toGenericAllocations(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
ArrayList<GenericAllocationDTO> result = new ArrayList<GenericAllocationDTO>();
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
if (resourceAllocation instanceof GenericResourceAllocation) {
result.add(from((GenericResourceAllocation) resourceAllocation));
}
}
return result;
}
}

View file

@ -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<AllocationDTO> currentAllocations = addDefaultGenericIfNeeded(asDTOs(this.task
List<AllocationDTO> 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<AllocationDTO> asDTOs(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
List<AllocationDTO> result = new ArrayList<AllocationDTO>();
result.addAll(toGenericAllocations(resourceAllocations));
result.addAll(toSpecificAllocations(resourceAllocations));
return result;
}
private List<SpecificAllocationDTO> toSpecificAllocations(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
List<SpecificAllocationDTO> result = new ArrayList<SpecificAllocationDTO>();
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
if (resourceAllocation instanceof SpecificResourceAllocation) {
SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation;
result.add(SpecificAllocationDTO.from(specific));
}
}
return result;
}
private Collection<GenericAllocationDTO> toGenericAllocations(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
ArrayList<GenericAllocationDTO> result = new ArrayList<GenericAllocationDTO>();
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
if (resourceAllocation instanceof GenericResourceAllocation) {
result.add(GenericAllocationDTO
.from((GenericResourceAllocation) resourceAllocation));
}
}
return result;
}
}

View file

@ -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<SpecificAllocationDTO> toSpecificAllocations(
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
List<SpecificAllocationDTO> result = new ArrayList<SpecificAllocationDTO>();
for (ResourceAllocation<?> resourceAllocation : resourceAllocations) {
if (resourceAllocation instanceof SpecificResourceAllocation) {
SpecificResourceAllocation specific = (SpecificResourceAllocation) resourceAllocation;
result.add(from(specific));
}
}
return result;
}
}