Beispiel #1
7
 private boolean overlaps(TimeSlot timeSlot, List<TimeSlot> timeSlots) {
   for (TimeSlot slot : timeSlots) {
     if (timeSlot.getStartTime().equals(slot.getStartTime())) {
       return configMatches(timeSlot, slot);
     } else if (timeSlot.getStartTime().isBefore(slot.getStartTime())) {
       // make sure timeSlot ends before slot starts
       if (timeSlot.getEndTime().isAfter(slot.getStartTime())) {
         return configMatches(timeSlot, slot);
       }
     } else {
       // disabled, as we do want overlapping time slots from different calendar configurations
       //                //only test if these time slots come from different configurations as we
       // DO want overlapping time slots (when min interval is smaller than min duration)
       //                if (!timeSlot.getConfig().equals(slot.getConfig())){
       //
       //                    //if timeSlot starts after slot, make sure it also starts before slot
       // ends
       //                    if (timeSlot.getStartTime().isBefore(slot.getEndTime())){
       //                        return true;
       //                    }
       //                }
     }
   }
   return false;
 }
Beispiel #2
0
  public void checkForBookedCourts(
      TimeSlot timeSlot, List<Booking> confirmedBookings, Boolean preventOverlapping) {
    LocalTime startTime = timeSlot.getStartTime();
    LocalTime endTime = timeSlot.getEndTime();

    for (Booking booking : confirmedBookings) {

      if (timeSlot.getDate().equals(booking.getBookingDate())) {
        LocalTime bookingStartTime = booking.getBookingTime();
        LocalTime bookingEndTime = bookingStartTime.plusMinutes(booking.getDuration().intValue());
        Boolean addBooking = false;
        if (preventOverlapping) {
          if (startTime.isBefore(bookingEndTime)) {
            if (endTime.isAfter(bookingStartTime)) {
              addBooking = true;
            }
          }
        } else {
          // for displaying allocations
          if (startTime.compareTo(bookingStartTime) >= 0) {
            if (endTime.compareTo(bookingEndTime) <= 0) {
              addBooking = true;
            }
          }
        }
        if (addBooking) {
          Offer offer = booking.getOffer();
          for (Offer timeSlotOffer : timeSlot.getConfig().getOffers()) {
            if (offer.equals(timeSlotOffer)) {
              timeSlot.addBooking(booking);
              break;
            }
          }
        }
      }
    }
  }
Beispiel #3
0
  public void addWeekView(
      LocalDate selectedDate,
      List<Facility> selectedFacilities,
      ModelAndView mav,
      Boolean preventOverlapping)
      throws JsonProcessingException {
    // calculate date configuration for datepicker
    LocalDate today = new LocalDate(DEFAULT_TIMEZONE);
    LocalDate firstDay = today.dayOfMonth().withMinimumValue();
    LocalDate lastDay = today.plusDays(Constants.CALENDAR_MAX_DATE).dayOfMonth().withMaximumValue();
    List<CalendarConfig> calendarConfigs = calendarConfigDAO.findBetween(firstDay, lastDay);
    Collections.sort(calendarConfigs);
    Map<String, DatePickerDayConfig> dayConfigs =
        getDayConfigMap(firstDay, lastDay, calendarConfigs);

    List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsBetween(firstDay, lastDay);

    // calculate available time slots
    List<TimeSlot> timeSlots = new ArrayList<>();
    List<LocalDate> weekDays = new ArrayList<>();
    for (int i = 1; i <= CalendarWeekDay.values().length; i++) {
      LocalDate date = selectedDate.withDayOfWeek(i);
      weekDays.add(date);
      if (!date.isBefore(new LocalDate())) {
        try {
          // generate list of bookable time slots
          timeSlots.addAll(
              getTimeSlotsForDate(
                  date, calendarConfigs, confirmedBookings, true, preventOverlapping));
        } catch (CalendarConfigException e) {
          // safe to ignore
        }
      }
    }

    SortedSet<Offer> offers = new TreeSet<>();
    List<TimeRange> rangeList = new ArrayList<>();
    // Map<TimeRange, List<TimeSlot>> rangeList = new TreeMap<>();
    for (TimeSlot slot : timeSlots) {
      Set<Offer> slotOffers = slot.getConfig().getOffers();
      offers.addAll(slotOffers);

      TimeRange range = new TimeRange();
      range.setStartTime(slot.getStartTime());
      range.setEndTime(slot.getEndTime());

      if (rangeList.contains(range)) {
        range = rangeList.get(rangeList.indexOf(range));
      } else {
        rangeList.add(range);
      }

      List<TimeSlot> slotis = range.getTimeSlots();
      slotis.add(slot);
      range.setTimeSlots(slotis);
    }
    Collections.sort(rangeList);

    List<Offer> selectedOffers = new ArrayList<>();
    if (selectedFacilities.isEmpty()) {
      selectedOffers = offerDAO.findAll();
    } else {
      for (Facility facility : selectedFacilities) {
        selectedOffers.addAll(facility.getOffers());
      }
    }
    Collections.sort(selectedOffers);

    mav.addObject("dayConfigs", objectMapper.writeValueAsString(dayConfigs));
    mav.addObject("maxDate", lastDay.toString());
    mav.addObject("Day", selectedDate);
    mav.addObject("NextMonday", selectedDate.plusDays(8 - selectedDate.getDayOfWeek()));
    mav.addObject("PrevSunday", selectedDate.minusDays(selectedDate.getDayOfWeek()));
    mav.addObject("WeekDays", weekDays);
    mav.addObject("RangeMap", rangeList);
    mav.addObject("Offers", offers);
    mav.addObject("SelectedOffers", selectedOffers);
    mav.addObject("SelectedFacilities", selectedFacilities);
    mav.addObject("Facilities", facilityDAO.findAll());
  }