mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
. Multiple email recipient support in Create/Edit Rule and Run Action screens.
. Group emailing support added to MailActionExecutor (i.e. selecting Group(s) is supported in the screens as above) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2527 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -252,6 +252,12 @@
|
||||
<property name="authenticationService">
|
||||
<ref bean="authenticationService"></ref>
|
||||
</property>
|
||||
<property name="nodeService">
|
||||
<ref bean="nodeService"></ref>
|
||||
</property>
|
||||
<property name="authorityService">
|
||||
<ref bean="authorityService"></ref>
|
||||
</property>
|
||||
<property name="serviceRegistry">
|
||||
<ref bean="ServiceRegistry"></ref>
|
||||
</property>
|
||||
|
@@ -16,19 +16,25 @@
|
||||
*/
|
||||
package org.alfresco.repo.action.executer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -49,6 +55,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
*/
|
||||
public static final String NAME = "mail";
|
||||
public static final String PARAM_TO = "to";
|
||||
public static final String PARAM_TO_MANY = "to_many";
|
||||
public static final String PARAM_SUBJECT = "subject";
|
||||
public static final String PARAM_TEXT = "text";
|
||||
public static final String PARAM_FROM = "from";
|
||||
@@ -79,6 +86,16 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
*/
|
||||
private AuthenticationService authService;
|
||||
|
||||
/**
|
||||
* The Node Service
|
||||
*/
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* The Authority Service
|
||||
*/
|
||||
private AuthorityService authorityService;
|
||||
|
||||
/**
|
||||
* The Service registry
|
||||
*/
|
||||
@@ -124,6 +141,22 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authorityService the AuthorityService
|
||||
*/
|
||||
public void setAuthorityService(AuthorityService authorityService)
|
||||
{
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the NodeService to set.
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the rule action
|
||||
*/
|
||||
@@ -134,7 +167,59 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
{
|
||||
// Create the simple mail message
|
||||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
|
||||
simpleMailMessage.setTo((String)ruleAction.getParameterValue(PARAM_TO));
|
||||
|
||||
// set recipient
|
||||
String to = (String)ruleAction.getParameterValue(PARAM_TO);
|
||||
if (to != null && to.length() != 0)
|
||||
{
|
||||
simpleMailMessage.setTo(to);
|
||||
}
|
||||
else
|
||||
{
|
||||
// see if multiple recipients have been supplied - as a list of authorities
|
||||
List<String> authorities = (List<String>)ruleAction.getParameterValue(PARAM_TO_MANY);
|
||||
if (authorities != null && authorities.size() != 0)
|
||||
{
|
||||
List<String> recipients = new ArrayList<String>(authorities.size());
|
||||
for (String authority : authorities)
|
||||
{
|
||||
AuthorityType authType = AuthorityType.getAuthorityType(authority);
|
||||
if (authType.equals(AuthorityType.USER))
|
||||
{
|
||||
if (this.personService.personExists(authority) == true)
|
||||
{
|
||||
NodeRef person = this.personService.getPerson(authority);
|
||||
String address = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||
if (address != null && address.length() != 0)
|
||||
{
|
||||
recipients.add(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (authType.equals(AuthorityType.GROUP))
|
||||
{
|
||||
// else notify all members of the group
|
||||
Set<String> users = this.authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
|
||||
for (String userAuth : users)
|
||||
{
|
||||
if (this.personService.personExists(userAuth) == true)
|
||||
{
|
||||
NodeRef person = this.personService.getPerson(authority);
|
||||
String address = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||
if (address != null && address.length() != 0)
|
||||
{
|
||||
recipients.add(address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
simpleMailMessage.setTo(recipients.toArray(new String[recipients.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
// set subject line
|
||||
simpleMailMessage.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT));
|
||||
|
||||
// See if an email template has been specified
|
||||
@@ -154,11 +239,14 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
text = templateService.processTemplate("freemarker", templateRef.toString(), model);
|
||||
}
|
||||
|
||||
// set the text body of the message
|
||||
if (text == null)
|
||||
{
|
||||
text = (String)ruleAction.getParameterValue(PARAM_TEXT);
|
||||
}
|
||||
simpleMailMessage.setText(text);
|
||||
|
||||
// set the from address - use the default if not set
|
||||
String from = (String)ruleAction.getParameterValue(PARAM_FROM);
|
||||
if (from != null)
|
||||
{
|
||||
@@ -187,7 +275,8 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
||||
@Override
|
||||
protected void addParameterDefintions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TO)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_TO)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_TO_MANY, DataTypeDefinition.ANY, false, getParamDisplayLabel(PARAM_TO_MANY)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_FROM, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_FROM)));
|
||||
|
Reference in New Issue
Block a user