ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: The resources per day are converted taking into account the worker calendar

This commit is contained in:
Óscar González Fernández 2009-09-23 13:24:54 +02:00
parent 019b5707be
commit fbd727da2f
4 changed files with 47 additions and 4 deletions

View file

@ -136,7 +136,11 @@ public class GenericResourceAllocation extends
}
return shares;
}
}
@Override
protected IWorkHours getWorkHoursGivenTaskHours(IWorkHours taskWorkHours) {
return taskWorkHours;
}
public IAllocatable forResources(Collection<? extends Resource> resources) {

View file

@ -207,11 +207,15 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
final int calculateTotalToDistribute(LocalDate day,
ResourcesPerDay resourcesPerDay) {
Integer workableHours = getWorkHours().getWorkableHours(day);
Integer workableHours = getWorkHoursPerDay().getWorkableHours(day);
return resourcesPerDay.asHoursGivenResourceWorkingDayOf(workableHours);
}
private IWorkHours getWorkHours() {
private IWorkHours getWorkHoursPerDay() {
return getWorkHoursGivenTaskHours(getTaskWorkHoursLimit());
}
private IWorkHours getTaskWorkHoursLimit() {
return new IWorkHours() {
@Override
public Integer getWorkableHours(LocalDate day) {
@ -225,6 +229,9 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
};
}
protected abstract IWorkHours getWorkHoursGivenTaskHours(
IWorkHours taskWorkHours);
protected final BaseCalendar getTaskCalendar() {
return getTask().getCalendar();
}

View file

@ -10,6 +10,8 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.NotNull;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.CombinedWorkHours;
import org.navalplanner.business.calendars.entities.IWorkHours;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
@ -96,14 +98,23 @@ public class SpecificResourceAllocation extends
assignmentsAllocation.allocate(resourcesPerDay);
}
@Override
protected IWorkHours getWorkHoursGivenTaskHours(IWorkHours taskWorkHours) {
if (getResource().getCalendar() == null) {
return taskWorkHours;
}
return CombinedWorkHours.minOf(taskWorkHours, getResource()
.getCalendar());
}
@Override
protected Class<SpecificDayAssignment> getDayAssignmentType() {
return SpecificDayAssignment.class;
}
@Override
protected List<DayAssignment> createAssignmentsAtDay(List<Resource> resources,
LocalDate day,
protected List<DayAssignment> createAssignmentsAtDay(
List<Resource> resources, LocalDate day,
ResourcesPerDay resourcesPerDay, int limit) {
int hours = calculateTotalToDistribute(day, resourcesPerDay);
SpecificDayAssignment specific = SpecificDayAssignment.create(day, Math

View file

@ -8,6 +8,8 @@ import static org.junit.Assert.assertThat;
import static org.navalplanner.business.test.planner.entities.DayAssignmentMatchers.consecutiveDays;
import static org.navalplanner.business.test.planner.entities.DayAssignmentMatchers.from;
import java.util.Date;
import org.joda.time.LocalDate;
import org.junit.Test;
import org.navalplanner.business.calendars.entities.BaseCalendar;
@ -35,6 +37,15 @@ public class SpecificResourceAllocationTest {
this.assignedHours = assignedHours;
}
private void givenResourceCalendarAlwaysReturning(int hours) {
this.calendar = createNiceMock(ResourceCalendar.class);
expect(this.calendar.getWorkableHours(isA(LocalDate.class))).andReturn(
hours).anyTimes();
expect(this.calendar.getWorkableHours(isA(Date.class)))
.andReturn(hours).anyTimes();
replay(this.calendar);
}
private void givenWorker(){
this.worker = createNiceMock(Worker.class);
expect(this.worker.getCalendar()).andReturn(calendar).anyTimes();
@ -98,4 +109,14 @@ public class SpecificResourceAllocationTest {
DayAssignmentMatchers.haveHours(8, 8));
}
@Test
public void theResourcesPerDayAreConvertedTakingIntoAccountTheWorkerCalendar() {
givenResourceCalendarAlwaysReturning(4);
LocalDate start = new LocalDate(2000, 2, 4);
givenSpecificResourceAllocation(start, 2);
specificResourceAllocation.allocate(ResourcesPerDay.amount(1));
assertThat(specificResourceAllocation.getAssignments(),
DayAssignmentMatchers.haveHours(4, 4));
}
}