Search in sources :

Example 1 with HolidayManager

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);
    }
}
Also used : RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) Holiday(com.autentia.tnt.businessobject.Holiday) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) Calendar(java.util.Calendar) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) HolidayManager(com.autentia.tnt.manager.holiday.HolidayManager) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) HolidaySearch(com.autentia.tnt.dao.search.HolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) Date(java.util.Date)

Example 2 with HolidayManager

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));
}
Also used : Holiday(com.autentia.tnt.businessobject.Holiday) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) HolidayManager(com.autentia.tnt.manager.holiday.HolidayManager) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 3 with HolidayManager

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));
}
Also used : Holiday(com.autentia.tnt.businessobject.Holiday) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) HolidayManager(com.autentia.tnt.manager.holiday.HolidayManager) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

Holiday (com.autentia.tnt.businessobject.Holiday)3 RequestHoliday (com.autentia.tnt.businessobject.RequestHoliday)3 HolidayManager (com.autentia.tnt.manager.holiday.HolidayManager)3 RequestHolidayManager (com.autentia.tnt.manager.holiday.RequestHolidayManager)3 Date (java.util.Date)3 LocalDate (java.time.LocalDate)2 Test (org.junit.Test)2 HolidaySearch (com.autentia.tnt.dao.search.HolidaySearch)1 RequestHolidaySearch (com.autentia.tnt.dao.search.RequestHolidaySearch)1 Calendar (java.util.Calendar)1