use of org.mifos.dto.domain.OfficeHoliday in project head by mifos.
the class HolidayServiceFacadeWebTier method holidaysByYear.
@Override
public Map<String, List<OfficeHoliday>> holidaysByYear() {
List<HolidayBO> holidays = this.holidayDao.findAllHolidays();
Map<String, List<OfficeHoliday>> holidaysByYear = new TreeMap<String, List<OfficeHoliday>>();
for (HolidayBO holiday : holidays) {
HolidayDetails holidayDetail = new HolidayDetails(holiday.getHolidayName(), holiday.getHolidayFromDate(), holiday.getHolidayThruDate(), holiday.getRepaymentRuleType().getValue());
String holidayRepaymentRuleName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(holiday.getRepaymentRuleType().getPropertiesKey());
holidayDetail.setRepaymentRuleName(holidayRepaymentRuleName);
int year = holiday.getThruDate().getYear();
List<OfficeHoliday> holidaysInYear = holidaysByYear.get(Integer.toString(year));
if (holidaysInYear == null) {
holidaysInYear = new LinkedList<OfficeHoliday>();
}
holidaysInYear.add(new OfficeHoliday(holidayDetail, this.holidayDao.applicableOffices(holiday.getId())));
holidaysByYear.put(Integer.toString(year), holidaysInYear);
}
sortValuesByFromDate(holidaysByYear);
return holidaysByYear;
}
use of org.mifos.dto.domain.OfficeHoliday in project head by mifos.
the class HolidayFormValidator method validate.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "REC_CATCH_EXCEPTION" }, justification = "Using catch all to detect invalid dates.")
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.NPathComplexity" })
@Override
public void validate(Object target, Errors errors) {
if (target instanceof OfficeHoliday) {
return;
}
HolidayFormBean formBean = (HolidayFormBean) target;
rejectIfEmptyOrWhitespace(errors, formBean.getName(), "error.holiday.mandatory_field");
Date dateFrom = null;
Date dateTo = null;
try {
dateFrom = new DateTime().withDate(Integer.parseInt(formBean.getFromYear()), formBean.getFromMonth(), formBean.getFromDay()).toDate();
} catch (Exception e) {
errors.reject("holiday.fromDate.invalid");
}
if (formBean.anyToDateFieldFilled() && !formBean.allToDateFieldsFilled()) {
errors.reject("holiday.thruDate.invalid");
}
try {
if (formBean.getToDay() != null) {
dateTo = new DateTime().withDate(Integer.parseInt(formBean.getToYear()), formBean.getToMonth(), formBean.getToDay()).toDate();
}
} catch (Exception e) {
if (!errors.hasFieldErrors("holiday.thruDate.invalid")) {
errors.reject("holiday.thruDate.invalid");
}
}
// it should exist in one place within the domain layer
if (dateFrom != null && dateTo != null && new DateTime(dateFrom).compareTo(new DateTime(dateTo)) > 0) {
errors.reject("holiday.fromDate.invalid2");
}
if (dateFrom != null && new DateMidnight(dateFrom).compareTo(new DateMidnight()) < 0) {
errors.reject("holiday.fromDate.invalid3");
}
if (dateFrom != null && new DateMidnight(dateFrom).compareTo(new DateMidnight()) == 0) {
errors.reject("holiday.fromDate.invalid4");
}
if (formBean.getRepaymentRuleId() == null || Integer.parseInt(formBean.getRepaymentRuleId()) < 0) {
errors.reject("holiday.repaymentrule.required");
}
if (formBean.getSelectedOfficeIds().trim().isEmpty()) {
errors.reject("holiday.appliesto.required");
}
}
Aggregations