Class AbstractUserNotificationBuilder
- java.lang.Object
-
- org.silverpeas.core.notification.user.builder.AbstractUserNotificationBuilder
-
- All Implemented Interfaces:
UserNotificationBuilder
- Direct Known Subclasses:
AbstractResourceUserNotificationBuilder
public abstract class AbstractUserNotificationBuilder extends Object implements UserNotificationBuilder
Abstract implementation of theUserNotificationBuilder
in which common code to build a user notification is already defined. It is recommended to extend this class instead of theUserNotificationBuilder
interface.- Author:
- Yohann Chastagnier
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractUserNotificationBuilder()
Default constructorprotected
AbstractUserNotificationBuilder(String title, String content)
Constructs the notification builder and prepares the notification to build with the specified title and content.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description UserNotification
build()
Builds the notification.protected abstract UserNotification
createNotification()
Creates the user notification.protected abstract NotifAction
getAction()
Gets the type of action on the resource concerned by the notification if any.protected org.silverpeas.kernel.bundle.LocalizationBundle
getBundle()
Gets the localization bundle from which the localized text to use in the notification can be get.protected org.silverpeas.kernel.bundle.LocalizationBundle
getBundle(String language)
Gets the localization bundle for the specified locale to use in the building the notification.protected abstract String
getComponentInstanceId()
Gets the component instance identifier.protected String
getContent()
Gets the content of the notification.protected Collection<String>
getExternalAddressesToNotify()
Gets a collection of email addresses, each of them corresponding to a person external of Silverpeas.protected Collection<String>
getGroupIdsToNotify()
Gets a collection of user group's identifiers.protected String
getLocalizationBundlePath()
Gets the path of the localization bundle to load.protected NotifMessageType
getMessageType()
Gets the type of notification message.protected NotificationMetaData
getNotificationMetaData()
Gets the notification metadata.protected abstract String
getSender()
Gets the sender (the user identifier usually)protected String
getTitle()
Gets the title of the notification.protected Collection<String>
getUserIdsToExcludeFromNotifying()
Collection of identifiers of users that don't have to be notified.protected abstract Collection<String>
getUserIdsToNotify()
A collection of user identifiers.protected void
initialize()
Performs common initializations.protected abstract boolean
isGroupCanBeNotified(String groupId)
Is the specified group of users can be notified?protected boolean
isSendImmediately()
Is the notification to build has to be sent immediately?protected abstract boolean
isUserCanBeNotified(String userId)
Is the specified user can be notified?protected abstract void
performBuild()
Builds the notification data containerprotected void
stop()
Stops the treatmentprotected boolean
stopWhenNoUserToNotify()
Should the notification treatment be stopped if there is no user to notify?
-
-
-
Constructor Detail
-
AbstractUserNotificationBuilder
protected AbstractUserNotificationBuilder()
Default constructor
-
AbstractUserNotificationBuilder
protected AbstractUserNotificationBuilder(String title, String content)
Constructs the notification builder and prepares the notification to build with the specified title and content.- Parameters:
title
- the title of the notification.content
- the content of the notification.
-
-
Method Detail
-
initialize
protected void initialize()
Performs common initializations. TheUserNotification
object is constructed here by invoking thecreateNotification()
method.
-
createNotification
protected abstract UserNotification createNotification()
Creates the user notification. This method is used to construct and initialize aUserNotification
object in thebuild()
method.- Returns:
- a
UserNotification
object.
-
getAction
protected abstract NotifAction getAction()
Gets the type of action on the resource concerned by the notification if any.- Returns:
- a value of the
NotifAction
enumeration.
-
getComponentInstanceId
protected abstract String getComponentInstanceId()
Gets the component instance identifier.- Returns:
- the unique identifier of the component instance concerned by the notification to build.
-
getSender
protected abstract String getSender()
Gets the sender (the user identifier usually)- Returns:
- the unique identifier of the sender.
-
isUserCanBeNotified
protected abstract boolean isUserCanBeNotified(String userId)
Is the specified user can be notified? The reason depends on the nature of the notification and as such it is delegated to the implementor. For example, for notifications about a resource, only users that can access the resource can be notified, not the others even if they are part of the recipients.- Returns:
- true of the specified user satisfies all the requirements to be notified.
-
isGroupCanBeNotified
protected abstract boolean isGroupCanBeNotified(String groupId)
Is the specified group of users can be notified? The reason depends on the nature of the notification and as such it is delegated to the implementor. For example, for notifications about a resource, only groups of users that can access the resource can be notified, not the others even if they are part of the recipients.- Returns:
- true of the specified group satisfies all the requirements to be notified.
-
getNotificationMetaData
protected final NotificationMetaData getNotificationMetaData()
Gets the notification metadata.- Returns:
- the metadata about the notification to build.
-
getMessageType
protected NotifMessageType getMessageType()
Gets the type of notification message.- Returns:
- a value in the
NotifMessageType
enumeration.
-
isSendImmediately
protected boolean isSendImmediately()
Is the notification to build has to be sent immediately? If no, then its sending will be delayed according to the preferences of the users.- Returns:
- true if the notification to build has to be sent immediately.
-
build
public final UserNotification build()
Builds the notification.- Specified by:
build
in interfaceUserNotificationBuilder
- Returns:
- a
UserNotification
object.
-
getUserIdsToNotify
protected abstract Collection<String> getUserIdsToNotify()
A collection of user identifiers. All the users in this collection will be notified. This method requires to be implemented.- Returns:
-
getUserIdsToExcludeFromNotifying
protected Collection<String> getUserIdsToExcludeFromNotifying()
Collection of identifiers of users that don't have to be notified. By default, an empty collection is returned.- Returns:
- a collection of identifiers of the users to exclude from the notification.
-
getGroupIdsToNotify
protected Collection<String> getGroupIdsToNotify()
Gets a collection of user group's identifiers. All the users in this collection will be notified. By default, an empty collection is returned.- Returns:
- a collection of user group's identifiers.
-
getExternalAddressesToNotify
protected Collection<String> getExternalAddressesToNotify()
Gets a collection of email addresses, each of them corresponding to a person external of Silverpeas. By default, an empty collection is returned.- Returns:
- a collection of email addresses.
-
stopWhenNoUserToNotify
protected boolean stopWhenNoUserToNotify()
Should the notification treatment be stopped if there is no user to notify? By default true. This method can be overridden to specify a different or a contextualized answer. In that case, the recipients setting should be then performed out of the builder.- Returns:
- true if no notification has to be done when no recipient is defined.
-
performBuild
protected abstract void performBuild()
Builds the notification data container
-
getLocalizationBundlePath
protected String getLocalizationBundlePath()
Gets the path of the localization bundle to load. By default, returns the general translations. For more specific localized text to use in the notification, override this method.- Returns:
- the path of the localization bundle.
-
getBundle
protected final org.silverpeas.kernel.bundle.LocalizationBundle getBundle()
Gets the localization bundle from which the localized text to use in the notification can be get.- Returns:
- the localization bundle whose the path is provided by the
getLocalizationBundlePath()
method.
-
getBundle
protected final org.silverpeas.kernel.bundle.LocalizationBundle getBundle(String language)
Gets the localization bundle for the specified locale to use in the building the notification.- Parameters:
language
- the ISO-631 code of a language.- Returns:
- the localization bundle whose path is provided by the
getLocalizationBundlePath()
method.
-
getTitle
protected String getTitle()
Gets the title of the notification. By overriding this method, the title can be customized. By default, the title is the one set explicitly in the constructor of this builder.- Returns:
- the title of the notification.
-
getContent
protected String getContent()
Gets the content of the notification. By overriding this method, the content can be customized. By default, the content is the one set explicitly in the constructor of this builder.- Returns:
- the content of the notification (aka the message itself).
-
stop
protected void stop()
Stops the treatment
-
-