Class RoomService

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.service.RoomService

@Service public class RoomService extends Object
Provides functionality to manage Rooms, namely to create, modify and delete them. This class has absolutely nothing to do with in-room dining in hotels.
  • Field Details

  • Constructor Details

  • Method Details

    • findAll

      @NonNull public @NonNull org.springframework.data.domain.Page<Room> findAll(@NonNull @NonNull org.springframework.data.domain.Pageable pageable)
      A subset of all Rooms in the database table according to the given Pageable.
      Parameters:
      pageable - The pagination information specifying which page of Rooms shall be returned.
      Returns:
      All Rooms, but only the specified subset.
    • findRoomByNumber

      @NonNull public @NonNull Room findRoomByNumber(String number) throws NotFoundException
      Fetches the Room with the specified Room.number from the database table.
      Parameters:
      number - The number of the room that is being looked for.
      Returns:
      The Room matching the given number, if it exists.
      Throws:
      NotFoundException - If no Room has the given room number.
    • findAllRoomNumbers

      @NonNull public @NonNull LinkedHashSet<String> findAllRoomNumbers()
      Fetches all room numbers present on any Rooms in the database.
      Returns:
      All room numbers in the database, sorted.
    • isRoomFree

      public boolean isRoomFree(@NonNull @NonNull Room room)
      Checks whether the given Room is currently free for use or occupied by a Reservation.
      Parameters:
      room - The Room whose status shall be checked.
      Returns:
      True if no Reservation is currently active for the Room.
    • buildScheduleForToday

      @NonNull public @NonNull RoomSchedule buildScheduleForToday(@NonNull @NonNull Room room)

      Creates a RoomSchedule for the given Room for today.

      The schedule will include

      • one RoomScheduleItem for each Reservation matching the given parameters;
      • one schedule item for each time period during which there is no Reservation, this includes the period before the first reservation and the period after the last reservation.

      If there is no Reservation for the Room today, the whole period will be a free period.

      Parameters:
      room - The Room for which the schedule shall be built.
      Returns:
      The schedule for the given Room today.
    • buildScheduleForWeek

      @NonNull public @NonNull LinkedHashMap<DayOfWeek, RoomSchedule> buildScheduleForWeek(@NonNull @NonNull Room room, @NonNull @NonNull LocalDate date)

      Creates a RoomSchedule for the given Room for every day in the given date's week. The week begins on a DayOfWeek.MONDAY, so either

      • on the last Monday or
      • on the given date if it happens to be a Monday.

      The schedule will include for each day:

      • one RoomScheduleItem for each Reservation matching the given parameters;
      • one schedule item for each time period during which there is no Reservation, this includes the period before the first reservation and the period after the last reservation.

      If there is no Reservation for the Room on a day, the whole period will be a free period.

      Consecutive RoomScheduleItems whose durations are no longer than the ReservationService.MINIMUM_RESERVATION_TIMESPAN will be merged recursively.

      Parameters:
      room - The identifier of the Room for which the schedule shall be built.
      date - Any day in the week that shall be considered.
      Returns:
      The schedule for the given Room for every day in the given date's week.
    • buildSchedule

      @NonNull public @NonNull RoomSchedule buildSchedule(@NonNull @NonNull Room room, @NonNull @NonNull LocalDate date)

      Creates a RoomSchedule for the given Room for the given LocalDate.

      The schedule will include

      • one RoomScheduleItem for each Reservation matching the given parameters;
      • one schedule item for each time period during which there is no Reservation, this includes the period before the first reservation and the period after the last reservation.

      If there is no Reservation for the Room today, the whole period will be a free period.

      Parameters:
      room - The Room for which the schedule shall be built.
      date - The schedule will cover this whole day.
      Returns:
      The schedule for the given Room today.
    • buildSchedule

      @NonNull public @NonNull RoomSchedule buildSchedule(@NonNull @NonNull Room room, @NonNull @NonNull LocalDate date, @NonNull @NonNull MergeOptions mergeOptions)
    • buildSchedule

      @NonNull public @NonNull RoomSchedule buildSchedule(@NonNull @NonNull Room room, @NonNull @NonNull LocalDate date, @NonNull @NonNull LocalTime startTime, @NonNull @NonNull LocalTime endTime) throws ReversedTimePeriodException, ReservationPeriodTooSmallException
      Parameters:
      room - The Room for which the schedule shall be built.
      date - The day for which the schedule shall be valid.
      startTime - Ignore Reservations that come before this point in time. Must come >5 minutes before the endTime!
      endTime - Ignore Reservations that come after this point in time. Must come >5 minutes after the startTime!
      Returns:
      The schedule for the given Room between the given startTime and endTime on the given day.
      Throws:
      ReversedTimePeriodException - If the start time does not come before the end time.
      ReservationPeriodTooSmallException - If the startTime does not come >5 minutes before the endTime.
    • createRoom

      @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public void createRoom(@NonNull @NonNull Room room) throws AlreadyExistsException, InvalidIndividualEquipmentException, InvalidCommonEquipmentException

      Adds the given Room to the database.

      Replaces the Room's IndividualEquipmentTypes with matching existing ones, in order not to add new ones to the database. Does the same for the CommonEquipmentTypes.

      Parameters:
      room - The new Room that shall be newly inserted into the database table. Must have a unique Room.id.
      Throws:
      AlreadyExistsException - If the Room's number is already present in the database.
      InvalidIndividualEquipmentException - If one of the Room's IndividualEquipmentTypes does not exist in the database.
      InvalidCommonEquipmentException - If one of the Room's CommonEquipmentTypes does not exist in the database.
    • deleteRoom

      @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public void deleteRoom(@NonNull @NonNull String roomNumber) throws NotFoundException, RoomStillHasReservationsException
      Removes the Room with the given Room.number from the database, if there are no Reservations for the Room that end after LocalDateTime.now().
      Parameters:
      roomNumber - The number of the Room that shall no longer be part of the system.
      Throws:
      NotFoundException - If no Room with the given number exists.
      RoomStillHasReservationsException - If there are still future Reservations for the given Room.