Class RoomService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EquipmentServiceUsed to fetch existing EquipmentTypes from the database.private final ReservationServiceprivate final RoomRepositoryProvides database access to actually create, modify and delete Rooms. -
Constructor Summary
ConstructorsConstructorDescriptionRoomService(@NonNull RoomRepository roomRepository, @NonNull ReservationService reservationService, @NonNull EquipmentService equipmentService) Constructs a new RoomService. -
Method Summary
Modifier and TypeMethodDescription@NonNull RoomSchedulebuildSchedule(@NonNull Room room, @NonNull LocalDate date) @NonNull RoomSchedulebuildSchedule(@NonNull Room room, @NonNull LocalDate date, @NonNull MergeOptions mergeOptions) @NonNull RoomSchedulebuildSchedule(@NonNull Room room, @NonNull LocalDate date, @NonNull LocalTime startTime, @NonNull LocalTime endTime) @NonNull RoomSchedulebuildScheduleForToday(@NonNull Room room) @NonNull LinkedHashMap<DayOfWeek, RoomSchedule> buildScheduleForWeek(@NonNull Room room, @NonNull LocalDate date) voidcreateRoom(@NonNull Room room) Adds the givenRoomto the database.voiddeleteRoom(@NonNull String roomNumber) Removes theRoomwith the givenRoom.numberfrom the database, if there are no Reservations for the Room that end afterLocalDateTime.now().@NonNull org.springframework.data.domain.Page<Room> findAll(@NonNull org.springframework.data.domain.Pageable pageable) A subset of all Rooms in the database table according to the givenPageable.@NonNull LinkedHashSet<String> Fetches all room numbers present on any Rooms in the database.@NonNull RoomfindRoomByNumber(String number) Fetches theRoomwith the specifiedRoom.numberfrom the database table.booleanisRoomFree(@NonNull Room room)
-
Field Details
-
roomRepository
Provides database access to actually create, modify and delete Rooms. -
reservationService
-
equipmentService
Used to fetch existing EquipmentTypes from the database.- See Also:
-
-
Constructor Details
-
RoomService
public RoomService(@NonNull @NonNull RoomRepository roomRepository, @Lazy @NonNull @NonNull ReservationService reservationService, @Lazy @NonNull @NonNull EquipmentService equipmentService) Constructs a new RoomService.- Parameters:
roomRepository- TheroomRepositoryto be used for database access.reservationService- ThereservationService.equipmentService- TheequipmentService.
-
-
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 givenPageable.- Parameters:
pageable- The pagination information specifying which page of Rooms shall be returned.- Returns:
- All Rooms, but only the specified subset.
-
findRoomByNumber
Fetches theRoomwith the specifiedRoom.numberfrom 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
Fetches all room numbers present on any Rooms in the database.- Returns:
- All room numbers in the database, sorted.
-
isRoomFree
- Parameters:
room- The Room whose status shall be checked.- Returns:
- True if no Reservation is currently active for the Room.
-
buildScheduleForToday
Creates a
RoomSchedulefor the givenRoomfor today.The schedule will include
- one
RoomScheduleItemfor eachReservationmatching 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.
- one
-
buildScheduleForWeek
@NonNull public @NonNull LinkedHashMap<DayOfWeek, RoomSchedule> buildScheduleForWeek(@NonNull @NonNull Room room, @NonNull @NonNull LocalDate date) Creates a
RoomSchedulefor the givenRoomfor every day in the given date's week. The week begins on aDayOfWeek.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
RoomScheduleItemfor eachReservationmatching 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_TIMESPANwill 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
RoomSchedulefor the givenRoomfor the givenLocalDate.The schedule will include
- one
RoomScheduleItemfor eachReservationmatching 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.
- one
-
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 Alias for
ReservationService.buildSchedule(Room, LocalDate, LocalTime, LocalTime).Creates a
RoomSchedulefor the givenRoomfor today.- 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 theendTime!endTime- Ignore Reservations that come after this point in time. Must come >5 minutes after thestartTime!- Returns:
- The schedule for the given Room between the given
startTimeandendTimeon the given day. - Throws:
ReversedTimePeriodException- If the start time does not come before the end time.ReservationPeriodTooSmallException- If thestartTimedoes not come >5 minutes before theendTime.
-
createRoom
@PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public void createRoom(@NonNull @NonNull Room room) throws AlreadyExistsException, InvalidIndividualEquipmentException, InvalidCommonEquipmentException Adds the given
Roomto 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 uniqueRoom.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 theRoomwith the givenRoom.numberfrom the database, if there are no Reservations for the Room that end afterLocalDateTime.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.
-