Package org.silverpeas.core.reminder
Class Reminder
- java.lang.Object
-
- org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity<E,I>
-
- org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity<Reminder,ReminderIdentifier>
-
- org.silverpeas.core.reminder.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 theisSchedulable()
method.- Author:
- mmoquillon
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Reminder.ReminderBuilder
A builder of reminders.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Reminder()
protected
Reminder(ContributionIdentifier contributionId, User user, ReminderProcessName processName)
Constructs a new reminder about the given contribution for the specified user.protected
Reminder(ContributionIdentifier contributionId, ReminderProcessName processName)
Constructs a new reminder about the given contribution for the system.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected OffsetDateTime
computeTriggeringDate()
Computes the date time at which this reminder will be triggered.Reminder
copy()
Copies this reminder to another one.boolean
equals(Object o)
static List<Reminder>
getByContribution(ContributionIdentifier contributionId)
Gets the reminders linked to a contribution represented by the given identifier.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.static Reminder
getById(String reminderId)
Gets a reminder by its identifier.static List<Reminder>
getByUser(User user)
Gets the reminders set by the specified user for himself.protected Contribution
getContribution()
Gets the contribution related by this reminder.ContributionIdentifier
getContributionId()
Gets the unique identifier of the contribution this remainder is set of.String
getContributionProperty()
Gets the temporal property of the contribution to which this reminder is related.String
getProcessName()
Gets the name of the process the reminder MUST perform when triggered.OffsetDateTime
getScheduledDateTime()
Gets the datetime at which this reminder is scheduled.String
getText()
Gets the reminder text.String
getUserId()
Gets the unique identifier of the user against which this reminder is aimed.int
hashCode()
boolean
isSchedulable()
Is this reminder schedulable?boolean
isScheduled()
Is this reminder scheduled?boolean
isSystemUser()
Indicates if the user id represents the system.boolean
isTriggered()
Is this reminder was triggered?static Reminder.ReminderBuilder
make(ContributionIdentifier contribution, User user)
Constructs aReminder.ReminderBuilder
to build a new reminder about the specified contribution and for the given user.<T extends Reminder>
Tschedule()
Schedules this reminder.protected void
triggered()
This reminder is currently being triggered.void
unschedule()
Unschedules this reminder.<T extends Reminder>
TwithText(String text)
Sets a text with this reminder.-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.BasicJpaEntity
performBeforePersist, performBeforeRemove, performBeforeUpdate
-
Methods inherited from class org.silverpeas.core.persistence.datasource.model.jpa.AbstractJpaEntity
getId, getNativeId, isPersisted, setId
-
-
-
-
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 theReminder
abstract one implements a default constructor as it is used to constructs an emptyReminder
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.
-
make
public static Reminder.ReminderBuilder make(ContributionIdentifier contribution, User user)
Constructs aReminder.ReminderBuilder
to build a new reminder about the specified contribution and for the given user.- Returns:
- a
Reminder.ReminderBuilder
;
-
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.
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractJpaEntity<Reminder,ReminderIdentifier>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractJpaEntity<Reminder,ReminderIdentifier>
-
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 inschedule()
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.
-
-