Class MailActionExecuter
- java.lang.Object
-
- org.alfresco.repo.action.CommonResourceAbstractBase
-
- org.alfresco.repo.action.ParameterizedItemAbstractBase
-
- org.alfresco.repo.action.executer.ActionExecuterAbstractBase
-
- org.alfresco.repo.action.executer.MailActionExecuter
-
- All Implemented Interfaces:
ActionExecuter,LoggingAwareExecuter,TestModeable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean
public class MailActionExecuter extends ActionExecuterAbstractBase implements org.springframework.beans.factory.InitializingBean, TestModeable
Mail action executor implementation. Note on executing this action as System: it is allowed to executemailactions as system. However there is a limitation if you do so. Because the system user is not a normal user and specifically because there is no correspondingcm:personnode for system, it is not possible to use any reference to that person in the associated email template. Various email templates use a 'person' object in the FTL model to access things like first name, last name etc. In the case of mail actions sent while running as system, none of these will be available.- Author:
- Roy Wetherall
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMailActionExecuter.URLHelper
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNAMEAction executor constantsstatic java.lang.StringPARAM_BCCstatic java.lang.StringPARAM_CCstatic java.lang.StringPARAM_FROMstatic java.lang.StringPARAM_FROM_PERSONAL_NAMEstatic java.lang.StringPARAM_HTMLstatic java.lang.StringPARAM_IGNORE_SEND_FAILUREstatic java.lang.StringPARAM_LOCALEstatic java.lang.StringPARAM_SEND_AFTER_COMMITstatic java.lang.StringPARAM_SUBJECTstatic java.lang.StringPARAM_SUBJECT_PARAMSstatic java.lang.StringPARAM_TEMPLATEstatic java.lang.StringPARAM_TEMPLATE_MODELstatic java.lang.StringPARAM_TEXTstatic java.lang.StringPARAM_TOstatic java.lang.StringPARAM_TO_MANY-
Fields inherited from class org.alfresco.repo.action.executer.ActionExecuterAbstractBase
actionDefinition, applicableTypes, publicAction
-
Fields inherited from class org.alfresco.repo.action.ParameterizedItemAbstractBase
adhocPropertiesAllowed, DISPLAY_LABEL, runtimeActionService
-
Fields inherited from class org.alfresco.repo.action.CommonResourceAbstractBase
name
-
Fields inherited from interface org.alfresco.repo.action.executer.ActionExecuter
PARAM_RESULT
-
-
Constructor Summary
Constructors Constructor Description MailActionExecuter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddParameterDefinitions(java.util.List<ParameterDefinition> paramList)Add the parameter definitionsvoidafterPropertiesSet()Initialise beanvoidclearLastTestMessage()Used when test mode is enabled.protected voidexecuteImpl(Action ruleAction, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef)Send an email messageintgetNumberFailedSends()intgetNumberSuccessfulSends()org.alfresco.service.cmr.repository.NodeRefgetPerson(java.lang.String user)java.lang.StringgetPersonEmail(java.lang.String user)java.lang.StringgetTestMessageTo()intgetTestSentCount()voidinit()Init methodbooleanisFromEnabled()static booleanisHTML(java.lang.String value)booleanisTestMode()protected voidonFail()protected voidonSend()booleanpersonExists(java.lang.String user)org.springframework.mail.javamail.MimeMessageHelperprepareEmail(Action ruleAction, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, org.alfresco.util.Pair<java.lang.String,java.util.Locale> recipient, org.alfresco.util.Pair<javax.mail.internet.InternetAddress,java.util.Locale> sender)intresetTestSentCount()javax.mail.internet.MimeMessageretrieveLastTestMessage()Returns the most recent message that wasn't sent because TestMode had been enabled.booleansendTestMessage()Send a test messagevoidsetAuthenticationService(AuthenticationService authService)voidsetAuthorityService(AuthorityService authorityService)voidsetFromAddress(java.lang.String fromAddress)voidsetFromEnabled(boolean fromEnabled)voidsetHeaderEncoding(java.lang.String headerEncoding)voidsetImageResolver(TemplateImageResolver imageResolver)voidsetMailService(org.springframework.mail.javamail.JavaMailSender javaMailSender)voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)voidsetPersonService(PersonService personService)voidsetPreferenceService(PreferenceService preferenceService)voidsetSendTestMessage(boolean sendTestMessage)voidsetServiceRegistry(ServiceRegistry serviceRegistry)voidsetSysAdminParams(SysAdminParams sysAdminParams)voidsetTemplateService(TemplateService templateService)voidsetTenantService(org.alfresco.repo.tenant.TenantService tenantService)voidsetTestMessageSubject(java.lang.String testMessageSubject)voidsetTestMessageText(java.lang.String testMessageText)voidsetTestMessageTo(java.lang.String testMessageTo)voidsetTestMode(boolean testMode)voidsetTestModeRecipient(java.lang.String testModeRecipient)voidsetValidateAddresses(boolean validateAddresses)-
Methods inherited from class org.alfresco.repo.action.executer.ActionExecuterAbstractBase
createActionDefinition, execute, getActionDefinition, getIgnoreLock, getQueueName, getTrackStatus, isApplicableType, onLogException, setApplicableTypes, setBaseNodeService, setDictionaryService, setIgnoreLock, setLockService, setMlAwareNodeService, setPublicAction, setQueueName, setTrackStatus
-
Methods inherited from class org.alfresco.repo.action.ParameterizedItemAbstractBase
checkMandatoryProperties, getAdhocPropertiesAllowed, getDescriptionKey, getLocalizedParameterDefinitions, getParamDisplayLabel, getParamDisplayLabel, getParameterDefintions, getTitleKey, setAdhocPropertiesAllowed, setLocales, setRuntimeActionService, toString
-
Methods inherited from class org.alfresco.repo.action.CommonResourceAbstractBase
setBeanName
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
Action executor constants- See Also:
- Constant Field Values
-
PARAM_LOCALE
public static final java.lang.String PARAM_LOCALE
- See Also:
- Constant Field Values
-
PARAM_TO
public static final java.lang.String PARAM_TO
- See Also:
- Constant Field Values
-
PARAM_CC
public static final java.lang.String PARAM_CC
- See Also:
- Constant Field Values
-
PARAM_BCC
public static final java.lang.String PARAM_BCC
- See Also:
- Constant Field Values
-
PARAM_TO_MANY
public static final java.lang.String PARAM_TO_MANY
- See Also:
- Constant Field Values
-
PARAM_SUBJECT
public static final java.lang.String PARAM_SUBJECT
- See Also:
- Constant Field Values
-
PARAM_SUBJECT_PARAMS
public static final java.lang.String PARAM_SUBJECT_PARAMS
- See Also:
- Constant Field Values
-
PARAM_TEXT
public static final java.lang.String PARAM_TEXT
- See Also:
- Constant Field Values
-
PARAM_HTML
public static final java.lang.String PARAM_HTML
- See Also:
- Constant Field Values
-
PARAM_FROM
public static final java.lang.String PARAM_FROM
- See Also:
- Constant Field Values
-
PARAM_FROM_PERSONAL_NAME
public static final java.lang.String PARAM_FROM_PERSONAL_NAME
- See Also:
- Constant Field Values
-
PARAM_TEMPLATE
public static final java.lang.String PARAM_TEMPLATE
- See Also:
- Constant Field Values
-
PARAM_TEMPLATE_MODEL
public static final java.lang.String PARAM_TEMPLATE_MODEL
- See Also:
- Constant Field Values
-
PARAM_IGNORE_SEND_FAILURE
public static final java.lang.String PARAM_IGNORE_SEND_FAILURE
- See Also:
- Constant Field Values
-
PARAM_SEND_AFTER_COMMIT
public static final java.lang.String PARAM_SEND_AFTER_COMMIT
- See Also:
- Constant Field Values
-
-
Method Detail
-
setMailService
public void setMailService(org.springframework.mail.javamail.JavaMailSender javaMailSender)
- Parameters:
javaMailSender- the java mail sender
-
setTemplateService
public void setTemplateService(TemplateService templateService)
- Parameters:
templateService- the TemplateService
-
setPersonService
public void setPersonService(PersonService personService)
- Parameters:
personService- the PersonService
-
setPreferenceService
public void setPreferenceService(PreferenceService preferenceService)
-
setAuthenticationService
public void setAuthenticationService(AuthenticationService authService)
- Parameters:
authService- the AuthenticationService
-
setServiceRegistry
public void setServiceRegistry(ServiceRegistry serviceRegistry)
- Parameters:
serviceRegistry- the ServiceRegistry
-
setAuthorityService
public void setAuthorityService(AuthorityService authorityService)
- Parameters:
authorityService- the AuthorityService
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
- Parameters:
nodeService- the NodeService to set.
-
setTenantService
public void setTenantService(org.alfresco.repo.tenant.TenantService tenantService)
- Parameters:
tenantService- the TenantService to set.
-
setHeaderEncoding
public void setHeaderEncoding(java.lang.String headerEncoding)
- Parameters:
headerEncoding- The mail header encoding to set.
-
setFromAddress
public void setFromAddress(java.lang.String fromAddress)
- Parameters:
fromAddress- The default mail address.
-
setSysAdminParams
public void setSysAdminParams(SysAdminParams sysAdminParams)
-
setImageResolver
public void setImageResolver(TemplateImageResolver imageResolver)
-
setTestMessageTo
public void setTestMessageTo(java.lang.String testMessageTo)
-
getTestMessageTo
public java.lang.String getTestMessageTo()
-
setTestMessageSubject
public void setTestMessageSubject(java.lang.String testMessageSubject)
-
setTestMessageText
public void setTestMessageText(java.lang.String testMessageText)
-
setSendTestMessage
public void setSendTestMessage(boolean sendTestMessage)
-
sendTestMessage
public boolean sendTestMessage()
Send a test message- Returns:
- true, message sent
- Throws:
org.alfresco.error.AlfrescoRuntimeException
-
setTestModeRecipient
public void setTestModeRecipient(java.lang.String testModeRecipient)
-
setValidateAddresses
public void setValidateAddresses(boolean validateAddresses)
-
init
public void init()
Description copied from class:ActionExecuterAbstractBaseInit method- Overrides:
initin classActionExecuterAbstractBase
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.ExceptionInitialise bean- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
executeImpl
protected void executeImpl(Action ruleAction, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef)
Send an email message- Specified by:
executeImplin classActionExecuterAbstractBase- Parameters:
ruleAction- the actionactionedUponNodeRef- the actioned upon node- Throws:
org.alfresco.error.AlfrescoRuntimeException
-
prepareEmail
public org.springframework.mail.javamail.MimeMessageHelper prepareEmail(Action ruleAction, org.alfresco.service.cmr.repository.NodeRef actionedUponNodeRef, org.alfresco.util.Pair<java.lang.String,java.util.Locale> recipient, org.alfresco.util.Pair<javax.mail.internet.InternetAddress,java.util.Locale> sender)
-
personExists
public boolean personExists(java.lang.String user)
-
getPerson
public org.alfresco.service.cmr.repository.NodeRef getPerson(java.lang.String user)
-
getPersonEmail
public java.lang.String getPersonEmail(java.lang.String user)
-
addParameterDefinitions
protected void addParameterDefinitions(java.util.List<ParameterDefinition> paramList)
Add the parameter definitions- Specified by:
addParameterDefinitionsin classParameterizedItemAbstractBase- Parameters:
paramList- the parameter definitions list
-
setTestMode
public void setTestMode(boolean testMode)
- Specified by:
setTestModein interfaceTestModeable
-
isTestMode
public boolean isTestMode()
- Specified by:
isTestModein interfaceTestModeable
-
retrieveLastTestMessage
public javax.mail.internet.MimeMessage retrieveLastTestMessage()
Returns the most recent message that wasn't sent because TestMode had been enabled.
-
getTestSentCount
public int getTestSentCount()
-
resetTestSentCount
public int resetTestSentCount()
-
clearLastTestMessage
public void clearLastTestMessage()
Used when test mode is enabled. Clears the record of the last message that was sent.
-
setFromEnabled
public void setFromEnabled(boolean fromEnabled)
-
isFromEnabled
public boolean isFromEnabled()
-
isHTML
public static boolean isHTML(java.lang.String value)
-
onSend
protected void onSend()
-
onFail
protected void onFail()
-
getNumberSuccessfulSends
public int getNumberSuccessfulSends()
-
getNumberFailedSends
public int getNumberFailedSends()
-
-