Search in sources :

Example 1 with HolidayDetails

use of org.mifos.dto.domain.HolidayDetails in project head by mifos.

the class HolidayServiceIntegrationTest method shouldCreateHolidayAgainstOfficesOfDifferentLevelThatDoNotExistInSameOfficeHierarchySubTree_Allbranches.

@Test
public void shouldCreateHolidayAgainstOfficesOfDifferentLevelThatDoNotExistInSameOfficeHierarchySubTree_Allbranches() throws Exception {
    // setup
    HolidayDetails holidayDetails = new HolidayDetails("test", new DateTime().plusDays(1).toDate(), new DateTime().plusDays(1).toDate(), RepaymentRuleTypes.NEXT_MEETING_OR_REPAYMENT.getValue());
    List<Short> officeIds = Arrays.asList(branch1.getOfficeId(), branch2.getOfficeId(), branch3.getOfficeId());
    // exercise test
    holidayService.create(holidayDetails, officeIds);
}
Also used : HolidayDetails(org.mifos.dto.domain.HolidayDetails) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with HolidayDetails

use of org.mifos.dto.domain.HolidayDetails 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 3 with HolidayDetails

use of org.mifos.dto.domain.HolidayDetails in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice.

@Test
public void shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice() throws Exception {
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    // setup
    createOfficeHierarchyUnderHeadOffice(headOffice);
    DateTime tomorrow = new DateTime().plusDays(1);
    HolidayDetails holidayDetails = new HolidayBuilder().withName("areaOffice2Holiday").from(tomorrow).to(tomorrow).buildDto();
    IntegrationTestObjectMother.createHoliday(holidayDetails, Arrays.asList(areaOffice2.getOfficeId()));
    HolidayDetails branchOnlyHolidayDetails = new HolidayBuilder().withName("branchOnlyHoliday").from(tomorrow).to(tomorrow).buildDto();
    IntegrationTestObjectMother.createHoliday(branchOnlyHolidayDetails, Arrays.asList(branch1.getOfficeId()));
    // refetch
    branch1 = IntegrationTestObjectMother.findOfficeById(branch1.getOfficeId());
    // exercise test
    try {
        holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(branch1.getParentOffice().getOfficeId(), areaOffice2.getOfficeId());
        fail("shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayDetails(org.mifos.dto.domain.HolidayDetails) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with HolidayDetails

use of org.mifos.dto.domain.HolidayDetails in project head by mifos.

the class PreviewHolidayController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = EDIT_PARAM, required = false) String edit, @RequestParam(value = CANCEL_PARAM, required = false) String cancel, @ModelAttribute("formBean") HolidayFormBean formBean, BindingResult result, SessionStatus status) {
    String viewName = REDIRECT_TO_ADMIN_SCREEN;
    ModelAndView modelAndView = new ModelAndView();
    if (StringUtils.isNotBlank(edit)) {
        viewName = "defineNewHoliday";
        modelAndView.setViewName(viewName);
        modelAndView.addObject("formBean", formBean);
    } else if (StringUtils.isNotBlank(cancel)) {
        modelAndView.setViewName("redirect:viewHolidays.ftl");
        status.setComplete();
    } else if (result.hasErrors()) {
        modelAndView.setViewName("previewHoliday");
    } else {
        HolidayDetails holidayDetail = holidayAssembler.translateHolidayFormBeanToDto(formBean);
        List<Short> branchIds = holidayAssembler.convertToIds(formBean.getSelectedOfficeIds());
        this.holidayServiceFacade.createHoliday(holidayDetail, branchIds);
        viewName = REDIRECT_TO_ADMIN_SCREEN;
        modelAndView.setViewName(viewName);
        status.setComplete();
    }
    return modelAndView;
}
Also used : HolidayDetails(org.mifos.dto.domain.HolidayDetails) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with HolidayDetails

use of org.mifos.dto.domain.HolidayDetails in project head by mifos.

the class CenterScheduleCreationUsingCustomerServiceIntegrationTest method saveHoliday.

private void saveHoliday(DateTime start, DateTime through, RepaymentRuleTypes rule) throws Exception {
    HolidayDetails holidayDetails = new HolidayDetails("testHoliday", start.toDate(), through.toDate(), rule.getValue());
    List<Short> officeIds = new LinkedList<Short>();
    officeIds.add((short) 1);
    IntegrationTestObjectMother.createHoliday(holidayDetails, officeIds);
}
Also used : HolidayDetails(org.mifos.dto.domain.HolidayDetails) LinkedList(java.util.LinkedList)

Aggregations

HolidayDetails (org.mifos.dto.domain.HolidayDetails)12 DateTime (org.joda.time.DateTime)7 Test (org.junit.Test)5 LinkedList (java.util.LinkedList)3 OfficeBO (org.mifos.customers.office.business.OfficeBO)3 Date (java.util.Date)2 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 TreeMap (java.util.TreeMap)1 LocalDate (org.joda.time.LocalDate)1 Before (org.junit.Before)1 HolidayBO (org.mifos.application.holiday.business.HolidayBO)1 RepaymentRuleTypes (org.mifos.application.holiday.util.helpers.RepaymentRuleTypes)1 MessageLookup (org.mifos.application.master.MessageLookup)1 OfficeHoliday (org.mifos.dto.domain.OfficeHoliday)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1