Class ReservationService

java.lang.Object
sk.iway.iwcm.components.reservation.rest.ReservationService

public class ReservationService extends Object
  • Field Details

  • Constructor Details

    • ReservationService

      public ReservationService()
    • ReservationService

      public ReservationService(Prop prop)
  • Method Details

    • checkReservationTimeRangeValidity

      public String checkReservationTimeRangeValidity(ReservationEntity reservation, ReservationObjectEntity reservationObject)
      !! Beware, reservation time must be already set into reservation date (date and time must be combined). Check this validation requirements : 1. Reservation time from is < reservation time to (interval must have 1 minute at least) 2. Reservation time interval inutes) set in reservation object 3. If reservation range reservationTimeFrom-reservationTimeTo fits inside of reservationObject range reservationTimeFrom-reservationTimeTo (check it separately for every day in date range dateFrom-DateTo because reservation object range can be different for every day in week)
      Parameters:
      reservation - reservation to check
      reservationObject - reservation object that we trying reserve
      Returns:
      If any of this validations are violated, text key with belonging error message is returned. Otherwise return null;
    • checkReservationOverlappingValidity

      public String checkReservationOverlappingValidity(ReservationEntity reservation, ReservationObjectEntity reservationObject, ReservationRepository rr, boolean isImporting)
      !! Beware, reservation time must be already set into reservation date (date and time must be combined). Check this validation requirements : 1. Reservation date from is <= than reservation date to (if from = to reservation is for 1 day) 2. Reservation date from/to are'nt in past 3. Reservation overlapping validity, reservation can overlap with other reservations BUT max number of overlaps is set by reservation object (we count ONLY already approved reservations)
      Parameters:
      reservation - reservation to check
      reservationObject - reservation object that we trying reserve
      rr - reservation repository (needed in proces of validation)
      Returns:
      If any of this validations are violated, text key with belonging error message is returned. Otherwise return null;
    • prepareReservationToValidation

      public void prepareReservationToValidation(ReservationEntity reservation, boolean isReservationForAllDay) throws IllegalArgumentException
      Prepare reservation to validation. First check if needed values are not null. Then set reservation date based on input value "isReservationForAllDay". If isReservationForAllDay is true, date is same but hh:mm:ss:ms are set to 0 (because reservation upon reservation object for whole day cant set other time then default). If isReservationForAllDay is false, date is set as combination of date from reservation and time from reservationEditorFields.
      Parameters:
      reservation -
      isReservationForAllDay -
      Throws:
      IllegalArgumentException
    • sendAcceptationEmail

      public void sendAcceptationEmail(ReservationEntity reservation, javax.servlet.http.HttpServletRequest request)
      Get reservation object "email accepter" and send mail to notify accepter about new waiting reservation for this reservation object. Email includes link to this reservation waiting for approve.
      Parameters:
      reservation -
      request -
    • sendConfirmationEmail

      public void sendConfirmationEmail(ReservationEntity reservation, javax.servlet.http.HttpServletRequest request, Identity loggedUser)
      Send confirmation email to email address set in reservation. Email subject and text is based on reservation "accepted" value where : (true, reservation was accepted), (false, reservation was rejected), (null, reservation status was reset and reservation is waiting for approve)
      Parameters:
      reservation - approved reservation
      request - HttpServletRequest instance
      loggedUser - actually logged user who change reservation accepted status
    • sendCreatedReservationEmail

      public void sendCreatedReservationEmail(ReservationEntity reservation, javax.servlet.http.HttpServletRequest request)
      Send email to recipient (who created reservation) about created reservation. Email includes reservation details + info if reservation is approved or awaiting for acceptation.
      Parameters:
      reservation - - created reservation
      request - - HttpServletRequest instance
    • checkOverlap

      public boolean checkOverlap(Date s1, Date e1, Date s2, Date e2, Boolean prepareDates)
      Validate if interval s1-e1 and interval s2-e2 are overlapping using logical formula. Used formula ((s1 <= e2) && (s2 <= e1)), return true if they are overlapping. Intervals are overlapping even if one start when second ends (08:00-09:00 and 09:00-10:00). IF function is used to compare date values (intervals) representing TIME we want all the values to share same yyyy-mm-dd part and for this reason with input param "prepareDates" set to true, every date part of value will be set to 2000-01-01, so we can compare times.
      Parameters:
      s1 - date value representing START of FIRST interval
      e1 - date value representing END of FIRST interval
      s2 - date value representing START of SECOND interval
      e2 - date value representing END of SECOND interval
      prepareDates - if true set date part of intervals to 2000-01-01, false/null - do nothing
      Returns:
      true - if interval are overlapping, otherwise false
    • throwError

      public void throwError(String errorTextKey)
      Custom function to throw new RuntimeException with message.
      Parameters:
      errorTextKey - translate key of error message
    • calculateReservationPrice

      public static BigDecimal calculateReservationPrice(ReservationEntity entity, int userIdToPay, ReservationObjectRepository ror, ReservationObjectPriceRepository ropr)
      Calculate price of reservation based on reservation object, reservation dateTime range and reservation object special prices.
      Parameters:
      entity - - reservation entity
      ror - - ReservationObjectRepository instance
      ropr - - ReservationObjectPriceRepository instance
      Returns:
    • calculateReservationPrice

      public static BigDecimal calculateReservationPrice(Date dateFrom, Date dateTo, Date timeFrom, Date timeTo, Long objectId, int userIdToPay, ReservationObjectRepository ror, ReservationObjectPriceRepository ropr)
      Calculate price of reservation based on reservation object, reservation dateTime range and reservation object special prices.
      Parameters:
      dateFrom - - start date of reservation
      dateTo - - end date of reservation
      timeFrom - - start time of reservation
      timeTo - - end time of reservation
      objectId - - id of reservation object
      ror - - ReservationObjectRepository instance
      ropr - - ReservationObjectPriceRepository instance
      Returns:
    • calculateReservationPrice

      public static BigDecimal calculateReservationPrice(Long dateFrom, Long dateTo, Long timeFrom, Long timeTo, Long objectId, int userIdToPay, ReservationObjectRepository ror, ReservationObjectPriceRepository ropr)
      Calculate price of reservation based on reservation object, reservation dateTime range and reservation object special prices.
      Parameters:
      dateFrom - - start date of reservation
      dateTo - - end date of reservation
      timeFrom - - start time of reservation
      timeTo - - end time of reservation
      objectId - - id of reservation object
      ror - - ReservationObjectRepository instance
      ropr - - ReservationObjectPriceRepository instance
      Returns:
    • getMapOfPrices

      public static Map<String,BigDecimal> getMapOfPrices(Long dateFrom, Long dateTo, Long timeFrom, Long timeTo, Long objectId, int userIdToPay, ReservationObjectRepository ror, ReservationObjectPriceRepository ropr)
    • acceptation

      public static boolean acceptation(ReservationEntity reservation, javax.servlet.http.HttpServletRequest request)
      If reservation object needs ACCEPTATION and logged user is not accepter (or none is logged), set reservation accepted to null (waiting for acceptation) AND return false. ELSE set reservation accepted to true and return true.
      Parameters:
      reservation -
      request -
      Returns:
    • getReservationObjectHoursSelectList

      public static List<LabelValueInteger> getReservationObjectHoursSelectList()
      Get list of reservation objects for select (as options)/ This reservation objects are filtered by domainId and reservationForAllDay = false.
      Returns:
    • getReservationObjectDaysSelectList

      public static List<LabelValueInteger> getReservationObjectDaysSelectList()
    • getReservationTimeRange

      public static Long[] getReservationTimeRange(Date dateToCheck, ReservationObjectEntity reservationObject)
      If this day have special time range (ReservationObjectTimesEntity) return it, otherwise return default time range (reservationObject). On top of that, remove Minutes/Seconds/MiliSeconds from date values.
      Parameters:
      dateToCheck - - date to check (if there is special time range for this day of week)
      reservationObject -
      Returns:
    • getHoursForTable

      public static List<String> getHoursForTable(Long from, Long to)
      Get list of hours for table (reservation table) based on from-to date values.
      Parameters:
      from -
      to -
      Returns:
    • computeReservationUsageByHours

      public static List<ReservationService.ReservationTableCell> computeReservationUsageByHours(ReservationObjectEntity roe, ReservationRepository rr, Long from, Long to, Long[] supportedRange)
      Prepare list of ReservationTableCell objects for reservation table.
      Parameters:
      roe - - reservation object entity
      rr - - ReservationRepository
      from -
      to -
      supportedRange - - range in which reservation can be made
      Returns:
    • getUserToPay

      public static int getUserToPay(String email, Long reservationId, ReservationRepository rr, javax.servlet.http.HttpServletRequest request)
      Get user id of user who should pay for reservation.
      Parameters:
      email -
      reservationId -
      rr -
      request -
      Returns:
    • getReservationDate

      public static Date getReservationDate(String reservationDateString, String formatString)
      Get reservation date from string. If string is empty or do not match regex, return current date.
      Parameters:
      reservationDateString -
      formatString -
      Returns:
    • getDateId

      public static String getDateId(Date date, boolean addHourToId)
      Get dateId from date object. If addHourToId is true, add hour to dateId.
      Parameters:
      date -
      addHourToId -
      Returns:
      yyyy-MM-dd or yyyy-MM-ddTHH
    • getDateId

      public static String getDateId(Calendar cal, boolean addHourToId)
      Get dateId from date object. If addHourToId is true, add hour to dateId.
      Parameters:
      cal -
      addHourToId -
      Returns:
      yyyy-MM-dd or yyyy-MM-ddTHH
    • computeReservationUsageByDays

      public static Map<String,Integer> computeReservationUsageByDays(Long selectedReservationId, Date startDate, Date endDate, ReservationRepository rr)
      Compute reservation usage by days aka how many reservations are exist for selected reservation object in selected date range (each day in range).
      Parameters:
      selectedReservationId -
      startDate -
      endDate -
      rr -
      Returns:
      Map where key is dateId and value is number of reservations in this day.
    • prepareDates

      public static void prepareDates(ReservationEntity entity, boolean isReservationForAllDay)
    • getArrivalTime

      public static Date getArrivalTime(ReservationEntity entity)
      Get arrival time for reservation. Arrival time is obtained from constant reservationAllDayStartTime.
      Parameters:
      entity -
      Returns:
      Date with time set to reservationAllDayStartTime OR null if constant has wrong format.
    • getDepartureTime

      public static Date getDepartureTime(ReservationEntity entity)
      Get departure time for reservation. Departure time is obtained from constant reservationAllDayEndTime.
      Parameters:
      entity -
      Returns:
      Date with time set to reservationAllDayEndTime OR null if constant has wrong format.
    • wasReservationChanged

      public static boolean wasReservationChanged(ReservationEntity entityToCheck, ReservationRepository rr)
      Check if reservation was changed - compare it with DB version.
      Parameters:
      entityToCheck -
      rr -
      Returns: