Search in sources :

Example 1 with OfficeHoliday

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;
}
Also used : HolidayDetails(org.mifos.dto.domain.HolidayDetails) MessageLookup(org.mifos.application.master.MessageLookup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HolidayBO(org.mifos.application.holiday.business.HolidayBO) TreeMap(java.util.TreeMap) OfficeHoliday(org.mifos.dto.domain.OfficeHoliday)

Example 2 with OfficeHoliday

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");
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) OfficeHoliday(org.mifos.dto.domain.OfficeHoliday) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Aggregations

OfficeHoliday (org.mifos.dto.domain.OfficeHoliday)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 DateMidnight (org.joda.time.DateMidnight)1 DateTime (org.joda.time.DateTime)1 HolidayBO (org.mifos.application.holiday.business.HolidayBO)1 MessageLookup (org.mifos.application.master.MessageLookup)1 HolidayDetails (org.mifos.dto.domain.HolidayDetails)1