ItEr26S07CUAsignacionGrupoRecursosAPlanificacionItEr25S07: Adding utility methods to DTOs
This commit is contained in:
parent
a036ba240a
commit
08a75008d8
3 changed files with 77 additions and 1 deletions
|
|
@ -1,6 +1,9 @@
|
|||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
|
||||
|
|
@ -11,6 +14,17 @@ import org.navalplanner.business.planner.entities.ResourceAllocation;
|
|||
*/
|
||||
public abstract class AllocationDTO {
|
||||
|
||||
public static List<GenericAllocationDTO> getGeneric(
|
||||
Collection<? extends AllocationDTO> all) {
|
||||
List<GenericAllocationDTO> result = new ArrayList<GenericAllocationDTO>();
|
||||
for (AllocationDTO dto : all) {
|
||||
if (dto.isGeneric()) {
|
||||
result.add((GenericAllocationDTO) dto);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private BigDecimal percentage;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
|
||||
/**
|
||||
|
|
@ -8,9 +10,21 @@ import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
|||
*/
|
||||
public class GenericAllocationDTO extends AllocationDTO {
|
||||
|
||||
public static GenericAllocationDTO createDefault() {
|
||||
GenericAllocationDTO result = new GenericAllocationDTO();
|
||||
result.setName(_("Generic"));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GenericAllocationDTO from(
|
||||
GenericResourceAllocation resourceAllocation) {
|
||||
GenericAllocationDTO result = createDefault();
|
||||
result.setPercentage(resourceAllocation.getPercentage());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGeneric() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
package org.navalplanner.web.planner.allocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
* The information required for creating a {@link SpecificResourceAllocation}
|
||||
|
|
@ -9,6 +14,49 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
*/
|
||||
public class SpecificAllocationDTO extends AllocationDTO {
|
||||
|
||||
public static List<SpecificAllocationDTO> withResource(
|
||||
List<SpecificAllocationDTO> specific, Worker worker) {
|
||||
List<SpecificAllocationDTO> result = new ArrayList<SpecificAllocationDTO>();
|
||||
for (SpecificAllocationDTO specificAllocationDTO : specific) {
|
||||
if (areEquals(specificAllocationDTO.getResource(), worker)) {
|
||||
result.add(specificAllocationDTO);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean areEquals(Resource one, Resource other) {
|
||||
if (one == other)
|
||||
return true;
|
||||
if (one == null || other == null)
|
||||
return false;
|
||||
return one.equals(other);
|
||||
}
|
||||
|
||||
public static List<SpecificAllocationDTO> getSpecific(
|
||||
Collection<? extends AllocationDTO> currentAllocations) {
|
||||
List<SpecificAllocationDTO> result = new ArrayList<SpecificAllocationDTO>();
|
||||
for (AllocationDTO allocationDTO : currentAllocations) {
|
||||
if (allocationDTO instanceof SpecificAllocationDTO) {
|
||||
result.add((SpecificAllocationDTO) allocationDTO);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SpecificAllocationDTO from(SpecificResourceAllocation specific) {
|
||||
SpecificAllocationDTO result = forResource(specific.getWorker());
|
||||
result.setPercentage(specific.getPercentage());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SpecificAllocationDTO forResource(Worker worker) {
|
||||
SpecificAllocationDTO result = new SpecificAllocationDTO();
|
||||
result.setName(worker.getName());
|
||||
result.setResource(worker);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Resource resource;
|
||||
|
||||
public Resource getResource() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue