Class AbstractNotifyMentionsObserver<T extends AmetysObject>
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.repository.mentions.AbstractNotifyMentionsObserver<T>
- Type Parameters:
T
- type of theAmetysObject
- All Implemented Interfaces:
AsyncObserver
,Observer
,LogEnabled
,Prioritizable
,Supporter<Event>
,Component
,Serviceable
- Direct Known Subclasses:
AbstractCommentNotifyMentionsObserver
,NotifyThreadMentionsObserver
public abstract class AbstractNotifyMentionsObserver<T extends AmetysObject>
extends AbstractLogEnabled
implements Component, Serviceable, AsyncObserver
Abstract observer to send mails to mentioned users in
AmetysObject
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Link to the ametys objectstatic final record
A record to get all information of the mentionable object -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CurrentUserProvider
The current user providerprotected I18nUtils
The i18n utils.protected MentionUtils
The mention utilsprotected Map
<UserIdentity, User> Cache for resolved usersprotected AmetysObjectResolver
The ametys object resolverprotected UserManager
The user managerFields inherited from interface org.ametys.core.observation.Observer
MAX_PRIORITY, MIN_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_canSendMailToMentionedUser
(T ametysObject, User authorIdentity, UserIdentity mentionedUserIdentity) true
if we can send a mail to the mentioned userprotected String
_createBody
(User user, I18nizableText message, AbstractNotifyMentionsObserver.MentionableObject mentionableObject) create a mail body with argumentsprotected abstract I18nizableText
_getMailMessage
(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Retrieves the notification mail's subjectprotected abstract I18nizableText
Get the type of message to display before the messageprotected abstract I18nizableText
_getMailSubject
(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Retrieves the notification mail's subjectprotected abstract I18nizableText
_getMailTitle
(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Get the title of the mail bodyprotected abstract AbstractNotifyMentionsObserver.MentionableObject
_getMentionableObjectFromArguments
(Map<String, Object> arguments) Get all information of the mentionable object from the argumentsprotected void
Send mail to the given userprotected void
_sendMailToMentionedUsers
(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Send mail to all mentioned users in the mentionable objectprotected abstract String
_transformSyntaxTextToReadableTextWithColors
(String syntaxText, UserIdentity recipient) Transform syntax text to readable text with colors according to whether the recipient is the one being tagged or notint
Get the priority for the component.protected StandardMailBodyHelper.MailBodyBuilder
Get a standard mail body helpervoid
Observes an event.void
service
(ServiceManager manager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.ametys.core.observation.AsyncObserver
parallelizable
-
Field Details
-
_resolver
The ametys object resolver -
_userManager
The user manager -
_currentUserProvider
The current user provider -
_i18nUtils
The i18n utils. -
_resolvedUsers
Cache for resolved users -
_mentionUtils
The mention utils
-
-
Constructor Details
-
AbstractNotifyMentionsObserver
public AbstractNotifyMentionsObserver()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getPriority
Description copied from interface:Prioritizable
Get the priority for the component. On components usingPrioritizable
interface, each implementation define the order. In most cases, less is the number, more prior is the component.- Specified by:
getPriority
in interfacePrioritizable
- Returns:
- the priority
-
observe
Description copied from interface:Observer
Observes an event.- Specified by:
observe
in interfaceObserver
- Parameters:
event
- the event.transientVars
- transientVars passed from one Observer to another when processing a single Event. This may allow optimizations between observers.- Throws:
Exception
- if an error occurs. All exceptions will be logged but not propagated, as the observation mechanism should never fail.
-
_sendMailToMentionedUsers
protected void _sendMailToMentionedUsers(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Send mail to all mentioned users in the mentionable object- Parameters:
mentionableObject
- the mentionable object
-
_createBody
protected String _createBody(User user, I18nizableText message, AbstractNotifyMentionsObserver.MentionableObject mentionableObject) create a mail body with arguments- Parameters:
user
- the usermessage
- the messagementionableObject
- the object- Returns:
- the mail body
-
getStandardMailBodyHelper
Get a standard mail body helper- Returns:
- the standard mail body helper
-
_getMailMessageType
Get the type of message to display before the message- Returns:
- the message type
-
_getMailTitle
protected abstract I18nizableText _getMailTitle(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Get the title of the mail body- Parameters:
mentionableObject
- the mentionable object- Returns:
- the mail title
-
_transformSyntaxTextToReadableTextWithColors
protected abstract String _transformSyntaxTextToReadableTextWithColors(String syntaxText, UserIdentity recipient) Transform syntax text to readable text with colors according to whether the recipient is the one being tagged or not- Parameters:
syntaxText
- the syntax textrecipient
- the recipient- Returns:
- the readable text
-
_canSendMailToMentionedUser
protected boolean _canSendMailToMentionedUser(T ametysObject, User authorIdentity, UserIdentity mentionedUserIdentity) true
if we can send a mail to the mentioned user- Parameters:
ametysObject
- the ametys objectauthorIdentity
- the authormentionedUserIdentity
- the mentioned user- Returns:
true
if we can send a mail to the mentioned user
-
_getMailSubject
protected abstract I18nizableText _getMailSubject(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Retrieves the notification mail's subject- Parameters:
mentionableObject
- the mentionable object- Returns:
- the notification mail's subject
-
_getMailMessage
protected abstract I18nizableText _getMailMessage(AbstractNotifyMentionsObserver.MentionableObject mentionableObject) Retrieves the notification mail's subject- Parameters:
mentionableObject
- the mentionable object- Returns:
- the notification mail's subject
-
_getMentionableObjectFromArguments
protected abstract AbstractNotifyMentionsObserver.MentionableObject _getMentionableObjectFromArguments(Map<String, Object> arguments) throws ExceptionGet all information of the mentionable object from the arguments- Parameters:
arguments
- the arguments map- Returns:
- the mentionable object
- Throws:
Exception
- if an error occurs.
-
_sendMail
Send mail to the given user- Parameters:
user
- the usersubject
- the mail subjectbody
- the mail body
-