. 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 f5d9aed0af
commit 15b01c8d5c
6 changed files with 575 additions and 271 deletions

View File

@@ -688,6 +688,7 @@ encoding=Encoding
encoding_utf8=UTF-8
rule_type=Rule Type
rule_background_info=If this option is selected the rule will execute in the background so the results may not appear immediately.
selected_recipients=Select email recipients
# New Space Wizard messages
new_space_title=New Space Wizard

View File

@@ -23,6 +23,9 @@ import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import org.alfresco.config.Config;
@@ -50,6 +53,8 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
@@ -57,6 +62,7 @@ import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.component.UIGenericPicker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -100,9 +106,13 @@ public abstract class BaseActionWizard extends AbstractWizardBean
// new rule/action wizard specific properties
protected boolean multiActionMode = false;
protected String action;
protected ActionService actionService;
protected DictionaryService dictionaryService;
protected MimetypeService mimetypeService;
protected PersonService personService;
protected AuthorityService authorityService;
protected List<SelectItem> actions;
protected List<SelectItem> transformers;
protected List<SelectItem> imageTransformers;
@@ -112,8 +122,18 @@ public abstract class BaseActionWizard extends AbstractWizardBean
protected Map<String, String> actionDescriptions;
protected Map<String, Serializable> currentActionProperties;
protected List<SelectItem> objectTypes;
/** cache of email templates that last 10 seconds - enough for a couple of page refreshes */
protected ExpiringValueCache<List<SelectItem>> cachedTemplates = new ExpiringValueCache<List<SelectItem>>(1000*10);
/** cache of email templates that last 30 seconds - enough for a few page refreshes */
protected ExpiringValueCache<List<SelectItem>> cachedTemplates = new ExpiringValueCache<List<SelectItem>>(1000*30);
/** datamodel for table of selected email recipients */
protected DataModel emailRecipientsDataModel;
/** selected email recipients */
protected List<RecipientWrapper> emailRecipients;
// ------------------------------------------------------------------------------
// Wizard implementation
/**
* Initialises the wizard
@@ -126,6 +146,8 @@ public abstract class BaseActionWizard extends AbstractWizardBean
this.users = null;
this.actions = null;
this.actionDescriptions = null;
this.emailRecipientsDataModel = null;
this.emailRecipients = new ArrayList<RecipientWrapper>(4);
this.currentActionProperties = new HashMap<String, Serializable>(3);
@@ -321,14 +343,20 @@ public abstract class BaseActionWizard extends AbstractWizardBean
}
else if (this.action.equals(MailActionExecuter.NAME))
{
// add the person(s) it's going to as a list of authorities
List<String> recipients = new ArrayList<String>(emailRecipients.size());
for (int i=0; i<emailRecipients.size(); i++)
{
RecipientWrapper wrapper = emailRecipients.get(i);
recipients.add(wrapper.authority);
}
actionParams.put(MailActionExecuter.PARAM_TO_MANY, (Serializable)recipients);
// add the actual email text to send
actionParams.put(MailActionExecuter.PARAM_TEXT,
this.currentActionProperties.get(PROP_MESSAGE));
// add the person it's going to
actionParams.put(MailActionExecuter.PARAM_TO,
this.currentActionProperties.get(PROP_TO));
// add the subject for the email
actionParams.put(MailActionExecuter.PARAM_SUBJECT,
this.currentActionProperties.get(PROP_SUBJECT));
@@ -459,9 +487,32 @@ public abstract class BaseActionWizard extends AbstractWizardBean
String message = (String)actionProps.get(MailActionExecuter.PARAM_TEXT);
this.currentActionProperties.put(PROP_MESSAGE, message);
// handle single email or multiple authority recipients
String to = (String)actionProps.get(MailActionExecuter.PARAM_TO);
if (to != null)
{
this.currentActionProperties.put(PROP_TO, to);
}
else
{
List<String> recipients = (List<String>)actionProps.get(MailActionExecuter.PARAM_TO_MANY);
if (recipients != null && recipients.size() != 0)
{
// rebuild the list of RecipientWrapper objects from the stored action
for (String authority : recipients)
{
this.emailRecipients.add(
new RecipientWrapper(displayLabelForAuthority(authority), authority));
}
}
}
NodeRef templateRef = (NodeRef)actionProps.get(MailActionExecuter.PARAM_TEMPLATE);
if (templateRef != null)
{
this.currentActionProperties.put(PROP_TEMPLATE, templateRef.getId());
}
}
else if (this.action.equals(ImporterActionExecuter.NAME))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER);
@@ -474,6 +525,10 @@ public abstract class BaseActionWizard extends AbstractWizardBean
}
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* @return Returns the selected action
*/
@@ -503,7 +558,7 @@ public abstract class BaseActionWizard extends AbstractWizardBean
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
* @param dictionaryService The dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
@@ -520,6 +575,39 @@ public abstract class BaseActionWizard extends AbstractWizardBean
this.mimetypeService = mimetypeService;
}
/**
* @param personService The personService to set.
*/
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
/**
* @param authorityService The authorityService to set.
*/
public void setAuthorityService(AuthorityService authorityService)
{
this.authorityService = authorityService;
}
/**
* Returns the properties for email recipients JSF DataModel
*
* @return JSF DataModel wrapping the current email recipients
*/
public DataModel getEmailRecipientsDataModel()
{
if (this.emailRecipientsDataModel == null)
{
this.emailRecipientsDataModel = new ListDataModel();
}
this.emailRecipientsDataModel.setWrappedData(this.emailRecipients);
return this.emailRecipientsDataModel;
}
/**
* @return Returns the list of selectable actions
*/
@@ -989,4 +1077,112 @@ public abstract class BaseActionWizard extends AbstractWizardBean
return templates;
}
// ------------------------------------------------------------------------------
// Action event handlers
/**
* Action handler called when the Add button is pressed to add an email recipient
*/
public void addRecipient(ActionEvent event)
{
UIGenericPicker picker = (UIGenericPicker)event.getComponent();
String[] results = picker.getSelectedResults();
if (results != null && results.length != 0)
{
for (String authority : results)
{
// first check the authority has not already been added to the list
boolean alreadyAdded = false;
for (int i=0; i<emailRecipients.size(); i++)
{
RecipientWrapper wrapper = emailRecipients.get(i);
if (wrapper.getAuthority().equals(authority))
{
alreadyAdded = true;
break;
}
}
if (alreadyAdded == false)
{
// find a display label for the authority if it is a known Person
String name = displayLabelForAuthority(authority);
// add the recipient to the list
RecipientWrapper wrapper = new RecipientWrapper(name, authority);
this.emailRecipients.add(wrapper);
}
}
}
}
protected String displayLabelForAuthority(String authority)
{
String label = authority;
if (this.personService.personExists(authority))
{
// create the node ref, then our node representation
NodeRef ref = personService.getPerson(authority);
Node node = new Node(ref);
// setup convience function for current user full name
label = (String)node.getProperties().get(ContentModel.PROP_FIRSTNAME) + ' ' +
(String)node.getProperties().get(ContentModel.PROP_LASTNAME);
}
return label;
}
/**
* Action handler called when the Remove icon is pressed to remove an email recipient
*/
public void removeRecipient(ActionEvent event)
{
RecipientWrapper wrapper = (RecipientWrapper)this.emailRecipientsDataModel.getRowData();
this.emailRecipients.remove(wrapper);
}
// ------------------------------------------------------------------------------
// Inner classes
/**
* Simple wrapper class for email recipient fields
*/
public static class RecipientWrapper
{
public RecipientWrapper(String name, String authority)
{
this.name = name;
this.authority = authority;
}
public String getName()
{
return this.name;
}
public String getAuthority()
{
return this.authority;
}
public boolean equals(Object obj)
{
if (obj instanceof RecipientWrapper)
{
return this.authority.equals( ((RecipientWrapper)obj).getAuthority() );
}
else
{
return false;
}
}
private String name;
private String authority;
}
}

View File

@@ -41,9 +41,16 @@ import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.action.executer.CheckInActionExecuter;
import org.alfresco.repo.action.executer.CopyActionExecuter;
import org.alfresco.repo.action.executer.ImageTransformActionExecuter;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.action.executer.LinkCategoryActionExecuter;
import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter;
import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter;
import org.alfresco.repo.action.executer.TransformActionExecuter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
@@ -1336,7 +1343,7 @@ public class NewRuleWizard extends BaseActionWizard
summary.append(" ");
// define a summary to be added for each action
if ("add-features".equals(actionName))
if (AddFeaturesActionExecuter.NAME.equals(actionName))
{
String aspect = (String)this.currentActionProperties.get(PROP_ASPECT);
@@ -1350,7 +1357,7 @@ public class NewRuleWizard extends BaseActionWizard
}
}
}
else if ("simple-workflow".equals(actionName))
else if (SimpleWorkflowActionExecuter.NAME.equals(actionName))
{
// just leave the summary as the title for now
String approveStepName = (String)this.currentActionProperties.get(PROP_APPROVE_STEP_NAME);
@@ -1382,13 +1389,13 @@ public class NewRuleWizard extends BaseActionWizard
summary.append(rejectMsg);
}
}
else if ("link-category".equals(actionName))
else if (LinkCategoryActionExecuter.NAME.equals(actionName))
{
NodeRef cat = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY);
String name = Repository.getNameForNode(this.nodeService, cat);
summary.append("'").append(name).append("'");
}
else if ("transform".equals(actionName))
else if (TransformActionExecuter.NAME.equals(actionName))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String name = Repository.getNameForNode(this.nodeService, space);
@@ -1408,7 +1415,7 @@ public class NewRuleWizard extends BaseActionWizard
String msg = MessageFormat.format(summary.toString(), new Object[] {name, transformer});
summary = new StringBuilder(msg);
}
else if ("transform-image".equals(actionName))
else if (ImageTransformActionExecuter.NAME.equals(actionName))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String name = Repository.getNameForNode(this.nodeService, space);
@@ -1429,18 +1436,38 @@ public class NewRuleWizard extends BaseActionWizard
String msg = MessageFormat.format(summary.toString(), new Object[] {name, transformer, option});
summary = new StringBuilder(msg);
}
else if ("copy".equals(actionName) || "move".equals(actionName) || "check-out".equals(actionName))
else if (CopyActionExecuter.NAME.equals(actionName) || "move".equals(actionName) || "check-out".equals(actionName))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);
summary.append("'").append(spaceName).append("'");
}
else if ("mail".equals(actionName))
else if (MailActionExecuter.NAME.equals(actionName))
{
String address = (String)this.currentActionProperties.get(PROP_TO);
if (address != null && address.length() != 0)
{
summary.append("'").append(address).append("'");
}
else if ("check-in".equals(actionName))
else
{
if (this.emailRecipients.size() != 0)
{
summary.append("'");
for (int i=0; i<this.emailRecipients.size(); i++)
{
RecipientWrapper wrapper = this.emailRecipients.get(i);
if (i != 0)
{
summary.append(", ");
}
summary.append(wrapper.getName());
}
summary.append("'");
}
}
}
else if (CheckInActionExecuter.NAME.equals(actionName))
{
String comment = (String)this.currentActionProperties.get(PROP_CHECKIN_DESC);
Boolean minorChange = (Boolean)this.currentActionProperties.get(PROP_CHECKIN_MINOR);
@@ -1458,7 +1485,7 @@ public class NewRuleWizard extends BaseActionWizard
String msg = MessageFormat.format(summary.toString(), new Object[] {change, comment});
summary = new StringBuilder(msg);
}
else if ("import".equals(actionName))
else if (ImporterActionExecuter.NAME.equals(actionName))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);

View File

@@ -470,6 +470,14 @@
<property-name>rulesBean</property-name>
<value>#{RulesBean}</value>
</managed-property>
<managed-property>
<property-name>personService</property-name>
<value>#{PersonService}</value>
</managed-property>
<managed-property>
<property-name>authorityService</property-name>
<value>#{AuthorityService}</value>
</managed-property>
</managed-bean>
<managed-bean>
@@ -507,6 +515,14 @@
<property-name>mimetypeService</property-name>
<value>#{MimetypeService}</value>
</managed-property>
<managed-property>
<property-name>personService</property-name>
<value>#{PersonService}</value>
</managed-property>
<managed-property>
<property-name>authorityService</property-name>
<value>#{AuthorityService}</value>
</managed-property>
</managed-bean>
<managed-bean>

View File

@@ -39,8 +39,7 @@
function checkButtonState()
{
if (document.getElementById("action-email:subject").value.length == 0 ||
document.getElementById("action-email:address").value.length == 0)
if (document.getElementById("action-email:subject").value.length == 0)
{
document.getElementById("action-email:next-button").disabled = true;
document.getElementById("action-email:finish-button").disabled = true;
@@ -140,12 +139,12 @@
<tr>
<td colspan="2" class="mainSubTitle"><h:outputText value="#{NewActionWizard.stepTitle}" /></td>
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
<tr>
<td><h:outputText value="#{msg.subject}"/>:</td>
<td width="90%">
<h:inputText id="subject" value="#{NewActionWizard.actionProperties.subject}"
size="75" maxlength="1024"
<h:inputText id="subject" value="#{NewActionWizard.actionProperties.subject}" size="75" maxlength="1024"
onkeyup="javascript:checkButtonState();" />&nbsp;*
</td>
</tr>
@@ -156,7 +155,7 @@
<td valign="top"><h:outputText value="#{msg.message}"/>:</td>
<td>
<h:inputTextarea value="#{NewActionWizard.actionProperties.message}"
rows="5" cols="75" />
rows="4" cols="75" />
</td>
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
@@ -172,15 +171,49 @@
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
<tr><td colspan="2" class="mainSubTitle"><h:outputText value="#{msg.selected_recipients}" /></td></tr>
<tr>
<td></td>
<%-- Picker to select Users/Groups --%>
<td>
<a:genericPicker id="picker" filters="#{InviteSpaceUsersWizard.filters}"
queryCallback="#{InviteSpaceUsersWizard.pickerCallback}"
actionListener="#{NewActionWizard.addRecipient}" />
</td>
</tr>
<tr>
<td valign="top"><h:outputText value="#{msg.to}"/>:</td>
<td>
<h:selectOneMenu id="address" value="#{NewActionWizard.actionProperties.to}"
onchange="javascript:checkButtonState();">
<f:selectItems value="#{NewActionWizard.users}" />
</h:selectOneMenu>
<h:dataTable value="#{NewActionWizard.emailRecipientsDataModel}" var="row"
rowClasses="selectedItemsRow,selectedItemsRowAlt"
styleClass="selectedItems" headerClass="selectedItemsHeader"
cellspacing="0" cellpadding="4"
rendered="#{NewActionWizard.emailRecipientsDataModel.rowCount != 0}">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.name}" />
</f:facet>
<h:outputText value="#{row.name}" />
</h:column>
<h:column>
<a:actionLink actionListener="#{NewActionWizard.removeRecipient}" image="/images/icons/delete.gif"
value="#{msg.remove}" showLink="false" style="padding-left:6px" />
</h:column>
</h:dataTable>
<a:panel id="no-items" rendered="#{NewActionWizard.emailRecipientsDataModel.rowCount == 0}">
<table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>
<tr>
<td colspan='2' class='selectedItemsHeader'><h:outputText id="no-items-name" value="#{msg.name}" /></td>
</tr>
<tr>
<td class='selectedItemsRow'><h:outputText id="no-items-msg" value="#{msg.no_selected_items}" /></td>
</tr>
</table>
</a:panel>
</td>
</tr>
<tr><td class="paddingRow"></td></tr>
<tr>
<td colspan="2"><h:outputText value="#{NewActionWizard.stepInstructions}" /></td>
@@ -194,7 +227,7 @@
<table cellpadding="1" cellspacing="1" border="0">
<tr>
<td align="center">
<h:commandButton id="next-button" value="#{msg.next_button}" action="#{NewActionWizard.next}" styleClass="wizardButton" />
<h:commandButton id="next-button" value="#{msg.next_button}" action="#{NewActionWizard.next}" styleClass="wizardButton" disabled="#{NewActionWizard.emailRecipientsDataModel.rowCount == 0}" />
</td>
</tr>
<tr>

View File

@@ -39,8 +39,7 @@
function checkButtonState()
{
if (document.getElementById("new-rule-email:subject").value.length == 0 ||
document.getElementById("new-rule-email:address").value.length == 0)
if (document.getElementById("new-rule-email:subject").value.length == 0)
{
document.getElementById("new-rule-email:ok-button").disabled = true;
}
@@ -131,8 +130,7 @@
<tr>
<td><h:outputText value="#{msg.subject}"/>:</td>
<td width="90%">
<h:inputText id="subject" value="#{NewRuleWizard.actionProperties.subject}"
size="75" maxlength="1024"
<h:inputText id="subject" value="#{NewRuleWizard.actionProperties.subject}" size="75" maxlength="1024"
onkeyup="javascript:checkButtonState();" />&nbsp;*
</td>
</tr>
@@ -143,7 +141,7 @@
<td valign="top"><h:outputText value="#{msg.message}"/>:</td>
<td>
<h:inputTextarea value="#{NewRuleWizard.actionProperties.message}"
rows="5" cols="75" />
rows="4" cols="75" />
</td>
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
@@ -159,13 +157,46 @@
</tr>
<tr><td colspan="2" class="paddingRow"></td></tr>
<tr><td colspan="2" class="mainSubTitle"><h:outputText value="#{msg.selected_recipients}" /></td></tr>
<tr>
<td></td>
<%-- Picker to select Users/Groups --%>
<td>
<a:genericPicker id="picker" filters="#{InviteSpaceUsersWizard.filters}"
queryCallback="#{InviteSpaceUsersWizard.pickerCallback}"
actionListener="#{NewRuleWizard.addRecipient}" />
</td>
</tr>
<tr>
<td valign="top"><h:outputText value="#{msg.to}"/>:</td>
<td>
<h:selectOneMenu id="address" value="#{NewRuleWizard.actionProperties.to}"
onchange="javascript:checkButtonState();">
<f:selectItems value="#{NewRuleWizard.users}" />
</h:selectOneMenu>
<h:dataTable value="#{NewRuleWizard.emailRecipientsDataModel}" var="row"
rowClasses="selectedItemsRow,selectedItemsRowAlt"
styleClass="selectedItems" headerClass="selectedItemsHeader"
cellspacing="0" cellpadding="4"
rendered="#{NewRuleWizard.emailRecipientsDataModel.rowCount != 0}">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.name}" />
</f:facet>
<h:outputText value="#{row.name}" />
</h:column>
<h:column>
<a:actionLink actionListener="#{NewRuleWizard.removeRecipient}" image="/images/icons/delete.gif"
value="#{msg.remove}" showLink="false" style="padding-left:6px" />
</h:column>
</h:dataTable>
<a:panel id="no-items" rendered="#{NewRuleWizard.emailRecipientsDataModel.rowCount == 0}">
<table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>
<tr>
<td colspan='2' class='selectedItemsHeader'><h:outputText id="no-items-name" value="#{msg.name}" /></td>
</tr>
<tr>
<td class='selectedItemsRow'><h:outputText id="no-items-msg" value="#{msg.no_selected_items}" /></td>
</tr>
</table>
</a:panel>
</td>
</tr>