Bug #1355: transform NOT EARLIER THAN and NOT LATER THAN constraints to the

correct constraint based on the scheduling mode.

To do that, the scheduling mode, start and end date are needed as parameters.

FEA: ItEr76S04BugFixing
This commit is contained in:
Jacobo Aragunde Pérez 2012-02-24 13:21:30 +01:00
parent 3e3eba1e81
commit 7e850ffaee
7 changed files with 39 additions and 22 deletions

View file

@ -31,5 +31,5 @@ public interface ITaskPositionConstrained {
TaskPositionConstraint getPositionConstraint(); TaskPositionConstraint getPositionConstraint();
void explicityMoved(IntraDayDate date); void explicityMoved(IntraDayDate startDate, IntraDayDate endDate);
} }

View file

@ -20,6 +20,8 @@
*/ */
package org.libreplan.business.planner.entities; package org.libreplan.business.planner.entities;
import org.libreplan.business.orders.entities.Order.SchedulingMode;
/** /**
* Enum with all possible ways of calculating the start of a task <br /> * Enum with all possible ways of calculating the start of a task <br />
@ -29,7 +31,7 @@ public enum PositionConstraintType {
AS_SOON_AS_POSSIBLE(false, _("as soon as possible")) { AS_SOON_AS_POSSIBLE(false, _("as soon as possible")) {
@Override @Override
public PositionConstraintType newTypeAfterMoved() { public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return START_NOT_EARLIER_THAN; return START_NOT_EARLIER_THAN;
} }
@ -41,8 +43,11 @@ public enum PositionConstraintType {
START_NOT_EARLIER_THAN(true, _("start not earlier than")) { START_NOT_EARLIER_THAN(true, _("start not earlier than")) {
@Override @Override
public PositionConstraintType newTypeAfterMoved() { public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return START_NOT_EARLIER_THAN; if(mode == SchedulingMode.FORWARD)
return START_NOT_EARLIER_THAN;
else
return FINISH_NOT_LATER_THAN;
} }
@Override @Override
@ -53,7 +58,7 @@ public enum PositionConstraintType {
START_IN_FIXED_DATE(true, _("start in fixed date")) { START_IN_FIXED_DATE(true, _("start in fixed date")) {
@Override @Override
public PositionConstraintType newTypeAfterMoved() { public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return START_IN_FIXED_DATE; return START_IN_FIXED_DATE;
} }
@ -65,7 +70,7 @@ public enum PositionConstraintType {
AS_LATE_AS_POSSIBLE(false, _("as late as possible")) { AS_LATE_AS_POSSIBLE(false, _("as late as possible")) {
@Override @Override
public PositionConstraintType newTypeAfterMoved() { public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return FINISH_NOT_LATER_THAN; return FINISH_NOT_LATER_THAN;
} }
@ -77,8 +82,11 @@ public enum PositionConstraintType {
FINISH_NOT_LATER_THAN(true, _("finish not later than")) { FINISH_NOT_LATER_THAN(true, _("finish not later than")) {
@Override @Override
public PositionConstraintType newTypeAfterMoved() { public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return FINISH_NOT_LATER_THAN; if(mode == SchedulingMode.FORWARD)
return START_NOT_EARLIER_THAN;
else
return FINISH_NOT_LATER_THAN;
} }
@Override @Override
@ -102,7 +110,7 @@ public enum PositionConstraintType {
this.name = name; this.name = name;
} }
public abstract PositionConstraintType newTypeAfterMoved(); public abstract PositionConstraintType newTypeAfterMoved(SchedulingMode mode);
public boolean isAssociatedDateRequired() { public boolean isAssociatedDateRequired() {
return dateRequired; return dateRequired;

View file

@ -419,8 +419,9 @@ public class Task extends TaskElement implements ITaskPositionConstrained {
} }
} }
public void explicityMoved(IntraDayDate date) { public void explicityMoved(IntraDayDate startDate, IntraDayDate endDate) {
getPositionConstraint().explicityMovedTo(date); getPositionConstraint().explicityMovedTo(startDate, endDate,
getOrderElement().getOrder().getSchedulingMode());
} }
public TaskPositionConstraint getPositionConstraint() { public TaskPositionConstraint getPositionConstraint() {

View file

@ -168,8 +168,9 @@ public class TaskMilestone extends TaskElement implements ITaskPositionConstrain
return false; return false;
} }
public void explicityMoved(IntraDayDate date) { public void explicityMoved(IntraDayDate startDate, IntraDayDate endDate) {
getPositionConstraint().explicityMovedTo(date); getPositionConstraint().explicityMovedTo(startDate, endDate,
getOrderElement().getOrder().getSchedulingMode());
} }
public TaskPositionConstraint getPositionConstraint() { public TaskPositionConstraint getPositionConstraint() {

View file

@ -23,6 +23,7 @@ package org.libreplan.business.planner.entities;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.libreplan.business.orders.entities.Order.SchedulingMode;
import org.libreplan.business.workingday.IntraDayDate; import org.libreplan.business.workingday.IntraDayDate;
/** /**
@ -57,10 +58,16 @@ public class TaskPositionConstraint {
.toDate() : null; .toDate() : null;
} }
public void explicityMovedTo(IntraDayDate date) { public void explicityMovedTo(IntraDayDate startDate, IntraDayDate endDate,
Validate.notNull(date); SchedulingMode mode) {
constraintType = constraintType.newTypeAfterMoved(); Validate.notNull(startDate);
constraintDate = date; Validate.notNull(endDate);
constraintType = constraintType.newTypeAfterMoved(mode);
if (isConstraintAppliedToStart()) {
constraintDate = startDate;
} else {
constraintDate = endDate;
}
} }
public IntraDayDate getConstraintDate() { public IntraDayDate getConstraintDate() {

View file

@ -897,7 +897,7 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel {
IntraDayDate endDate) { IntraDayDate endDate) {
task.setIntraDayStartDate(startDate); task.setIntraDayStartDate(startDate);
task.setIntraDayEndDate(endDate); task.setIntraDayEndDate(endDate);
task.explicityMoved(startDate); task.explicityMoved(startDate, endDate);
} }
private void addLimitingResourceQueueElementIfNeeded(LimitingResourceQueue queue, private void addLimitingResourceQueueElementIfNeeded(LimitingResourceQueue queue,

View file

@ -469,15 +469,14 @@ public class TaskElementAdapter {
public void moveTo(GanttDate newStart) { public void moveTo(GanttDate newStart) {
if (taskElement instanceof ITaskPositionConstrained) { if (taskElement instanceof ITaskPositionConstrained) {
ITaskPositionConstrained task = (ITaskPositionConstrained) taskElement; ITaskPositionConstrained task = (ITaskPositionConstrained) taskElement;
GanttDate newEnd = inferEndFrom(newStart);
if (task.getPositionConstraint() if (task.getPositionConstraint()
.isConstraintAppliedToStart()) { .isConstraintAppliedToStart()) {
setBeginDate(newStart); setBeginDate(newStart);
task.explicityMoved(toIntraDay(newStart));
} else { } else {
GanttDate newEnd = inferEndFrom(newStart);
setEndDate(newEnd); setEndDate(newEnd);
task.explicityMoved(toIntraDay(newEnd));
} }
task.explicityMoved(toIntraDay(newStart), toIntraDay(newEnd));
} }
} }
}; };
@ -568,7 +567,8 @@ public class TaskElementAdapter {
.compareTo(PositionConstraintType.FINISH_NOT_LATER_THAN) == 0 .compareTo(PositionConstraintType.FINISH_NOT_LATER_THAN) == 0
|| constraintType || constraintType
.compareTo(PositionConstraintType.AS_LATE_AS_POSSIBLE) == 0) { .compareTo(PositionConstraintType.AS_LATE_AS_POSSIBLE) == 0) {
task.explicityMoved(toIntraDay(endDate)); task.explicityMoved(taskElement.getIntraDayStartDate(),
toIntraDay(endDate));
} }
} }
} }