Package de.xima.fc.appointment
Class AppointmentValidationBuilder<Context>
- java.lang.Object
-
- de.xima.fc.appointment.AppointmentValidationBuilder<Context>
-
- Type Parameters:
Context
- Type of the context for the data access object.
public final class AppointmentValidationBuilder<Context> extends Object
Validation builder for validation a sequence of appointment actions. Takes care that if the first appointment is created, a second one cannot be created at the same slot.When an appointment is validated successfully, it is stored locally and taken into consideration when validating other appointments.
- Since:
- 6.5.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AppointmentValidationBuilder<Context>
clearFlags()
Clears all flags that are used for validation.AppointmentValidationBuilder<Context>
flags(EAppointmentBookingFlag... flags)
Uses the given flags for validation.AppointmentValidationBuilder<Context>
flags(Set<EAppointmentBookingFlag> flags)
Uses the given flags for validation.static AppointmentValidationBuilder<IEntityContext>
forActiveDatabase(IEntityContext ec, AppointmentTemplate template, List<IAppointmentClosingTime> closingTimes)
Returns a validation builder backed by an active database connection.static <Context> AppointmentValidationBuilder<Context>
forCustom(IAppointmentValidationAccessObject<Context> dao, AppointmentTemplate template, List<IAppointmentClosingTime> closingTimes)
Returns a validation builder backed by the given data access object.com.google.common.collect.ImmutableList<EAppointmentBookingError>
getAllErrors()
com.google.common.collect.ImmutableSet<UUID>
getSuccessfullyModified()
int
getSuccessfullyModifiedCount()
IAppointmentValidationInfo
getValidationInfo(long appointmentId)
AppointmentValidationBuilder<Context>
now(Instant now)
void
registerAppointment(Appointment appointment, EAppointmentActionType actionType)
Registers an appointment to be validated.Set<EAppointmentBookingError>
validateAppointment(Context ctx, Appointment appointment, EAppointmentActionType actionType, com.google.common.collect.Range<Instant> newTime)
Validates the given appointment and returns all validation errors.Set<EAppointmentBookingError>
validateAppointment(Context ctx, Appointment appointment, SubmittedAppointment action)
Validates the given appointment and returns all validation errors.
-
-
-
Method Detail
-
clearFlags
public AppointmentValidationBuilder<Context> clearFlags()
Clears all flags that are used for validation. Must be called beforevalidateAppointment(Object, Appointment, EAppointmentActionType, Range)
.- Returns:
- This for chaining.
-
flags
public AppointmentValidationBuilder<Context> flags(EAppointmentBookingFlag... flags)
Uses the given flags for validation. Must be called beforevalidateAppointment(Object, Appointment, EAppointmentActionType, Range)
.- Parameters:
flags
- Flags to use for validation. They are added to the existing flags.- Returns:
- This for chaining.
-
flags
public AppointmentValidationBuilder<Context> flags(Set<EAppointmentBookingFlag> flags)
Uses the given flags for validation. Must be called beforevalidateAppointment(Object, Appointment, EAppointmentActionType, Range)
.- Parameters:
flags
- Flags to use for validation. They are added to the existing flags.- Returns:
- This for chaining.
-
getAllErrors
public com.google.common.collect.ImmutableList<EAppointmentBookingError> getAllErrors()
- Returns:
- All errors that have occurred so far by calls to
validateAppointment(Object, Appointment, EAppointmentActionType, Range)
.
-
getSuccessfullyModified
public com.google.common.collect.ImmutableSet<UUID> getSuccessfullyModified()
- Returns:
- The appointments that required validation because of a change and that were validated successfully.
-
getSuccessfullyModifiedCount
public int getSuccessfullyModifiedCount()
- Returns:
- The number of appointments that required validation because of a change and that were validated successfully.
-
now
public AppointmentValidationBuilder<Context> now(Instant now)
- Parameters:
now
- An instant to use as the current server time.- Returns:
- This for chaining.
-
registerAppointment
public void registerAppointment(Appointment appointment, EAppointmentActionType actionType)
Registers an appointment to be validated. This is called automatically byvalidateAppointment(Object, Appointment, EAppointmentActionType, Range)
. However, when you wish to validate multiple appointments, you should call this method on all appointments first. This ensures an optimal order of validation, e.g. booking an appointment at 12:00 o'clock and then cancelling an existing appointment at 12:00 o'clock does not work, but canceling the existing one first and then booking the other appointment works.If you call this method on an appointment, you must also later call
validateAppointment(Object, Appointment, EAppointmentActionType, Range)
, or the total validation resultgetAllErrors()
may be wrong.- Parameters:
appointment
- Appointment that will be validated later.actionType
- Action that would be applied to the appointment.
-
validateAppointment
public Set<EAppointmentBookingError> validateAppointment(Context ctx, Appointment appointment, EAppointmentActionType actionType, com.google.common.collect.Range<Instant> newTime)
Validates the given appointment and returns all validation errors. Appointments that previously validated successfully can block slots.- Parameters:
ctx
- Context for the data access object.appointment
- Appointment to validate.actionType
- Action that would be performed with the appointment.newTime
- New time of a moved appointment. Should benull
otherwise.- Returns:
- All validation errors of the given appointment.
-
validateAppointment
public Set<EAppointmentBookingError> validateAppointment(Context ctx, Appointment appointment, SubmittedAppointment action)
Validates the given appointment and returns all validation errors. Appointments that previously validated successfully can block slots.- Parameters:
ctx
- Context for the data access object.appointment
- Appointment to validate.action
- Action that would be performed with the appointment.- Returns:
- All validation errors of the given appointment.
-
getValidationInfo
public IAppointmentValidationInfo getValidationInfo(long appointmentId)
-
forActiveDatabase
public static AppointmentValidationBuilder<IEntityContext> forActiveDatabase(IEntityContext ec, AppointmentTemplate template, List<IAppointmentClosingTime> closingTimes)
Returns a validation builder backed by an active database connection.- Parameters:
ec
- An entity context that must be active.template
- A template for which to validate appointments. Must be contained in the given entity context.- Returns:
- A new validation builder that queries the database for checking against existing appointments.
-
forCustom
public static <Context> AppointmentValidationBuilder<Context> forCustom(IAppointmentValidationAccessObject<Context> dao, AppointmentTemplate template, List<IAppointmentClosingTime> closingTimes)
Returns a validation builder backed by the given data access object.- Type Parameters:
Context
- Context required by the data access object.- Parameters:
dao
- The data access object to use for looking up existing appointments.template
- A template for which to validate appointments. Must have its references toslots
,closing time
,types
set and accessible.- Returns:
- A new validation builder that queries the given data access object for checking against existing appointments.
-
-