Convert type of constraintDate of TaskStartConstraint to LocalDate

FEA: ItEr61S08TimeUnitConfigurablePlanning
This commit is contained in:
Óscar González Fernández 2010-10-06 23:38:29 +02:00
parent 79ccf427e7
commit 3243858c41
8 changed files with 30 additions and 25 deletions

View file

@ -834,7 +834,8 @@ public abstract class OrderElement extends IntegrationEntity implements
}
protected void applyStartConstraintTo(Task task) {
task.getStartConstraint().notEarlierThan(this.getInitDate());
task.getStartConstraint().notEarlierThan(
LocalDate.fromDateFields(this.getInitDate()));
}
public Set<DirectCriterionRequirement> getDirectCriterionRequirement() {

View file

@ -19,8 +19,6 @@
*/
package org.navalplanner.business.planner.entities;
import java.util.Date;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
@ -33,7 +31,7 @@ public class TaskStartConstraint {
private StartConstraintType startConstraintType = StartConstraintType.AS_SOON_AS_POSSIBLE;
private Date constraintDate = null;
private LocalDate constraintDate = null;
public TaskStartConstraint() {
}
@ -46,26 +44,25 @@ public class TaskStartConstraint {
public void explicityMovedTo(LocalDate date) {
Validate.notNull(date);
startConstraintType = startConstraintType.newTypeAfterMoved();
constraintDate = date.toDateTimeAtStartOfDay().toDate();
constraintDate = date;
}
public Date getConstraintDate() {
return constraintDate != null ? new Date(constraintDate.getTime())
: null;
public LocalDate getConstraintDate() {
return constraintDate;
}
public void notEarlierThan(Date date) {
public void notEarlierThan(LocalDate date) {
Validate.notNull(date);
this.constraintDate = date;
this.startConstraintType = StartConstraintType.START_NOT_EARLIER_THAN;
}
public boolean isValid(StartConstraintType type, Date value) {
public boolean isValid(StartConstraintType type, LocalDate value) {
return type != null
&& type.isAssociatedDateRequired() == (value != null);
}
public void update(StartConstraintType type, Date value) {
public void update(StartConstraintType type, LocalDate value) {
Validate.isTrue(isValid(type, value));
this.startConstraintType = type;
this.constraintDate = value;

View file

@ -64,7 +64,7 @@
<param name="enumClass">org.navalplanner.business.planner.entities.StartConstraintType</param>
</type>
</property>
<property name="constraintDate" />
<property name="constraintDate" type="org.joda.time.contrib.hibernate.PersistentLocalDate"/>
</component>
<one-to-one name="consolidation" class="org.navalplanner.business.planner.entities.consolidations.Consolidation"

View file

@ -240,10 +240,10 @@ public class TaskElementTest {
@Test
@SuppressWarnings("unchecked")
public void ifSomeParentHasInitDateTheStartConstraintIsNotEarlierThan() {
Date initDate = asDate(new LocalDate(2005, 10, 5));
LocalDate initDate = new LocalDate(2005, 10, 5);
OrderLineGroup group = OrderLineGroup.create();
addOrderTo(group);
group.setInitDate(initDate);
group.setInitDate(asDate(initDate));
OrderLine orderLine = OrderLine.create();
group.add(orderLine);
LocalDate deadline = new LocalDate(2007, 4, 4);
@ -291,14 +291,15 @@ public class TaskElementTest {
};
}
private static Matcher<TaskStartConstraint> hasValue(final Date value) {
private static Matcher<TaskStartConstraint> hasValue(final LocalDate value) {
return new BaseMatcher<TaskStartConstraint>() {
@Override
public boolean matches(Object object) {
if (object instanceof TaskStartConstraint) {
TaskStartConstraint startConstraint = (TaskStartConstraint) object;
Date constraintDate = startConstraint.getConstraintDate();
LocalDate constraintDate = startConstraint
.getConstraintDate();
boolean bothNotNull = value != null
&& constraintDate != null;
return value == constraintDate || bothNotNull

View file

@ -111,12 +111,12 @@ public class TaskElementAdapter implements ITaskElementAdapter {
return Collections.emptyList();
case START_IN_FIXED_DATE:
return Collections.singletonList(DateConstraint
.equalTo(startConstraint.getConstraintDate()));
.equalTo(asDate(startConstraint.getConstraintDate())));
case START_NOT_EARLIER_THAN:
return Collections
.singletonList(DateConstraint
.biggerOrEqualThan(startConstraint
.getConstraintDate()));
.biggerOrEqualThan(asDate(startConstraint
.getConstraintDate())));
default:
throw new RuntimeException("can't handle " + constraintType);
}
@ -125,6 +125,10 @@ public class TaskElementAdapter implements ITaskElementAdapter {
}
}
private static Date asDate(LocalDate date) {
return date.toDateTimeAtStartOfDay().toDate();
}
@Autowired
private IAdHocTransactionService transactionService;

View file

@ -118,9 +118,9 @@ public class SubcontractModel implements ISubcontractModel {
private void convertOnStartOnFixedDate(Task task) {
TaskStartConstraint taskConstraint = task.getStartConstraint();
if (taskConstraint.isValid(StartConstraintType.START_IN_FIXED_DATE,
task.getStartDate())) {
task.getIntraDayStartDate().getDate())) {
taskConstraint.update(StartConstraintType.START_IN_FIXED_DATE, task
.getStartDate());
.getIntraDayStartDate().getDate());
}
}

View file

@ -451,7 +451,7 @@ public class EditTaskController extends GenericForwardComposer {
}
return ((ITaskLeafConstraint) taskElement).getStartConstraint()
.getConstraintDate();
.getConstraintDate().toDateTimeAtStartOfDay().toDate();
}
private boolean isTaskLeafConstraint() {

View file

@ -27,6 +27,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.joda.time.LocalDate;
import org.navalplanner.business.planner.entities.ITaskLeafConstraint;
import org.navalplanner.business.planner.entities.StartConstraintType;
import org.navalplanner.business.planner.entities.Task;
@ -293,7 +294,8 @@ public class TaskPropertiesController extends GenericForwardComposer {
startConstraintDate.setVisible(constraint.isAssociatedDateRequired());
TaskStartConstraint taskStartConstraint = currentTaskElementAsTaskLeafConstraint()
.getStartConstraint();
startConstraintDate.setValue(taskStartConstraint.getConstraintDate());
startConstraintDate.setValue(taskStartConstraint.getConstraintDate()
.toDateTimeAtStartOfDay().toDate());
}
private boolean saveConstraintChanges() {
@ -301,8 +303,8 @@ public class TaskPropertiesController extends GenericForwardComposer {
.getStartConstraint();
WebStartConstraintType type = (WebStartConstraintType) startConstraintTypes
.getSelectedItemApi().getValue();
Date inputDate = type.isAssociatedDateRequired() ? startConstraintDate
.getValue() : null;
LocalDate inputDate = type.isAssociatedDateRequired() ? LocalDate
.fromDateFields(startConstraintDate.getValue()) : null;
if (taskConstraint.isValid(type.getType(), inputDate)) {
taskConstraint.update(type.getType(), inputDate);
if (currentContext != null) {