ItEr46S12CUVisualizacionResponsabilidadesTRaballoNaPlanificacion: Letting add resource allocations that are not satisfied.

Task lets not satisfied resource allocations to be added. However, in
order to retrieve them getAllResourceAllocations must be called.
This commit is contained in:
Óscar González Fernández 2010-02-03 17:04:28 +01:00
parent 17ab781ab5
commit b2955b55ab
3 changed files with 32 additions and 24 deletions

View file

@ -56,6 +56,17 @@ import org.navalplanner.business.resources.entities.Resource;
public abstract class ResourceAllocation<T extends DayAssignment> extends
BaseEntity {
public static <T extends ResourceAllocation<?>> List<T> getSatisfied(
Collection<T> resourceAllocations) {
List<T> result = new ArrayList<T>();
for (T each : resourceAllocations) {
if (each.isSatisfied()) {
result.add(each);
}
}
return result;
}
public static <T extends ResourceAllocation<?>> List<T> getOfType(
Class<T> type,
Collection<? extends ResourceAllocation<?>> resourceAllocations) {
@ -453,8 +464,12 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
assert isUnsatisfied();
}
public boolean isSatisfied() {
return hasAssignments();
}
public boolean isUnsatisfied() {
return !hasAssignments();
return !isSatisfied();
}
private void resetAssignmentsTo(List<T> assignments) {

View file

@ -124,21 +124,14 @@ public class Task extends TaskElement {
}
public Set<ResourceAllocation<?>> getResourceAllocations() {
return Collections.unmodifiableSet(filterEmpty(resourceAllocations));
List<ResourceAllocation<?>> filtered = ResourceAllocation
.getSatisfied(resourceAllocations);
return Collections.unmodifiableSet(new HashSet<ResourceAllocation<?>>(
filtered));
}
private Set<ResourceAllocation<?>> filterEmpty(
Set<ResourceAllocation<?>> allocations) {
Set<ResourceAllocation<?>> result = new HashSet<ResourceAllocation<?>>();
for (ResourceAllocation<?> each : allocations) {
if (each.hasAssignments()) {
result.add(each);
} else {
LOG.warn("there is an empty resource allocation: "
+ each.toString() + " ,on task: " + this);
}
}
return result;
public Set<ResourceAllocation<?>> getAllResourceAllocations() {
return Collections.unmodifiableSet(resourceAllocations);
}
public void addResourceAllocation(ResourceAllocation<?> resourceAllocation) {
@ -146,13 +139,8 @@ public class Task extends TaskElement {
throw new IllegalArgumentException(
"the resourceAllocation's task must be this task");
}
if (resourceAllocation.hasAssignments()) {
resourceAllocations.add(resourceAllocation);
resourceAllocation.associateAssignmentsToResource();
} else {
LOG.warn("adding a resource allocation without assignments: "
+ resourceAllocation);
}
resourceAllocations.add(resourceAllocation);
resourceAllocation.associateAssignmentsToResource();
}
public void removeResourceAllocation(

View file

@ -90,13 +90,17 @@ public class TaskTest {
}
@Test
public void addingEmptyResourceAllocationDoesntAddIt() {
public void getResourceAllocationsDoesntRetrieveUnsatisfiedAllocations() {
assertThat(task.getResourceAllocations().size(), equalTo(0));
SpecificResourceAllocation resourceAllocation = SpecificResourceAllocation.create(task);
task.addResourceAllocation(resourceAllocation);
SpecificResourceAllocation unsatisfied = SpecificResourceAllocation
.create(task);
assertTrue("in order to be meaningful this test needs an unsatisfied "
+ "allocation", unsatisfied.isUnsatisfied());
task.addResourceAllocation(unsatisfied);
assertThat(task.getResourceAllocations().size(), equalTo(0));
assertThat(task.getAllResourceAllocations().size(), equalTo(1));
}
@Test
@ -152,6 +156,7 @@ public class TaskTest {
.anyTimes();
expect(resourceAllocation.getTask()).andReturn(task).anyTimes();
expect(resourceAllocation.hasAssignments()).andReturn(true).anyTimes();
expect(resourceAllocation.isSatisfied()).andReturn(true).anyTimes();
replay(resourceAllocation);
return resourceAllocation;
}