Adds constraint to check the validation of the dates of the work weeks when these one are empty.
FEA: ItEr75S05CalendarAdminInterfaceItEr74S06
This commit is contained in:
parent
9eaba85472
commit
ae8936afd1
3 changed files with 50 additions and 26 deletions
|
|
@ -24,6 +24,7 @@ package org.navalplanner.web.calendars;
|
|||
import static org.navalplanner.web.I18nHelper._;
|
||||
import static org.navalplanner.web.common.Util.findOrCreate;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -46,6 +47,7 @@ import org.navalplanner.business.calendars.entities.Capacity;
|
|||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar.DayType;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData.Days;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.EffortDuration.Granularity;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
|
|
@ -732,11 +734,11 @@ public abstract class BaseCalendarEditionController extends
|
|||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
if (!baseCalendarModel.checkAndChangeStartDate(version,
|
||||
LocalDate.fromDateFields(((Date) value)))) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("This date can not include the whole previous work week"));
|
||||
try {
|
||||
baseCalendarModel.checkAndChangeStartDate(version,
|
||||
((Date) value));
|
||||
} catch (ValidationException e) {
|
||||
throw new WrongValueException(comp, e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -789,11 +791,12 @@ public abstract class BaseCalendarEditionController extends
|
|||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
if (!baseCalendarModel.checkChangeExpiringDate(version,
|
||||
LocalDate.fromDateFields(((Date) value)))) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("This date can not include the whole next work week"));
|
||||
Date date = ((Date) value);
|
||||
try {
|
||||
baseCalendarModel
|
||||
.checkChangeExpiringDate(version, date);
|
||||
} catch (ValidationException e) {
|
||||
throw new WrongValueException(comp, e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -502,12 +502,22 @@ public class BaseCalendarModel extends IntegrationEntityModel implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAndChangeStartDate(CalendarData version,
|
||||
LocalDate newStartDate) {
|
||||
public void checkAndChangeStartDate(CalendarData version, Date date)
|
||||
throws ValidationException {
|
||||
|
||||
if (date == null) {
|
||||
if (version.equals(getBaseCalendar().getFirstCalendarData())) {
|
||||
return;
|
||||
} else {
|
||||
throw new ValidationException(_("This date can not be empty"));
|
||||
}
|
||||
}
|
||||
|
||||
LocalDate newStartDate = LocalDate.fromDateFields(date);
|
||||
CalendarData prevVersion = getBaseCalendar().getPrevious(version);
|
||||
if ((newStartDate != null) && (prevVersion != null)) {
|
||||
if (getBaseCalendar().getPrevious(prevVersion) == null) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
LocalDate prevStartDate = getBaseCalendar()
|
||||
.getPrevious(prevVersion).getExpiringDate();
|
||||
|
|
@ -515,27 +525,37 @@ public class BaseCalendarModel extends IntegrationEntityModel implements
|
|||
|| ((newStartDate
|
||||
.compareTo(prevStartDate) > 0))) {
|
||||
prevVersion.setExpiringDate(newStartDate);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
throw new ValidationException(
|
||||
_("This date can not include the whole previous work week"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkChangeExpiringDate(CalendarData version,
|
||||
LocalDate newExpiringDate) {
|
||||
public void checkChangeExpiringDate(CalendarData version, Date date) {
|
||||
Integer index = getBaseCalendar().getCalendarDataVersions().indexOf(
|
||||
version);
|
||||
if ((newExpiringDate != null)
|
||||
&& (index < getBaseCalendar().getCalendarDataVersions().size() - 1)) {
|
||||
|
||||
if (date == null) {
|
||||
if (version.equals(getBaseCalendar().getLastCalendarData())) {
|
||||
return;
|
||||
} else {
|
||||
throw new ValidationException(_("This date can not be empty"));
|
||||
}
|
||||
}
|
||||
|
||||
LocalDate newExpiringDate = LocalDate.fromDateFields(date);
|
||||
if ((index < getBaseCalendar().getCalendarDataVersions().size() - 1)) {
|
||||
LocalDate nextExpiringDate = getBaseCalendar()
|
||||
.getCalendarDataVersions().get(index + 1).getExpiringDate();
|
||||
if ((nextExpiringDate == null)
|
||||
|| (newExpiringDate.compareTo(nextExpiringDate) < 0)) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
throw new ValidationException(
|
||||
_("This date can not include the whole next work week"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -211,11 +211,6 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
void checkIsReferencedByOtherEntities(BaseCalendar calendar) throws ValidationException;
|
||||
|
||||
boolean checkAndChangeStartDate(CalendarData version, LocalDate newStartDate);
|
||||
|
||||
boolean checkChangeExpiringDate(CalendarData version,
|
||||
LocalDate newExpiringDate);
|
||||
|
||||
BaseCalendar getCurrentParent();
|
||||
|
||||
List<BaseCalendar> getSortedBaseCalendars(List<BaseCalendar> baseCalendars);
|
||||
|
|
@ -224,4 +219,10 @@ public interface IBaseCalendarModel extends IIntegrationEntityModel {
|
|||
|
||||
Date getCurrentExpiringDate();
|
||||
|
||||
void checkChangeExpiringDate(CalendarData version, Date date)
|
||||
throws ValidationException;
|
||||
|
||||
void checkAndChangeStartDate(CalendarData version, Date date)
|
||||
throws ValidationException;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue