ItEr36S14CUAdministracionCategoriaCosteItEr35S15: added validation for negative time intervals in HourCost entity
I have implemented entity-level validation using hibernate validators, and interface-level validation using ZK constraints modified dinamically in the onChange event.
This commit is contained in:
parent
073d60c501
commit
36bbea7e18
3 changed files with 37 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ package org.navalplanner.business.costcategories.entities;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
|
|
@ -107,4 +108,12 @@ public class HourCost extends BaseEntity {
|
|||
if(category!=null && !category.getHourCosts().contains(this))
|
||||
category.addHourCost(this);
|
||||
}
|
||||
|
||||
@AssertTrue(message="The end date cannot be before the init date")
|
||||
public boolean PositiveTimeInterval() {
|
||||
if (endDate == null) {
|
||||
return true;
|
||||
}
|
||||
return (endDate.isAfter(initDate) || initDate.equals(endDate));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.joda.time.LocalDate;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.daos.ICostCategoryDAO;
|
||||
import org.navalplanner.business.costcategories.daos.IHourCostDAO;
|
||||
import org.navalplanner.business.costcategories.daos.ITypeOfWorkHoursDAO;
|
||||
|
|
@ -137,4 +138,13 @@ public class HourCostDAOTest {
|
|||
assertFalse(costCategory1.getHourCosts().contains(hourCost));
|
||||
assertTrue(costCategory2.getHourCosts().contains(hourCost));
|
||||
}
|
||||
|
||||
@Test(expected=ValidationException.class)
|
||||
public void testPositiveTimeInterval() {
|
||||
HourCost hourCost = createValidHourCost();
|
||||
hourCost.setInitDate(new LocalDate(2000,12,31));
|
||||
hourCost.setEndDate(new LocalDate(2000,12,1));
|
||||
|
||||
hourCostDAO.save(hourCost);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,11 +303,25 @@ public class CostCategoryCRUDController extends GenericForwardComposer
|
|||
*
|
||||
* @param row
|
||||
*/
|
||||
private void appendDateboxInitDate(Row row) {
|
||||
private void appendDateboxInitDate(final Row row) {
|
||||
Datebox initDateBox = new Datebox();
|
||||
initDateBox.setConstraint("no empty:" + _("The init date cannot be empty"));
|
||||
bindDateboxInitDate(initDateBox, (HourCost) row.getValue());
|
||||
row.appendChild(initDateBox);
|
||||
|
||||
initDateBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
// Updates the constraint of the endDate box with the new date
|
||||
LocalDate initDate = ((HourCost)row.getValue()).getInitDate();
|
||||
Datebox endDateBox = (Datebox) row.getChildren().get(3);
|
||||
endDateBox.setConstraint("after " + initDate.getYear() +
|
||||
initDate.getMonthOfYear() + initDate.getDayOfMonth());
|
||||
|
||||
Util.reloadBindings(listHourCosts);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -352,6 +366,9 @@ public class CostCategoryCRUDController extends GenericForwardComposer
|
|||
*/
|
||||
private void appendDateboxEndDate(Row row) {
|
||||
Datebox endDateBox = new Datebox();
|
||||
LocalDate initDate = ((HourCost)row.getValue()).getInitDate();
|
||||
endDateBox.setConstraint("after " + initDate.getYear() +
|
||||
initDate.getMonthOfYear() + initDate.getDayOfMonth());
|
||||
bindDateboxEndDate(endDateBox, (HourCost) row.getValue());
|
||||
row.appendChild(endDateBox);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue