ItEr29S06CUAsignacionGrupoRecursosAPlanificacionItEr28S06: Moving AllocationResult to top level

This commit is contained in:
Óscar González Fernández 2009-10-06 23:24:18 +02:00
parent 9c9b54de22
commit bd5fd66242
2 changed files with 116 additions and 81 deletions

View file

@ -0,0 +1,115 @@
/*
* This file is part of ###PROJECT_NAME###
*
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
* Desenvolvemento Tecnolóxico de Galicia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.navalplanner.web.planner.allocation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang.Validate;
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
import org.navalplanner.business.planner.entities.CalculatedValue;
import org.navalplanner.business.planner.entities.ResourceAllocation;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.Task.ModifiedAllocation;
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourceAllocationWithDesiredResourcesPerDay;
/**
* @author Óscar González Fernández <ogonzalez@igalia.com>
*
*/
public class AllocationResult {
private static Map<ResourceAllocation<?>, ResourceAllocation<?>> translation(
Map<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> fromDetachedToAttached) {
Map<ResourceAllocation<?>, ResourceAllocation<?>> result = new HashMap<ResourceAllocation<?>, ResourceAllocation<?>>();
for (Entry<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> entry : fromDetachedToAttached
.entrySet()) {
result
.put(entry.getKey().getResourceAllocation(), entry
.getValue());
}
return result;
}
private final AggregateOfResourceAllocations aggregate;
private final Integer daysDuration;
private final Map<ResourceAllocation<?>, ResourceAllocation<?>> fromDetachedAllocationToAttached;
private final CalculatedValue calculatedValue;
AllocationResult(
CalculatedValue calculatedValue,
AggregateOfResourceAllocations aggregate,
Integer daysDuration,
Map<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> fromDetachedAllocationToAttached) {
Validate.notNull(daysDuration);
Validate.notNull(aggregate);
Validate.notNull(calculatedValue);
this.calculatedValue = calculatedValue;
this.aggregate = aggregate;
this.daysDuration = daysDuration;
this.fromDetachedAllocationToAttached = translation(fromDetachedAllocationToAttached);
}
public AggregateOfResourceAllocations getAggregate() {
return aggregate;
}
public Integer getDaysDuration() {
return daysDuration;
}
public List<ResourceAllocation<?>> getNew() {
List<ResourceAllocation<?>> result = new ArrayList<ResourceAllocation<?>>();
for (Entry<ResourceAllocation<?>, ResourceAllocation<?>> entry : fromDetachedAllocationToAttached
.entrySet()) {
if (entry.getValue() == null) {
result.add(entry.getKey());
}
}
return result;
}
public List<Task.ModifiedAllocation> getModified() {
List<ModifiedAllocation> result = new ArrayList<ModifiedAllocation>();
for (Entry<ResourceAllocation<?>, ResourceAllocation<?>> entry : fromDetachedAllocationToAttached
.entrySet()) {
if (entry.getValue() != null) {
result.add(new ModifiedAllocation(entry.getValue(), entry
.getKey()));
}
}
return result;
}
public CalculatedValue getCalculatedValue() {
return calculatedValue;
}
public void applyTo(Task task) {
task.mergeAllocation(getCalculatedValue(), getDaysDuration(), getNew(),
getModified());
}
}

View file

@ -31,7 +31,6 @@ import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.apache.commons.lang.Validate;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
@ -40,7 +39,6 @@ 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;
import org.navalplanner.business.planner.entities.Task.ModifiedAllocation;
import org.navalplanner.business.planner.entities.allocationalgorithms.ResourceAllocationWithDesiredResourcesPerDay;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.resources.entities.Resource;
@ -297,82 +295,4 @@ public class ResourceAllocationsBeingEdited {
return daysDuration;
}
}
class AllocationResult {
private static Map<ResourceAllocation<?>, ResourceAllocation<?>> translation(
Map<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> fromDetachedToAttached) {
Map<ResourceAllocation<?>, ResourceAllocation<?>> result = new HashMap<ResourceAllocation<?>, ResourceAllocation<?>>();
for (Entry<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> entry : fromDetachedToAttached
.entrySet()) {
result
.put(entry.getKey().getResourceAllocation(), entry
.getValue());
}
return result;
}
private final AggregateOfResourceAllocations aggregate;
private final Integer daysDuration;
private final Map<ResourceAllocation<?>, ResourceAllocation<?>> fromDetachedAllocationToAttached;
private final CalculatedValue calculatedValue;
AllocationResult(
CalculatedValue calculatedValue,
AggregateOfResourceAllocations aggregate,
Integer daysDuration,
Map<ResourceAllocationWithDesiredResourcesPerDay, ResourceAllocation<?>> fromDetachedAllocationToAttached) {
Validate.notNull(daysDuration);
Validate.notNull(aggregate);
Validate.notNull(calculatedValue);
this.calculatedValue = calculatedValue;
this.aggregate = aggregate;
this.daysDuration = daysDuration;
this.fromDetachedAllocationToAttached = translation(fromDetachedAllocationToAttached);
}
public AggregateOfResourceAllocations getAggregate() {
return aggregate;
}
public Integer getDaysDuration() {
return daysDuration;
}
public List<ResourceAllocation<?>> getNew() {
List<ResourceAllocation<?>> result = new ArrayList<ResourceAllocation<?>>();
for (Entry<ResourceAllocation<?>, ResourceAllocation<?>> entry : fromDetachedAllocationToAttached
.entrySet()) {
if (entry.getValue() == null) {
result.add(entry.getKey());
}
}
return result;
}
public List<Task.ModifiedAllocation> getModified() {
List<ModifiedAllocation> result = new ArrayList<ModifiedAllocation>();
for (Entry<ResourceAllocation<?>, ResourceAllocation<?>> entry : fromDetachedAllocationToAttached
.entrySet()) {
if (entry.getValue() != null) {
result.add(new ModifiedAllocation(entry.getValue(), entry
.getKey()));
}
}
return result;
}
public CalculatedValue getCalculatedValue() {
return calculatedValue;
}
public void applyTo(Task task) {
task.mergeAllocation(getCalculatedValue(),
getDaysDuration(),
getNew(), getModified());
}
}
}