Package org.ametys.cms.workflow
Class SendMailFunction
- java.lang.Object
-
- org.ametys.plugins.workflow.AbstractWorkflowComponent
-
- org.ametys.cms.workflow.AbstractContentWorkflowComponent
-
- org.ametys.cms.workflow.SendMailFunction
-
- All Implemented Interfaces:
com.opensymphony.workflow.FunctionProvider
,PluginAware
,Initializable
,Contextualizable
,LogEnabled
,Serviceable
- Direct Known Subclasses:
SendMailFunction
,SendMailToUserFunction
public class SendMailFunction extends AbstractContentWorkflowComponent implements com.opensymphony.workflow.FunctionProvider, Initializable, PluginAware, Contextualizable
OS workflow function to send mail after an action is triggered.
-
-
Field Summary
Fields Modifier and Type Field Description protected Context
_context
The Avalon context.protected CurrentUserProvider
_currentUserProvider
The current user provider.protected I18nUtils
_i18nUtils
I18nUtilsprotected String
_pluginName
The plugin name.protected RightManager
_rightManager
The rights manager.protected SourceResolver
_sourceResolver
The source resolver.protected UserManager
_userManager
The users manager.protected WorkflowProvider
_workflowProvider
The workflow.protected static String
BODY_KEY
The mail body key.protected static String
RIGHTS_KEY
The rights key.static String
SEND_MAIL
Provide "false" to prevent the function sending the mail.protected static String
SUBJECT_KEY
The mail subject key.-
Fields inherited from class org.ametys.cms.workflow.AbstractContentWorkflowComponent
_contentHelper, CONTENT_KEY
-
Fields inherited from class org.ametys.plugins.workflow.AbstractWorkflowComponent
_logger, _manager, CONTEXT_PARAMETERS_KEY, FAIL_CONDITIONS_KEY, RESULT_MAP_KEY, WORKFLOW_ERRORS_KEY, WORKFLOW_WARNS_KEY
-
-
Constructor Summary
Constructors Constructor Description SendMailFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
_getContentUri(WorkflowAwareContent content)
Get the content uriRequest
_getRequest()
Retrieve the request from which this component is called.protected String
_getRequestUri()
Get the request URI.protected Set<UserIdentity>
_getUsers(WorkflowAwareContent content, Set<String> rights)
Get the user logins.protected void
_sendMails(String subject, String body, Set<String> recipients, String from)
Send the notification emails.void
contextualize(Context context)
void
execute(Map transientVars, Map args, com.opensymphony.module.propertyset.PropertySet ps)
protected List<String>
getBodyI18nParams(User user, WorkflowAwareContent content)
Get the i18n parameters of mail body textUser
getCaller(Map transientVars, WorkflowAwareContent content)
Get the caller of the workflow actionprotected String
getMailBody(String bodyI18nKey, User user, WorkflowAwareContent content, Map transientVars)
Get the text body of mailprotected String
getMailSubject(String subjectI18nKey, User user, WorkflowAwareContent content)
Get the subject of mailprotected Set<String>
getRecipients(Map transientVars, WorkflowAwareContent content, Set<String> rights)
Get the recipientsprotected String
getSender(Map transientVars, WorkflowAwareContent content)
Get the sender for mailprotected List<String>
getSubjectI18nParams(User user, WorkflowAwareContent content)
Get the i18n parameters of mail subjectvoid
initialize()
void
setPluginInfo(String pluginName, String featureName, String id)
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.-
Methods inherited from class org.ametys.cms.workflow.AbstractContentWorkflowComponent
getContent, service
-
Methods inherited from class org.ametys.plugins.workflow.AbstractWorkflowComponent
addWorkflowError, addWorkflowWarning, enableLogging, getConditionFailures, getContextParameters, getResultsMap, getUser
-
-
-
-
Field Detail
-
SEND_MAIL
public static final String SEND_MAIL
Provide "false" to prevent the function sending the mail. Useful when making large automatic workflow operations (for instance, when bulk importing and proposing in one action).- See Also:
- Constant Field Values
-
RIGHTS_KEY
protected static final String RIGHTS_KEY
The rights key.- See Also:
- Constant Field Values
-
SUBJECT_KEY
protected static final String SUBJECT_KEY
The mail subject key.- See Also:
- Constant Field Values
-
BODY_KEY
protected static final String BODY_KEY
The mail body key.- See Also:
- Constant Field Values
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider.
-
_rightManager
protected RightManager _rightManager
The rights manager.
-
_userManager
protected UserManager _userManager
The users manager.
-
_sourceResolver
protected SourceResolver _sourceResolver
The source resolver.
-
_workflowProvider
protected WorkflowProvider _workflowProvider
The workflow.
-
_pluginName
protected String _pluginName
The plugin name.
-
_i18nUtils
protected I18nUtils _i18nUtils
I18nUtils
-
-
Constructor Detail
-
SendMailFunction
public SendMailFunction()
-
-
Method Detail
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
setPluginInfo
public void setPluginInfo(String pluginName, String featureName, String id)
Description copied from interface:PluginAware
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.- Specified by:
setPluginInfo
in interfacePluginAware
- Parameters:
pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)id
- Unique identifier of this component
-
execute
public void execute(Map transientVars, Map args, com.opensymphony.module.propertyset.PropertySet ps) throws com.opensymphony.workflow.WorkflowException
- Specified by:
execute
in interfacecom.opensymphony.workflow.FunctionProvider
- Throws:
com.opensymphony.workflow.WorkflowException
-
getMailSubject
protected String getMailSubject(String subjectI18nKey, User user, WorkflowAwareContent content)
Get the subject of mail- Parameters:
subjectI18nKey
- the i18n key to use for subjectuser
- the callercontent
- the content- Returns:
- the subject
-
getMailBody
protected String getMailBody(String bodyI18nKey, User user, WorkflowAwareContent content, Map transientVars)
Get the text body of mail- Parameters:
bodyI18nKey
- the i18n key to use for bodyuser
- the callercontent
- the contenttransientVars
- the transient variables- Returns:
- the text body
-
_sendMails
protected void _sendMails(String subject, String body, Set<String> recipients, String from)
Send the notification emails.- Parameters:
subject
- the e-mail subject.body
- the e-mail body.recipients
- the recipients emails address.from
- the address sending the e-mail.
-
getSubjectI18nParams
protected List<String> getSubjectI18nParams(User user, WorkflowAwareContent content)
Get the i18n parameters of mail subject- Parameters:
user
- the callercontent
- the content- Returns:
- the i18n parameters
-
getBodyI18nParams
protected List<String> getBodyI18nParams(User user, WorkflowAwareContent content)
Get the i18n parameters of mail body text- Parameters:
user
- the callercontent
- the content- Returns:
- the i18n parameters
-
_getContentUri
protected String _getContentUri(WorkflowAwareContent content)
Get the content uri- Parameters:
content
- the content- Returns:
- the content uri
-
_getRequestUri
protected String _getRequestUri()
Get the request URI.- Returns:
- the full request URI.
-
_getRequest
public Request _getRequest()
Retrieve the request from which this component is called.- Returns:
- the request or
null
.
-
getCaller
public User getCaller(Map transientVars, WorkflowAwareContent content) throws com.opensymphony.workflow.WorkflowException
Get the caller of the workflow action- Parameters:
transientVars
- the transient variablescontent
- content the content- Returns:
- caller the caller if the workflow function
- Throws:
com.opensymphony.workflow.WorkflowException
- if failed to get caller
-
getSender
protected String getSender(Map transientVars, WorkflowAwareContent content) throws com.opensymphony.workflow.WorkflowException
Get the sender for mail- Parameters:
transientVars
- the transient variablescontent
- the content- Returns:
- the sender email address
- Throws:
com.opensymphony.workflow.WorkflowException
- if failed to get email for sender
-
getRecipients
protected Set<String> getRecipients(Map transientVars, WorkflowAwareContent content, Set<String> rights) throws com.opensymphony.workflow.WorkflowException
Get the recipients- Parameters:
transientVars
- the transient variablescontent
- the content.rights
- the set of rights to check.- Returns:
- the recipients.
- Throws:
com.opensymphony.workflow.WorkflowException
- If failed to get recipients
-
_getUsers
protected Set<UserIdentity> _getUsers(WorkflowAwareContent content, Set<String> rights) throws com.opensymphony.workflow.WorkflowException
Get the user logins.- Parameters:
content
- the content.rights
- the set of rights to check.- Returns:
- the users.
- Throws:
com.opensymphony.workflow.WorkflowException
- If an error occurred
-
-