use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.
the class HolidayDaoHibernate method validateNoExtraFutureHolidaysApplicableOnParentOffice.
@Override
public void validateNoExtraFutureHolidaysApplicableOnParentOffice(Short oldParentOfficeId, Short newParentOfficeId) throws ApplicationException {
List<Holiday> previousApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(oldParentOfficeId);
List<Holiday> possibleApplicableHolidays = retrieveCurrentAndFutureHolidaysForOfficeHierarchyInAscendingOrder(newParentOfficeId);
if (previousApplicableHolidays.size() != possibleApplicableHolidays.size()) {
throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
}
for (Holiday holiday : previousApplicableHolidays) {
HolidayBO applicableHoliday = (HolidayBO) holiday;
if (!possibleApplicableHolidays.contains(applicableHoliday)) {
throw new ApplicationException(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT);
}
}
}
use of org.mifos.application.holiday.business.HolidayBO in project head by mifos.
the class HolidayDaoHibernateIntegrationTest method shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst.
@Test
public void shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst() throws Exception {
DateTime yesterday = new DateTime().minusDays(1);
Set<HolidayBO> holidays;
OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
holidays = new HashSet<HolidayBO>();
holidays.add((HolidayBO) new HolidayBuilder().withName("Fourth").from(yesterday.plusWeeks(4)).to(yesterday.plusWeeks(5)).build());
holidays.add((HolidayBO) new HolidayBuilder().withName("Second").from(yesterday.plusDays(1)).to(yesterday.plusWeeks(7)).build());
headOffice.setHolidays(holidays);
IntegrationTestObjectMother.createOffice(headOffice);
// builder not setting searchId correctly due to not going thru office.save (which uses HierarchyManager)
String headOfficeSearchId = headOffice.getSearchId();
OfficeBO areaOffice = new OfficeBuilder().withName("Area Office").withSearchId(headOfficeSearchId + "25.").withParentOffice(headOffice).withGlobalOfficeNum("area56").build();
holidays = new HashSet<HolidayBO>();
holidays.add((HolidayBO) new HolidayBuilder().withName("Fifth").from(yesterday.plusWeeks(8)).to(yesterday.plusWeeks(9)).build());
areaOffice.setHolidays(holidays);
IntegrationTestObjectMother.createOffice(areaOffice);
OfficeBO myOffice = new OfficeBuilder().withName("My Office").withSearchId(headOfficeSearchId + "25.1.").withParentOffice(areaOffice).withGlobalOfficeNum("my001").build();
holidays = new HashSet<HolidayBO>();
holidays.add((HolidayBO) new HolidayBuilder().withName("Third").from(yesterday.plusWeeks(3)).to(yesterday.plusWeeks(4)).build());
holidays.add((HolidayBO) new HolidayBuilder().withName("First").from(yesterday).to(yesterday.plusWeeks(2)).build());
myOffice.setHolidays(holidays);
IntegrationTestObjectMother.createOffice(myOffice);
OfficeBO anotherOffice = new OfficeBuilder().withName("Another Unconnected Office").withSearchId(headOfficeSearchId + "26.").withParentOffice(headOffice).withGlobalOfficeNum("n/a001").build();
holidays = new HashSet<HolidayBO>();
holidays.add((HolidayBO) new HolidayBuilder().withName("N/A").from(yesterday.minusWeeks(3)).to(yesterday.plusWeeks(4)).build());
anotherOffice.setHolidays(holidays);
IntegrationTestObjectMother.createOffice(anotherOffice);
List<Holiday> myHolidays = holidayDao.findCurrentAndFutureOfficeHolidaysEarliestFirst(myOffice.getOfficeId());
assertThat(myHolidays.size(), is(5));
assertThat(myHolidays.get(0).getName(), is("First"));
assertThat(myHolidays.get(1).getName(), is("Second"));
assertThat(myHolidays.get(2).getName(), is("Third"));
assertThat(myHolidays.get(3).getName(), is("Fourth"));
assertThat(myHolidays.get(4).getName(), is("Fifth"));
}
Aggregations