diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java
index 54d8b9ce0..2f8470c39 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/IAllocatable.java
@@ -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);
+
/**
*
* 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.
*
*
- * @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);
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java
index 23ad73936..6e02a4038 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/ResourceAllocation.java
@@ -761,6 +761,14 @@ public abstract class ResourceAllocation 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 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 {
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java
index abcf06803..acd4ac55b 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/SpecificResourceAllocation.java
@@ -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()
diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java
index 2a1723d5a..0d4262efc 100644
--- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java
+++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/SpecificResourceAllocationTest.java
@@ -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 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);