frequency = FrequencyType.BIWEEKLY;
} else {
frequency = FrequencyType.WEEKLY;
}
InfoLesson infoLesson = (InfoLesson) request.getAttribute(PresentationConstants.LESSON);
InfoShift infoShift = (InfoShift) request.getAttribute(PresentationConstants.SHIFT);
String action = request.getParameter("action");
final Shift shift;
if (action != null && action.equals("edit")) {
final Lesson lesson = FenixFramework.getDomainObject(infoLesson.getExternalId());
shift = lesson.getShift();
} else {
shift = FenixFramework.getDomainObject(infoShift.getExternalId());
}
final GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod = shift.getExecutionCourse().getMaxLessonsPeriod();
YearMonthDay lessonNewBeginDate = getDateFromForm(manageLessonForm, "newBeginDate");
YearMonthDay lessonEndDate = getDateFromForm(manageLessonForm, "newEndDate");
List<InfoRoom> emptyRoomsList = null;
if (lessonEndDate != null) {
YearMonthDay executionDegreeLessonsBeginDate = maxLessonsPeriod.getLeft();
YearMonthDay executionDegreeLessonsEndDate = maxLessonsPeriod.getRight();
if (lessonNewBeginDate == null || lessonNewBeginDate.isAfter(lessonEndDate)
|| lessonNewBeginDate.isBefore(executionDegreeLessonsBeginDate)) {
actionErrors.add("error.Lesson.invalid.new.begin.date",
new ActionError("error.Lesson.invalid.new.begin.date"));
saveErrors(request, actionErrors);
return mapping.getInputForward();
}
if (lessonEndDate.isAfter(executionDegreeLessonsEndDate)) {
actionErrors.add("error.Lesson.invalid.new.end.date", new ActionError("error.Lesson.invalid.new.end.date"));
saveErrors(request, actionErrors);
return mapping.getInputForward();
}
emptyRoomsList =
SpaceUtils.allocatableSpace(lessonNewBeginDate, lessonEndDate,
HourMinuteSecond.fromCalendarFields(inicio), HourMinuteSecond.fromCalendarFields(fim), weekDay,
null, frequency, true);
} else if (action != null && action.equals("edit")) {
actionErrors.add("error.Lesson.already.finished", new ActionError("error.Lesson.already.finished"));
saveErrors(request, actionErrors);
return mapping.getInputForward();
} else {
actionErrors.add("error.executionDegree.empty.lessonsPeriod", new ActionError(
"error.executionDegree.empty.lessonsPeriod"));
saveErrors(request, actionErrors);
return mapping.getInputForward();
}
if (emptyRoomsList == null || emptyRoomsList.isEmpty()) {
actionErrors.add("search.empty.rooms.no.rooms", new ActionError("search.empty.rooms.no.rooms"));
saveErrors(request, actionErrors);
return mapping.getInputForward();
}
if (action != null && action.equals("edit")) {
final InfoLesson il = (InfoLesson) request.getAttribute(PresentationConstants.LESSON);
final Space allocatableSpace = il.getAllocatableSpace();
if (allocatableSpace != null) {
emptyRoomsList.add(infoLesson.getInfoRoomOccupation().getInfoRoom());
manageLessonForm.set("nomeSala", infoLesson.getInfoRoomOccupation().getInfoRoom().getNome());
}
}