Class Reminder

  • All Implemented Interfaces:
    Serializable, IdentifiableEntity
    Direct Known Subclasses:
    DateTimeReminder, DurationReminder

    @Entity
    public abstract class Reminder
    extends BasicJpaEntity<Reminder,​ReminderIdentifier>
    A reminder. A reminder is a notification that is sent to a given user at a specific datetime. The accuracy of the reminding triggering is about 5mn meaning a reminder shouldn't be lesser than this value. Nevertheless we recommend strongly to set a reminder at a time far greater than 15mn otherwise expecting behaviour might occurred (this isn't constrained by the reminder). A reminder can be automatically rescheduled, meaning that it is rescheduled at another datetime at each of its triggering until that another datetime isn't defined. This capability depends on the concrete type of the used reminder and it is based upon the return of the isSchedulable() method.
    Author:
    mmoquillon
    See Also:
    Serialized Form
    • Constructor Detail

      • Reminder

        protected Reminder​(ContributionIdentifier contributionId,
                           ReminderProcessName processName)
        Constructs a new reminder about the given contribution for the system.
        Parameters:
        contributionId - the unique identifier of a contribution.
        processName - the name of the process the reminder MUST perform when triggered.
      • Reminder

        protected Reminder​(ContributionIdentifier contributionId,
                           User user,
                           ReminderProcessName processName)
        Constructs a new reminder about the given contribution for the specified user.
        Parameters:
        contributionId - the unique identifier of a contribution.
        user - the user for which the reminder is aimed to.
        processName - the name of the process the reminder MUST perform when triggered.
      • Reminder

        protected Reminder()
    • Method Detail

      • getByContribution

        public static List<Reminder> getByContribution​(ContributionIdentifier contributionId)
        Gets the reminders linked to a contribution represented by the given identifier.
        Parameters:
        contributionId - the identifier of a contribution.
        Returns:
        a list of reminders related to the specified contribution, empty if no such reminders.
      • getByUser

        public static List<Reminder> getByUser​(User user)
        Gets the reminders set by the specified user for himself.
        Parameters:
        user - the user.
        Returns:
        a list of the user's reminders, empty if no such reminders.
      • getByContributionAndUser

        public static List<Reminder> getByContributionAndUser​(ContributionIdentifier contributionId,
                                                              User user)
        Gets the reminders that was set by the specified user for himself and that are about the specified contribution.
        Parameters:
        contributionId - the unique identifier of a contribution.
        user - the user.
        Returns:
        a list of the user's reminders related to the contribution, empty if no such reminders.
      • getById

        public static Reminder getById​(String reminderId)
        Gets a reminder by its identifier.
        Parameters:
        reminderId - the identifier of a reminder.
        Returns:
        the right reminder, null otherwise.
      • copy

        public Reminder copy()
        Copies this reminder to another one. This method expects the concrete class extending the Reminder abstract one implements a default constructor as it is used to constructs an empty Reminder instance before setting the attributes. Any concrete reminders should override this method in order to set their specifics attributes.
        Returns:
        a copy of this reminder.
      • withText

        public <T extends Reminder> T withText​(String text)
        Sets a text with this reminder. The text will be sent with the notification to the user.
        Parameters:
        text - a text to attach with the reminder.
        Returns:
        itself.
      • getContributionId

        public ContributionIdentifier getContributionId()
        Gets the unique identifier of the contribution this remainder is set of.
        Returns:
        the contribution unique identifier.
      • getUserId

        public String getUserId()
        Gets the unique identifier of the user against which this reminder is aimed.
        Returns:
        the identifier of a user as a String
      • isSystemUser

        public boolean isSystemUser()
        Indicates if the user id represents the system.
        Returns:
        the identifier of a user as a String
      • getProcessName

        public String getProcessName()
        Gets the name of the process the reminder MUST perform when triggered.
        Returns:
        the name of the process as string.
      • getText

        public String getText()
        Gets the reminder text.
        Returns:
        the text associated with this reminder.
      • getScheduledDateTime

        public OffsetDateTime getScheduledDateTime()
        Gets the datetime at which this reminder is scheduled. If this reminder isn't yet scheduled, the datetime returned is null, even if its triggering rule is set. The datetime is in UTC/Greenwich.
        Returns:
        a OffsetDateTime value or null if the reminder isn't yet scheduled.
      • getContributionProperty

        public String getContributionProperty()
        Gets the temporal property of the contribution to which this reminder is related.
        Returns:
        the name of a temporal business property of the contribution.
      • isScheduled

        public boolean isScheduled()
        Is this reminder scheduled? The reminder is scheduled if it is taken in charge by the Silverpeas scheduler engine.
        Returns:
        true if this reminder is scheduled to be triggered at its specified date time, false otherwise.
      • isTriggered

        public boolean isTriggered()
        Is this reminder was triggered?
        Returns:
        true if this reminder was already fired, false otherwise.
      • triggered

        protected void triggered()
        This reminder is currently being triggered.
      • schedule

        public <T extends Reminder> T schedule()
        Schedules this reminder. It persists first the reminder properties and then starts its scheduling according to its triggering rule. If this reminder is already scheduled, it is rescheduled with its new triggering rules and any of its properties changes are persisted. Hence, this method can be used both for scheduling and for rescheduling a reminder.
        Returns:
        itself.
        Throws:
        TransactionRuntimeException - if the persistence or the scheduling fails.
        IllegalStateException - if no trigger was set or the triggering date is null.
      • unschedule

        public void unschedule()
        Unschedules this reminder. The reminder won't be anymore scheduled and it will be also removed from the persistence context.
        Throws:
        TransactionRuntimeException - if the persistence or the scheduling fails.
      • isSchedulable

        public boolean isSchedulable()
        Is this reminder schedulable? A reminder is schedulable if its trigger is correctly set and it matches the expectation of the concrete reminder. By default a reminder is schedulable or reschedulable if the temporal property of the related contribution from which the triggering date is computed is non null and after now.
        Returns:
        true if this reminder can be scheduled, false otherwise.
      • getContribution

        protected Contribution getContribution()
        Gets the contribution related by this reminder.
        Returns:
        a Contribution object.
      • computeTriggeringDate

        protected OffsetDateTime computeTriggeringDate()
        Computes the date time at which this reminder will be triggered. This method is invoked in schedule() in order to plan the trigger of this reminder in the timeline. The triggering datetime is computed from the triggering rule that is specific to the concrete type of this reminder. The timezone of the returned triggering date has to be set with the timezone of the user behind the reminder.
        Returns:
        an OffsetDateTime value.