ItEr25S07CUAsignacionGrupoRecursosAPlanificacionItEr24S08: When doing the allocation the assignments created are related with the parent allocation
This commit is contained in:
parent
3629bb0c0f
commit
7ca7680c4a
7 changed files with 80 additions and 6 deletions
|
|
@ -33,7 +33,7 @@ public class GenericDayAssigment extends DayAssigment {
|
|||
return genericResourceAllocation;
|
||||
}
|
||||
|
||||
public void setGenericResourceAllocation(
|
||||
protected void setGenericResourceAllocation(
|
||||
GenericResourceAllocation genericResourceAllocation) {
|
||||
if (this.genericResourceAllocation != null)
|
||||
throw new IllegalStateException(
|
||||
|
|
|
|||
|
|
@ -162,11 +162,18 @@ public class GenericResourceAllocation extends ResourceAllocation {
|
|||
private void setAssigments(List<GenericDayAssigment> assignmentsCreated) {
|
||||
this.genericDayAssigments = new HashSet<GenericDayAssigment>(
|
||||
assignmentsCreated);
|
||||
setParentFor(assignmentsCreated);
|
||||
clearFieldsCalculatedFromAssignments();
|
||||
}
|
||||
|
||||
private void setParentFor(List<GenericDayAssigment> assignmentsCreated) {
|
||||
for (GenericDayAssigment genericDayAssigment : assignmentsCreated) {
|
||||
genericDayAssigment.setGenericResourceAllocation(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<? extends DayAssigment> getAssignments() {
|
||||
public List<? extends DayAssigment> getAssignments() {
|
||||
return DayAssigment.orderedByDay(genericDayAssigments);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,11 +123,10 @@ public abstract class ResourceAllocation extends BaseEntity {
|
|||
return total;
|
||||
}
|
||||
|
||||
protected abstract List<? extends DayAssigment> getAssignments();
|
||||
public abstract List<? extends DayAssigment> getAssignments();
|
||||
|
||||
|
||||
public ResourcesPerDay getResourcesPerDay() {
|
||||
return resourcesPerDay;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -66,6 +67,14 @@ public class SpecificResourceAllocation extends ResourceAllocation implements
|
|||
private void setAssignments(List<SpecificDayAssigment> assignments) {
|
||||
this.specificDaysAssigment = new HashSet<SpecificDayAssigment>(
|
||||
assignments);
|
||||
setParentFor(specificDaysAssigment);
|
||||
}
|
||||
|
||||
private void setParentFor(
|
||||
Collection<? extends SpecificDayAssigment> assignments) {
|
||||
for (SpecificDayAssigment specificDayAssigment : assignments) {
|
||||
specificDayAssigment.setSpecificResourceAllocation(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import org.junit.matchers.CombinableMatcher;
|
|||
import org.junit.matchers.JUnitMatchers;
|
||||
import org.navalplanner.business.planner.entities.DayAssigment;
|
||||
import org.navalplanner.business.planner.entities.GenericDayAssigment;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.SpecificDayAssigment;
|
||||
|
||||
/**
|
||||
* Some {@link Matcher} that work against dayAssigments
|
||||
|
|
@ -123,4 +125,36 @@ public class DayAssigmentMatchers {
|
|||
return new FromMatcher(start);
|
||||
}
|
||||
|
||||
public static ListDayAssigmentsMatcher haveResourceAllocation(
|
||||
final ResourceAllocation allocation) {
|
||||
return new ListDayAssigmentsMatcher() {
|
||||
|
||||
@Override
|
||||
protected boolean matches(List<DayAssigment> assignments) {
|
||||
for (DayAssigment dayAssigment : assignments) {
|
||||
if (dayAssigment instanceof GenericDayAssigment) {
|
||||
GenericDayAssigment generic = (GenericDayAssigment) dayAssigment;
|
||||
if (!allocation.equals(generic
|
||||
.getGenericResourceAllocation())) {
|
||||
return false;
|
||||
}
|
||||
} else if (dayAssigment instanceof SpecificDayAssigment) {
|
||||
SpecificDayAssigment specific = (SpecificDayAssigment) dayAssigment;
|
||||
if (!allocation.equals(specific
|
||||
.getSpecificResourceAllocation())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("all must belong to allocation "
|
||||
+ allocation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import static org.junit.Assert.assertThat;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.navalplanner.business.test.planner.entities.DayAssigmentMatchers.from;
|
||||
import static org.navalplanner.business.test.planner.entities.DayAssigmentMatchers.haveHours;
|
||||
import static org.navalplanner.business.test.planner.entities.DayAssigmentMatchers.haveResourceAllocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -154,6 +155,22 @@ public class GenericResourceAllocationTest {
|
|||
assertTrue(assigments.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theGeneratedDayAssignmentsAreRelatedWithTheAllocation() {
|
||||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period.days(2)));
|
||||
givenGenericResourceAllocationForTask(task);
|
||||
givenWorkersWithoutLoadAndWithoutCalendar();
|
||||
|
||||
genericResourceAllocation.forResources(Arrays.asList(worker1))
|
||||
.allocate(ResourcesPerDay.amount(1));
|
||||
|
||||
List<GenericDayAssigment> assignments = (List<GenericDayAssigment>) genericResourceAllocation
|
||||
.getAssignments();
|
||||
assertThat(assignments,
|
||||
haveResourceAllocation(genericResourceAllocation));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocatingGeneratesDayAssignmentsForEachDay() {
|
||||
final int TASK_DURATION_DAYS = 4;
|
||||
|
|
@ -231,8 +248,7 @@ public class GenericResourceAllocationTest {
|
|||
LocalDate start = new LocalDate(2006, 10, 5);
|
||||
final int TASK_DURATION_DAYS = 1;
|
||||
final Integer defaultWorkableHours = SameWorkHoursEveryDay
|
||||
.getDefaultWorkingDay()
|
||||
.getWorkableHours(start);
|
||||
.getDefaultWorkingDay().getWorkableHours(start);
|
||||
givenBaseCalendarWithoutExceptions(defaultWorkableHours);
|
||||
givenTaskWithStartAndEnd(toInterval(start, Period
|
||||
.days(TASK_DURATION_DAYS)));
|
||||
|
|
|
|||
|
|
@ -71,6 +71,15 @@ public class SpecificResourceAllocationTest {
|
|||
consecutiveDays(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theAllocationsDoneHaveAsParentTheAllocation() {
|
||||
givenSpecificResourceAllocation(new LocalDate(2000, 2, 4), 2);
|
||||
specificResourceAllocation.allocate(ResourcesPerDay.amount(1));
|
||||
assertThat(specificResourceAllocation.getAssignments(),
|
||||
DayAssigmentMatchers
|
||||
.haveResourceAllocation(specificResourceAllocation));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theAllocationStartsAtTheStartDate() {
|
||||
LocalDate start = new LocalDate(2000, 2, 4);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue