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));
}
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));
}
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();
}
}
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;
}
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);
}
Aggregations