. 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:
Kevin Roast
2006-03-09 13:47:48 +00:00
parent ac2e167b60
commit e49879f557
2 changed files with 133 additions and 38 deletions

View File

@@ -252,6 +252,12 @@
<property name="authenticationService"> <property name="authenticationService">
<ref bean="authenticationService"></ref> <ref bean="authenticationService"></ref>
</property> </property>
<property name="nodeService">
<ref bean="nodeService"></ref>
</property>
<property name="authorityService">
<ref bean="authorityService"></ref>
</property>
<property name="serviceRegistry"> <property name="serviceRegistry">
<ref bean="ServiceRegistry"></ref> <ref bean="ServiceRegistry"></ref>
</property> </property>

View File

@@ -16,19 +16,25 @@
*/ */
package org.alfresco.repo.action.executer; package org.alfresco.repo.action.executer;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; 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.TemplateNode;
import org.alfresco.service.cmr.repository.TemplateService; import org.alfresco.service.cmr.repository.TemplateService;
import org.alfresco.service.cmr.security.AuthenticationService; 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.alfresco.service.cmr.security.PersonService;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -44,11 +50,12 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{ {
private static Log logger = LogFactory.getLog(MailActionExecuter.class); private static Log logger = LogFactory.getLog(MailActionExecuter.class);
/** /**
* Action executor constants * Action executor constants
*/ */
public static final String NAME = "mail"; public static final String NAME = "mail";
public static final String PARAM_TO = "to"; 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_SUBJECT = "subject";
public static final String PARAM_TEXT = "text"; public static final String PARAM_TEXT = "text";
public static final String PARAM_FROM = "from"; public static final String PARAM_FROM = "from";
@@ -58,11 +65,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
* From address * From address
*/ */
public static final String FROM_ADDRESS = "alfresco_repository@alfresco.org"; public static final String FROM_ADDRESS = "alfresco_repository@alfresco.org";
/** /**
* The java mail sender * The java mail sender
*/ */
private JavaMailSender javaMailSender; private JavaMailSender javaMailSender;
/** /**
* The Template service * The Template service
@@ -79,18 +86,28 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
*/ */
private AuthenticationService authService; private AuthenticationService authService;
/**
* The Node Service
*/
private NodeService nodeService;
/**
* The Authority Service
*/
private AuthorityService authorityService;
/** /**
* The Service registry * The Service registry
*/ */
private ServiceRegistry serviceRegistry; private ServiceRegistry serviceRegistry;
/** /**
* @param javaMailSender the java mail sender * @param javaMailSender the java mail sender
*/ */
public void setMailService(JavaMailSender javaMailSender) public void setMailService(JavaMailSender javaMailSender)
{ {
this.javaMailSender = javaMailSender; this.javaMailSender = javaMailSender;
} }
/** /**
* @param templateService the TemplateService * @param templateService the TemplateService
@@ -123,20 +140,88 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{ {
this.serviceRegistry = serviceRegistry; 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 * Execute the rule action
*/ */
@Override @Override
protected void executeImpl( protected void executeImpl(
Action ruleAction, Action ruleAction,
NodeRef actionedUponNodeRef) NodeRef actionedUponNodeRef)
{ {
// Create the simple mail message // Create the simple mail message
SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo((String)ruleAction.getParameterValue(PARAM_TO));
simpleMailMessage.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT)); // 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 // See if an email template has been specified
String text = null; String text = null;
NodeRef templateRef = (NodeRef)ruleAction.getParameterValue(PARAM_TEMPLATE); NodeRef templateRef = (NodeRef)ruleAction.getParameterValue(PARAM_TEMPLATE);
@@ -154,11 +239,14 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
text = templateService.processTemplate("freemarker", templateRef.toString(), model); text = templateService.processTemplate("freemarker", templateRef.toString(), model);
} }
// set the text body of the message
if (text == null) if (text == null)
{ {
text = (String)ruleAction.getParameterValue(PARAM_TEXT); text = (String)ruleAction.getParameterValue(PARAM_TEXT);
} }
simpleMailMessage.setText(text); simpleMailMessage.setText(text);
// set the from address - use the default if not set
String from = (String)ruleAction.getParameterValue(PARAM_FROM); String from = (String)ruleAction.getParameterValue(PARAM_FROM);
if (from != null) if (from != null)
{ {
@@ -171,26 +259,27 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
try try
{ {
// Send the message // Send the message
javaMailSender.send(simpleMailMessage); javaMailSender.send(simpleMailMessage);
} }
catch (Throwable e) catch (Throwable e)
{ {
// don't stop the action but let admins know email is not getting sent // don't stop the action but let admins know email is not getting sent
logger.error("Failed to send email to " + (String)ruleAction.getParameterValue(PARAM_TO), e); logger.error("Failed to send email to " + (String)ruleAction.getParameterValue(PARAM_TO), e);
} }
} }
/** /**
* Add the parameter definitions * Add the parameter definitions
*/ */
@Override @Override
protected void addParameterDefintions(List<ParameterDefinition> paramList) 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_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT))); paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT)));
paramList.add(new ParameterDefinitionImpl(PARAM_FROM, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_FROM))); paramList.add(new ParameterDefinitionImpl(PARAM_FROM, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_FROM)));
paramList.add(new ParameterDefinitionImpl(PARAM_TEMPLATE, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_TEMPLATE))); paramList.add(new ParameterDefinitionImpl(PARAM_TEMPLATE, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_TEMPLATE)));
} }
} }