Search in sources :

Example 1 with HolidayBO

use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testGetListOfAccountIdsHavingLoanSchedulesWithinAHoliday.

@Test
public void testGetListOfAccountIdsHavingLoanSchedulesWithinAHoliday() throws Exception {
    Set<HolidayBO> holidays;
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(30);
    GenericDao genericDao = new GenericDaoHibernate();
    OfficeDao officeDao = new OfficeDaoHibernate(genericDao);
    HolidayDao holidayDao = new HolidayDaoHibernate(genericDao);
    OfficeBO sampleBranch = officeDao.findOfficeById(this.getBranchOffice().getOfficeId());
    holidays = new HashSet<HolidayBO>();
    holiday = new HolidayBuilder().withName("Welcome Holiday").from(fromDate).to(thruDate).build();
    holidayDao.save(holiday);
    holidays.add((HolidayBO) holiday);
    sampleBranch.setHolidays(holidays);
    new OfficePersistence().createOrUpdate(sampleBranch);
    StaticHibernateUtil.flushSession();
    List<Object[]> AccountIds = legacyAccountDao.getListOfAccountIdsHavingLoanSchedulesWithinAHoliday(holiday);
    Assert.assertNotNull(AccountIds);
    assertThat(AccountIds.size(), is(2));
}
Also used : GenericDaoHibernate(org.mifos.accounts.savings.persistence.GenericDaoHibernate) GenericDao(org.mifos.accounts.savings.persistence.GenericDao) DateTime(org.joda.time.DateTime) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) HolidayDaoHibernate(org.mifos.application.holiday.persistence.HolidayDaoHibernate) DateMidnight(org.joda.time.DateMidnight) OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficeDao(org.mifos.customers.office.persistence.OfficeDao) HolidayBO(org.mifos.application.holiday.business.HolidayBO) OfficeDaoHibernate(org.mifos.customers.office.persistence.OfficeDaoHibernate) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 2 with HolidayBO

use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testGetListOfAccountIdsHavingCustomerSchedulesWithinAHoliday.

@Test
public void testGetListOfAccountIdsHavingCustomerSchedulesWithinAHoliday() throws Exception {
    Set<HolidayBO> holidays;
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(30);
    GenericDao genericDao = new GenericDaoHibernate();
    OfficeDao officeDao = new OfficeDaoHibernate(genericDao);
    HolidayDao holidayDao = new HolidayDaoHibernate(genericDao);
    OfficeBO sampleBranch = officeDao.findOfficeById(this.getBranchOffice().getOfficeId());
    holidays = new HashSet<HolidayBO>();
    holiday = new HolidayBuilder().withName("Welcome Holiday").from(fromDate).to(thruDate).build();
    holidayDao.save(holiday);
    holidays.add((HolidayBO) holiday);
    sampleBranch.setHolidays(holidays);
    new OfficePersistence().createOrUpdate(sampleBranch);
    StaticHibernateUtil.flushSession();
    List<Object[]> AccountIds = legacyAccountDao.getListOfAccountIdsHavingCustomerSchedulesWithinAHoliday(holiday);
    Assert.assertNotNull(AccountIds);
    assertThat(AccountIds.size(), is(3));
}
Also used : GenericDaoHibernate(org.mifos.accounts.savings.persistence.GenericDaoHibernate) GenericDao(org.mifos.accounts.savings.persistence.GenericDao) DateTime(org.joda.time.DateTime) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) HolidayDaoHibernate(org.mifos.application.holiday.persistence.HolidayDaoHibernate) DateMidnight(org.joda.time.DateMidnight) OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficeDao(org.mifos.customers.office.persistence.OfficeDao) HolidayBO(org.mifos.application.holiday.business.HolidayBO) OfficeDaoHibernate(org.mifos.customers.office.persistence.OfficeDaoHibernate) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 3 with HolidayBO

use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.

the class HolidayServiceImpl method create.

@Override
public void create(HolidayDetails holidayDetails, List<Short> officeIds) {
    HolidayBO holiday = HolidayBO.fromDto(holidayDetails);
    holiday.validate();
    List<OfficeBO> offices = new ArrayList<OfficeBO>();
    for (Short officeId : officeIds) {
        OfficeBO office = officeDao.findOfficeById(officeId);
        offices.add(office);
        if (office.hasChildWithAnyOf(officeIds)) {
            throw new BusinessRuleException(HolidayConstants.HOLIDAY_CREATION_EXCEPTION);
        // "Holidays can only be associated with one level of office in an office hierarchy."
        }
    }
    try {
        hibernateTransactionHelper.startTransaction();
        this.holidayDao.save(holiday);
        for (OfficeBO office : offices) {
            office.addHoliday(holiday);
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ArrayList(java.util.ArrayList) HolidayBO(org.mifos.application.holiday.business.HolidayBO) BusinessRuleException(org.mifos.service.BusinessRuleException)

Example 4 with HolidayBO

use of org.mifos.application.holiday.business.HolidayBO 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 5 with HolidayBO

use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.

the class ApplyHolidayChangesHelperIntegrationTest method createOfficeHolidayTestData.

private void createOfficeHolidayTestData(DateTime startDate) throws Exception {
    /*
         * When startDate is 'yesterday' Head Office Holiday: from 2010-02-22 thru 2010-03-01 ... repayment rule is next
         * meeting date Branch Holiday:
         *
         * from 2010-03-08 thru 2010-03-22 ... moratorium
         *
         * One more holiday that should not affect any schedules
         */
    // Creating Office Holidays
    Set<HolidayBO> holidays;
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("HO Holiday").from(startDate).to(startDate.plusWeeks(1)).withRepaymentRule(RepaymentRuleTypes.NEXT_MEETING_OR_REPAYMENT).build());
    headOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(headOffice);
    OfficeBO centerOffice = testSaveCollectionSheetUtils.getCenter().getOffice();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Center Hierarchy Holiday").from(startDate.plusWeeks(2)).to(startDate.plusWeeks(4)).withRepaymentMoratoriumRule().build());
    centerOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(centerOffice);
    // builder not setting searchId correctly due to not going thru office.save (which uses HierarchyManager)
    String headOfficeSearchId = headOffice.getSearchId();
    OfficeBO anotherOffice = new OfficeBuilder().withParentOffice(headOffice).withName("Another Office").withSearchId(headOfficeSearchId + "26.").withGlobalOfficeNum("n/a001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("N/A").from(startDate.minusWeeks(3)).to(startDate.plusWeeks(8)).withRepaymentMoratoriumRule().build());
    anotherOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(anotherOffice);
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayBO(org.mifos.application.holiday.business.HolidayBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder)

Aggregations

HolidayBO (org.mifos.application.holiday.business.HolidayBO)7 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)4 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DateMidnight (org.joda.time.DateMidnight)2 GenericDao (org.mifos.accounts.savings.persistence.GenericDao)2 GenericDaoHibernate (org.mifos.accounts.savings.persistence.GenericDaoHibernate)2 Holiday (org.mifos.application.holiday.business.Holiday)2 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)2 HolidayDaoHibernate (org.mifos.application.holiday.persistence.HolidayDaoHibernate)2 OfficeDao (org.mifos.customers.office.persistence.OfficeDao)2 OfficeDaoHibernate (org.mifos.customers.office.persistence.OfficeDaoHibernate)2 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 MessageLookup (org.mifos.application.master.MessageLookup)1