It can specify the intervals using IntraDayDates now
FEA: ItEr74S04BugFixing
This commit is contained in:
parent
9c6d2da933
commit
1169113027
4 changed files with 85 additions and 5 deletions
|
|
@ -22,6 +22,7 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.workingday.IntraDayDate;
|
||||
|
||||
/**
|
||||
* This interface represents an object on which an allocation can be done
|
||||
|
|
@ -33,6 +34,12 @@ public interface IAllocatable extends IAllocateResourcesPerDay {
|
|||
|
||||
public IAllocateResourcesPerDay resourcesPerDayFromEndUntil(LocalDate start);
|
||||
|
||||
/**
|
||||
* @see IAllocatable#onIntervalWithinTask(IntraDayDate, IntraDayDate)
|
||||
*/
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(
|
||||
LocalDate startInclusive, LocalDate endExclusive);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* It does the allocation in the intersection of the underlying task's
|
||||
|
|
@ -45,12 +52,18 @@ public interface IAllocatable extends IAllocateResourcesPerDay {
|
|||
* allocation beyond the task's bounds.
|
||||
* </p>
|
||||
*
|
||||
* @param startInclusive
|
||||
* @param endExclusive
|
||||
* @param start
|
||||
* @param end
|
||||
* @return an object which can be used to allocate hours on the interval
|
||||
* specified with the considerations noted above
|
||||
*/
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(LocalDate startInclusive,
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(IntraDayDate start,
|
||||
IntraDayDate end);
|
||||
|
||||
/**
|
||||
* @see IAllocatable#onInterval(IntraDayDate, IntraDayDate)
|
||||
*/
|
||||
public IAllocateHoursOnInterval onInterval(LocalDate startInclusive,
|
||||
LocalDate endExclusive);
|
||||
|
||||
/**
|
||||
|
|
@ -62,8 +75,8 @@ public interface IAllocatable extends IAllocateResourcesPerDay {
|
|||
* @return an object which can be used to allocate hours on the interval
|
||||
* specified with the considerations noted above
|
||||
*/
|
||||
public IAllocateHoursOnInterval onInterval(LocalDate startInclusive,
|
||||
LocalDate endExclusive);
|
||||
public IAllocateHoursOnInterval onInterval(IntraDayDate start,
|
||||
IntraDayDate end);
|
||||
|
||||
public IAllocateHoursOnInterval fromStartUntil(LocalDate endExclusive);
|
||||
|
||||
|
|
|
|||
|
|
@ -761,6 +761,14 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
new AllocationIntervalInsideTask(start, end));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(
|
||||
IntraDayDate start, IntraDayDate end) {
|
||||
checkStartBeforeOrEqualEnd(start, end);
|
||||
return new OnSubIntervalAllocator(new AllocationIntervalInsideTask(
|
||||
start, end));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onInterval(
|
||||
final LocalDate startInclusive, final LocalDate endExclusive) {
|
||||
|
|
@ -769,11 +777,26 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
startInclusive, endExclusive));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onInterval(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
checkStartBeforeOrEqualEnd(start, end);
|
||||
return new OnSubIntervalAllocator(
|
||||
new AllocationInterval(start,
|
||||
end));
|
||||
}
|
||||
|
||||
private void checkStartBeforeOrEqualEnd(LocalDate start, LocalDate end) {
|
||||
Validate.isTrue(start.compareTo(end) <= 0,
|
||||
"the end must be equal or posterior than start");
|
||||
}
|
||||
|
||||
private void checkStartBeforeOrEqualEnd(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
Validate.isTrue(start.compareTo(end) <= 0,
|
||||
"the end must be equal or posterior than start");
|
||||
}
|
||||
|
||||
private class OnSubIntervalAllocator implements
|
||||
IAllocateHoursOnInterval {
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import org.navalplanner.business.scenarios.entities.Scenario;
|
|||
import org.navalplanner.business.util.deepcopy.OnCopy;
|
||||
import org.navalplanner.business.util.deepcopy.Strategy;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.IntraDayDate;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
/**
|
||||
|
|
@ -207,6 +208,13 @@ public class SpecificResourceAllocation extends
|
|||
return new SpecificAssignmentsAllocator().onIntervalWithinTask(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
return new SpecificAssignmentsAllocator().onIntervalWithinTask(start,
|
||||
end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onInterval(LocalDate startInclusive,
|
||||
LocalDate endExclusive) {
|
||||
|
|
@ -214,6 +222,12 @@ public class SpecificResourceAllocation extends
|
|||
endExclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onInterval(IntraDayDate start,
|
||||
IntraDayDate end) {
|
||||
return new SpecificAssignmentsAllocator().onInterval(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ICalendar getCalendarGivenTaskCalendar(ICalendar taskCalendar) {
|
||||
return CombinedWorkHours.minOf(taskCalendar, getResource()
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import org.junit.Test;
|
|||
import org.navalplanner.business.calendars.entities.AvailabilityTimeLine;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation.DetachDayAssignmentOnRemoval;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation.IOnDayAssignmentRemoval;
|
||||
import org.navalplanner.business.planner.entities.SpecificDayAssignment;
|
||||
|
|
@ -315,6 +316,24 @@ public class SpecificResourceAllocationTest {
|
|||
assertThat(specificResourceAllocation.getAssignments(), haveHours(5, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theIntervalWithinTaskCanBeMadeOfIntraDayDates() {
|
||||
LocalDate start = new LocalDate(2000, 2, 4);
|
||||
givenSpecificResourceAllocation(start, 4);
|
||||
IntraDayDate startInterval = IntraDayDate.startOfDay(start);
|
||||
IntraDayDate endInterval = IntraDayDate.create(start.plusDays(2),
|
||||
EffortDuration.hours(4));
|
||||
specificResourceAllocation.onIntervalWithinTask(startInterval,
|
||||
endInterval).allocateHours(12);
|
||||
List<SpecificDayAssignment> assignments = specificResourceAllocation
|
||||
.getAssignments();
|
||||
assertThat(DayAssignment.sum(assignments), equalTo(hours(12)));
|
||||
assertTrue(assignments.get(0).getDuration()
|
||||
.compareTo(assignments.get(2).getDuration()) > 0);
|
||||
assertTrue(assignments.get(1).getDuration()
|
||||
.compareTo(assignments.get(2).getDuration()) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thePartOfTheIntervalUsedIsTheOneOverlapping() {
|
||||
LocalDate start = new LocalDate(2000, 2, 4);
|
||||
|
|
@ -417,6 +436,17 @@ public class SpecificResourceAllocationTest {
|
|||
haveHours(8, 8, 8, 8, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canAllocateOutsideTheBoundsUsingAnIntervalMadeOfIntraDayDates() {
|
||||
LocalDate start = new LocalDate(2000, 2, 4);
|
||||
givenSpecificResourceAllocation(start, 4);
|
||||
specificResourceAllocation.onInterval(IntraDayDate.startOfDay(start),
|
||||
IntraDayDate.create(start.plusDays(4), hours(4)))
|
||||
.allocateHours(36);
|
||||
assertThat(specificResourceAllocation.getAssignments(),
|
||||
haveHours(8, 8, 8, 8, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocatingZeroHoursAtTheEndShrinksTheAllocation() {
|
||||
LocalDate start = new LocalDate(2000, 2, 4);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue