@HandlesEvent("updateAcademicYear")
public Resolution updateAcademicYear() {
long days = 0;
String message = EsimsConstants._BLANK_STRING;
AcademicYear academicYear = (AcademicYear) this.getContext()
.getAttributeFromSession("academicYear");
School school = this.academicYearService
.getSchoolByItsId(this.schoolId);
academicYear.setDescription(this.description);
academicYear.setSchool(school);
academicYear.setStartDate(this.startDate);
academicYear.setEndDate(this.endDate);
academicYear.setStatus(this.status);
//checking for sanity of dates chosen.
try {
// this method was used since India doesnt use DST :-)
days = (endDate.getTime() - startDate.getTime()) / 1000 / 60 / 60
/ 24;
if (days > 365)
throw new BusinessRuleException(
"An academic year cannot be more than 365 days");
} catch (BusinessRuleException businessRuleException) {
ValidationErrors errors = new ValidationErrors();
errors.add("endDate", new LocalizableError(
"/admin/academicyear/tooLong"));
getContext().setValidationErrors(errors);
return getContext().getSourcePageResolution();
}
try {
if (days < 279)
throw new BusinessRuleException(
"An academic year cannot be less than 279 days");
} catch (BusinessRuleException businessRuleException) {
ValidationErrors errors = new ValidationErrors();
errors.add("endDate", new LocalizableError(
"/admin/academicyear/tooShort"));
getContext().setValidationErrors(errors);
return getContext().getSourcePageResolution();
}
this.academicYearService.saveAcademicYear(academicYear);
message = EsimsUtils.createInfoMessage(this.getContext()
.getContextPath(), "Academic year <strong>"
+ academicYear.getDescription()
+ "</strong> was updated succesfully");
this.getContext().removeAttributeFromSession("academicYear");
this.getContext().removeAttributeFromSession("listOfAllAcademicYears");
FlashScope.getCurrent(this.getContext().getRequest(), true).put("message", message);