Class ReservationEventRequest

java.lang.Object
ch.tocco.nice2.optional.reservation.api.ReservationEventRequest

public final class ReservationEventRequest extends Object
Encapsulates all information needed to create or modify a CalendarEvent for a given Reservation entity.
  • Field Details

  • Method Details

    • createFor

      public static ReservationEventRequest createFor(Entity reservation)
    • forTarget

      public ReservationEventRequest forTarget(Entity assignedEntity, String relationName)
      Creates a new request using this request and the new specified assigned entity. The relationName is the path from the Calendar_event to the entity that is expected to be linked to the calendar event.
    • forTargetRelation

      public ReservationEventRequest forTargetRelation(String relationName)
      Creates a new request using this request and adds a new assigned entity using only the given relationName which is the path from the Calendar_event to an entity that is expected to be linked to the calendar_event.
    • withConflictSettings

      public ReservationEventRequest withConflictSettings(Entity target, String relationName)
      Conflict settings are essentially another assigned-target consisting of a path from the Calendar_event to the entity that is the physical potential conflicting entity regarding this calendar event. In most cases it is the same as the entity that is directly linked to the calendar event (like "Room/relRoom" or "Appliance/relAppliance"). But it might also be further down, like on registrations (User/relReservation_registration.relRegistration.relUser).

      This method creates a new request using this request and the specified conflict settings.

    • getReservation

      public Entity getReservation()
    • getAssignedTarget

    • getConflictSetting

      public Optional<ReservationEventRequest.AsssignedTarget> getConflictSetting()
      Returns the relation-path and target entity of the entity to create conflicts for. This is not necessarily the same as assignedTarget (which is the entity the calendar-event is linked to!). But if no special conflicting target is specified, the assignedTarget is returned.
    • isFacilityDateField

      public static boolean isFacilityDateField(String fieldname)
      Returns true iff the given fieldname equals either FACILITY_FROM or FACILITY_TILL.
    • isInventoryDateField

      public static boolean isInventoryDateField(String fieldname)
      Returns true, iff the given fieldname equals either INVENTORY_FROM or INVENTORY_TILL.
    • isReservationDateField

      public static boolean isReservationDateField(String fieldname)
      Returns true, iff the given fieldname equals either RESERVATION_FROM or RESERVATION_TILL
    • isReservationLabelField

      public static boolean isReservationLabelField(String fieldname)
      Returns `true`, iff the given field name denotes the label field of the Reservation entity.
    • resolveFrom

      public static Optional<Entity> resolveFrom(Entity source, Entity target, String relationPath) throws PersistException
      Resolves to the entity found at relationPath going from the given source entity.

      This is a helper, because entity.resolve("relSomething.relAntoher") does not work! It only resolves one step (a relation name, but not a relation path)!

      Throws:
      PersistException
    • getContext

      public Context getContext()
      Returns the context from the Reservation entity.
    • getCalendarEventFilter

      public EntityFilter getCalendarEventFilter()
      Returns a filter for CalendarEvents.

      This is deduced from the values given to this request and applies any existing constraints.

      At first, the filter will always return calendar events linked to the reservation entity of this request. If a assignedTarget is defined, it is used to further constrain the query by requiring the calendar events to have an existing target for the specified relation name, and, if the target-entity is defined, too, this target must exist.

    • getDateRestrictedEventFilter

      public EntityFilter getDateRestrictedEventFilter() throws PersistException
      Returns a filter for CalendarEvents.

      This filter restricts the events based on the from/to date pairs that exist on the reservation entity of this request. First, only calendar events that are linked to the reservation entity of this request are returned. Then the following applies:

      If facility dates are specified, the filter will skip all calendar events that are linked to rooms.

      If inventory dates are specified, the filter will skip all calendar events that are linked to appliances.

      Throws:
      PersistException
    • getFacilityDates

      public Optional<ReservationEventRequest.Range> getFacilityDates() throws PersistException
      Returns the from/to fields for the facility, if the model contains those fields. If the reservation-facility module is not present, those fields will not exists and Optional.empty() is returned. If no dates exists (i.e. the from date is null), then Optional.empty() is returned, too.
      Throws:
      PersistException
    • getInventoryDates

      public Optional<ReservationEventRequest.Range> getInventoryDates() throws PersistException
      Returns the from/to fields for the inventory, if the model contains those fields. If the reservation-appliance module is not present, those fields will not exists and Optional.empty() is returned. If no dates exists (i.e. the from date is null), then Optional.empty() is returned, too.
      Throws:
      PersistException
    • getReservationDates

      public Optional<ReservationEventRequest.Range> getReservationDates() throws PersistException
      Returns the from/to fields of the Reservation entity. If the from field is not defined, Optional.empty() is returned.
      Throws:
      PersistException
    • getDates

      Returns the most specific from/to dates for this request:
      • If a assignedTarget relation is defined, those specific dates are returned, or the standard from/to dates of the reservation as a fallback.
      • If no assignedTarget is defined, the reservation dates are returned if available, and those of facility and/or inventory serve as fallback. If the reservation from/to fields are mandatory in the form (which should be true by now) this case does not occur.
      If this method returns Optional.empty() this means, that there are no dates at all to return.

      If assignedTarget is defined, and its relation field is neither relRoom nor relAppliance, the standard reservation dates are returned.

      Throws:
      PersistException