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();
void explicityMoved(IntraDayDate date);
void explicityMoved(IntraDayDate startDate, IntraDayDate endDate);
}

View file

@ -20,6 +20,8 @@
*/
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 />
@ -29,7 +31,7 @@ public enum PositionConstraintType {
AS_SOON_AS_POSSIBLE(false, _("as soon as possible")) {
@Override
public PositionConstraintType newTypeAfterMoved() {
public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return START_NOT_EARLIER_THAN;
}
@ -41,8 +43,11 @@ public enum PositionConstraintType {
START_NOT_EARLIER_THAN(true, _("start not earlier than")) {
@Override
public PositionConstraintType newTypeAfterMoved() {
return START_NOT_EARLIER_THAN;
public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
if(mode == SchedulingMode.FORWARD)
return START_NOT_EARLIER_THAN;
else
return FINISH_NOT_LATER_THAN;
}
@Override
@ -53,7 +58,7 @@ public enum PositionConstraintType {
START_IN_FIXED_DATE(true, _("start in fixed date")) {
@Override
public PositionConstraintType newTypeAfterMoved() {
public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return START_IN_FIXED_DATE;
}
@ -65,7 +70,7 @@ public enum PositionConstraintType {
AS_LATE_AS_POSSIBLE(false, _("as late as possible")) {
@Override
public PositionConstraintType newTypeAfterMoved() {
public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
return FINISH_NOT_LATER_THAN;
}
@ -77,8 +82,11 @@ public enum PositionConstraintType {
FINISH_NOT_LATER_THAN(true, _("finish not later than")) {
@Override
public PositionConstraintType newTypeAfterMoved() {
return FINISH_NOT_LATER_THAN;
public PositionConstraintType newTypeAfterMoved(SchedulingMode mode) {
if(mode == SchedulingMode.FORWARD)
return START_NOT_EARLIER_THAN;
else
return FINISH_NOT_LATER_THAN;
}
@Override
@ -102,7 +110,7 @@ public enum PositionConstraintType {
this.name = name;
}
public abstract PositionConstraintType newTypeAfterMoved();
public abstract PositionConstraintType newTypeAfterMoved(SchedulingMode mode);
public boolean isAssociatedDateRequired() {
return dateRequired;

View file

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

View file

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

View file

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

View file

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

View file

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