use of com.autentia.tnt.manager.holiday.HolidayManager in project TNTConcept by autentia.
the class AvailabilityBean method fillModelHolidays.
/**
* Fill holidays in listOccupations for that user.
*
* @param user
* @param model
*/
private void fillModelHolidays(User user, OcupationModel model) {
Calendar calendarFirstDayOfMonth = Calendar.getInstance();
Calendar calendarLastDayOfMonth = Calendar.getInstance();
Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(selectedDate);
Date lastDayOfMonth = DateUtils.getLastDayOfMonth(selectedDate);
calendarFirstDayOfMonth.setTime(firstDayOfMonth);
calendarLastDayOfMonth.setTime(lastDayOfMonth);
calendarFirstDayOfMonth.add(Calendar.MONTH, -1);
calendarLastDayOfMonth.add(Calendar.MONTH, 1);
RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
RequestHolidaySearch rhSearch = new RequestHolidaySearch();
rhSearch.setUserRequest(user);
rhSearch.setState(HolidayState.ACCEPT);
rhSearch.setStartBeginDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndBeginDate(calendarLastDayOfMonth.getTime());
rhSearch.setStartFinalDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndFinalDate(calendarLastDayOfMonth.getTime());
List<RequestHoliday> listH = rhManager.getAllEntities(rhSearch, null);
for (RequestHoliday rH : listH) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(rH.getBeginDate()));
oc.setEnd(DateUtils.maxHourInDate(rH.getFinalDate()));
oc.setVacances(true);
oc.setHoliday(false);
oc.setDescription(FacesUtils.getMessage("activity.acceptedHolidays"));
model.addOcupationEntry(oc);
}
HolidaySearch monthSearch = new HolidaySearch();
HolidayManager holidayManager = HolidayManager.getDefault();
monthSearch.setStartDate(calendarFirstDayOfMonth.getTime());
monthSearch.setEndDate(calendarLastDayOfMonth.getTime());
List<Holiday> allHolidays = holidayManager.getAllEntities(monthSearch, null);
for (Holiday holiday : allHolidays) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(holiday.getDate()));
oc.setEnd(DateUtils.maxHourInDate(holiday.getDate()));
oc.setVacances(false);
oc.setHoliday(true);
oc.setDescription(holiday.getDescription());
model.addOcupationEntry(oc);
}
}
use of com.autentia.tnt.manager.holiday.HolidayManager in project TNTConcept by autentia.
the class ActivityBean_IT method getMonthTotalHours_GeneralHolidaysInWorkingDays.
@Test
public void getMonthTotalHours_GeneralHolidaysInWorkingDays() {
// create a general holiday day
HolidayManager holidayManager = HolidayManager.getDefault();
Holiday holiday = new Holiday();
LocalDate holidayDay = LocalDate.of(2017, 8, 15);
Date holidayDate = Date.from(holidayDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
holiday.setDate(holidayDate);
holiday.setDescription("Test Holiday");
holidayManager.insertEntity(holiday);
// verify total hours for the month where the holiday day is in
ActivityBeanNoJSF sut = new ActivityBeanNoJSF();
LocalDate august = LocalDate.of(2017, 8, 1);
Date augustDate = Date.from(august.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(augustDate);
double augustHours = sut.getMonthTotalHours();
assertThat(augustHours, closeTo(176.0, 0.1));
}
use of com.autentia.tnt.manager.holiday.HolidayManager in project TNTConcept by autentia.
the class ActivityBean_IT method getMonthTotalHours_GeneralHolidaysInWeekend.
@Test
public void getMonthTotalHours_GeneralHolidaysInWeekend() {
// create a general holiday day in a weekend
HolidayManager holidayManager = HolidayManager.getDefault();
Holiday holiday = new Holiday();
LocalDate holidayInWeekendDay = LocalDate.of(2017, 8, 13);
Date holidayDate = Date.from(holidayInWeekendDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
holiday.setDate(holidayDate);
holiday.setDescription("Test Holiday");
holidayManager.insertEntity(holiday);
// verify total hours for the month where the holiday is in
ActivityBeanNoJSF sut = new ActivityBeanNoJSF();
LocalDate august = LocalDate.of(2017, 8, 1);
Date augustDate = Date.from(august.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(augustDate);
double augustHours = sut.getMonthTotalHours();
assertThat(augustHours, closeTo(184.0, 0.1));
}
Aggregations