mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged V3.2 to HEAD
Merged in r17325. Fixing ETHREEOH-3030 Moved some behaviour out of Javascript embedded in nomination-invitation-processdefinition.xml into a Java class SendInviteAction. Added tests to ensure whitespace and special characters are handled properly. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18303 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<!-- Nominated invitation -->
|
||||
|
||||
<process-definition xmlns="urn:jbpm.org:jpdl-3.1"
|
||||
name="inwf:invitation-nominated">
|
||||
name="inwf:invitation-nominated">
|
||||
|
||||
<swimlane name="initiator"/>
|
||||
|
||||
@@ -12,46 +12,7 @@
|
||||
<task name="inwf:inviteToSiteTask" swimlane="initiator" />
|
||||
|
||||
<transition name="sendInvite" to="invitePending">
|
||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
||||
<script>
|
||||
var workflowId = workflowinstanceid;
|
||||
var inviterPerson = people.getPerson(inwf_inviterUserName);
|
||||
var inviteePerson = people.getPerson(inwf_inviteeUserName);
|
||||
var site = siteService.getSite(inwf_resourceName);
|
||||
var siteName = site.shortName;
|
||||
if (site.title.length() > 0)
|
||||
{
|
||||
siteName = site.title;
|
||||
}
|
||||
var params = "?inviteId=" + workflowId +
|
||||
"&inviteeUserName=" + inwf_inviteeUserName +
|
||||
"&siteShortName=" + inwf_resourceName +
|
||||
"&inviteTicket=" + inwf_inviteTicket;
|
||||
var acceptLink = inwf_serverPath + inwf_acceptUrl + params;
|
||||
var rejectLink = inwf_serverPath + inwf_rejectUrl + params;
|
||||
var mail = actions.create("mail");
|
||||
mail.parameters.from = inviterPerson.properties["cm:email"];
|
||||
mail.parameters.to = inviteePerson.properties["cm:email"];
|
||||
mail.parameters.subject = "Invitation to join '" + siteName + "' site";
|
||||
|
||||
var results = search.luceneSearch(" PATH:\"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.ftl\"");
|
||||
var template = results[0];
|
||||
|
||||
var args = [];
|
||||
args["inviteePersonRef"] = inviteePerson.nodeRef.toString();
|
||||
args["inviterPersonRef"] = inviterPerson.nodeRef.toString();
|
||||
args["siteName"] = siteName;
|
||||
args["inviteeSiteRole"] = inwf_inviteeRole;
|
||||
args["inviteeUserName"] = inwf_inviteeUserName;
|
||||
args["inviteeGenPassword"] = inwf_inviteeGenPassword;
|
||||
args["acceptLink"] = acceptLink;
|
||||
args["rejectLink"] = rejectLink;
|
||||
var mail_text = inviteePerson.processTemplate(template, args);
|
||||
|
||||
mail.parameters.text = mail_text;
|
||||
mail.execute(bpm_package);
|
||||
</script>
|
||||
</action>
|
||||
<action class="org.alfresco.repo.invitation.site.SendInviteAction" />
|
||||
</transition>
|
||||
</start-state>
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -80,6 +80,11 @@ public interface WorkflowModelNominatedInvitation
|
||||
public static final String wfVarResourceDescription = "inwf_resourceDescription";
|
||||
public static final String wfVarResourceType = "inwf_resourceType";
|
||||
public static final String wfVarWorkflowInstanceId = "workflowinstanceid";
|
||||
public static final String wfVarRole = "inwf_inviteeRole";
|
||||
public static final String wfVarRole = "inwf_inviteeRole";
|
||||
public static final String wfVarInviteTicket = "inwf_inviteTicket";
|
||||
public static final String wfVarServerPath = "inwf_serverPath";
|
||||
public static final String wfVarAcceptUrl = "inwf_acceptUrl";
|
||||
public static final String wfVarRejectUrl = "inwf_rejectUrl";
|
||||
public static final String wfVarInviteeGenPassword = "inwf_inviteeGenPassword";
|
||||
|
||||
}
|
||||
|
255
source/java/org/alfresco/repo/invitation/site/InviteSender.java
Normal file
255
source/java/org/alfresco/repo/invitation/site/InviteSender.java
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.search.SearcherException;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
|
||||
/**
|
||||
* This class is responsible for sending email invitations, allowing nominated
|
||||
* user's to join a Site.
|
||||
*
|
||||
* @author Nick Smith
|
||||
*/
|
||||
public class InviteSender
|
||||
{
|
||||
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
||||
public static final String WF_PACKAGE = "wf_package";
|
||||
|
||||
private static final List<String> expectedProperties = Arrays.asList(wfVarInviteeUserName,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviterUserName,//
|
||||
wfVarInviteeUserName,//
|
||||
wfVarRole,//
|
||||
wfVarInviteeGenPassword,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviteTicket,//
|
||||
wfVarServerPath,//
|
||||
wfVarAcceptUrl,//
|
||||
wfVarRejectUrl, WF_INSTANCE_ID,//
|
||||
WF_PACKAGE);
|
||||
|
||||
private final ActionService actionService;
|
||||
private final NodeService nodeService;
|
||||
private final PersonService personService;
|
||||
private final SearchService searchService;
|
||||
private final SiteService siteService;
|
||||
private final TemplateService templateService;
|
||||
private final Repository repository;
|
||||
|
||||
public InviteSender(ServiceRegistry services, Repository repository)
|
||||
{
|
||||
this.actionService = services.getActionService();
|
||||
this.nodeService = services.getNodeService();
|
||||
this.personService = services.getPersonService();
|
||||
this.searchService = services.getSearchService();
|
||||
this.siteService = services.getSiteService();
|
||||
this.templateService = services.getTemplateService();
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an invitation email.
|
||||
*
|
||||
* @param properties A Map containing the properties needed to send the
|
||||
* email.
|
||||
*/
|
||||
public void sendMail(Map<String, String> properties)
|
||||
{
|
||||
checkProperties(properties);
|
||||
ParameterCheck.mandatory("Properties", properties);
|
||||
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
||||
String inviteeName = properties.get(wfVarInviteeUserName);
|
||||
NodeRef invitee = personService.getPerson(inviteeName);
|
||||
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_FROM, getEmail(inviter));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TO, getEmail(invitee));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, buildSubject(properties));
|
||||
String mailText = buildMailText(properties, inviter, invitee);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEXT, mailText);
|
||||
actionService.executeAction(mail, getWorkflowPackage(properties));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param properties
|
||||
*/
|
||||
private void checkProperties(Map<String, String> properties)
|
||||
{
|
||||
Set<String> keys = properties.keySet();
|
||||
if (!keys.containsAll(expectedProperties))
|
||||
{
|
||||
LinkedList<String> missingProperties = new LinkedList<String>(expectedProperties);
|
||||
missingProperties.removeAll(keys);
|
||||
throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildSubject(Map<String, String> properties)
|
||||
{
|
||||
return "Invitation to join '" + getSiteName(properties) + "' site";
|
||||
}
|
||||
|
||||
private String buildMailText(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||
{
|
||||
String template = getEmailTemplate();
|
||||
Map<String, Object> model = makeDefaultModel();
|
||||
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
||||
model.put("args", args);
|
||||
return templateService.processTemplate(template, model);
|
||||
}
|
||||
|
||||
private String getEmailTemplate()
|
||||
{
|
||||
NodeRef template = getEmailTemplateNodeRef();
|
||||
return template.toString();
|
||||
}
|
||||
|
||||
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||
{
|
||||
String params = buildUrlParamString(properties);
|
||||
String serverPath = properties.get(wfVarServerPath);
|
||||
String acceptLink = serverPath + properties.get(wfVarAcceptUrl) + params;
|
||||
String rejectLink = serverPath + properties.get(wfVarRejectUrl) + params;
|
||||
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
args.put("inviteePersonRef", invitee.toString());
|
||||
args.put("inviterPersonRef", inviter.toString());
|
||||
args.put("siteName", getSiteName(properties));
|
||||
args.put("inviteeSiteRole", properties.get(wfVarRole));
|
||||
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
||||
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
||||
args.put("acceptLink", acceptLink);
|
||||
args.put("rejectLink", rejectLink);
|
||||
return args;
|
||||
}
|
||||
|
||||
private Map<String, Object> makeDefaultModel()
|
||||
{
|
||||
NodeRef person = repository.getPerson();
|
||||
NodeRef companyHome = repository.getCompanyHome();
|
||||
NodeRef userHome = repository.getUserHome(person);
|
||||
Map<String, Object> model = templateService.buildDefaultModel(person, companyHome, userHome, null, null);
|
||||
return model;
|
||||
}
|
||||
|
||||
private String getEmail(NodeRef person)
|
||||
{
|
||||
return (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||
}
|
||||
|
||||
private NodeRef getWorkflowPackage(Map<String, String> properties)
|
||||
{
|
||||
String packageRef = properties.get(WF_PACKAGE);
|
||||
return new NodeRef(packageRef);
|
||||
}
|
||||
|
||||
private NodeRef getEmailTemplateNodeRef()
|
||||
{
|
||||
StoreRef spacesStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||
String query = " PATH:\"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.ftl\"";
|
||||
|
||||
SearchParameters searchParams = new SearchParameters();
|
||||
searchParams.addStore(spacesStore);
|
||||
searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
searchParams.setQuery(query);
|
||||
|
||||
ResultSet results = null;
|
||||
try
|
||||
{
|
||||
results = searchService.query(searchParams);
|
||||
List<NodeRef> nodeRefs = results.getNodeRefs();
|
||||
if (nodeRefs.size() == 1)
|
||||
return nodeRefs.get(0);
|
||||
else
|
||||
throw new InvitationException("Cannot find the email templatte!");
|
||||
}
|
||||
catch (SearcherException e)
|
||||
{
|
||||
throw new InvitationException("Cannot find the email templatte!", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (results != null)
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
|
||||
private String buildUrlParamString(Map<String, String> properties)
|
||||
{
|
||||
StringBuilder params = new StringBuilder("?inviteId=");
|
||||
params.append(properties.get(WF_INSTANCE_ID));
|
||||
params.append("&inviteeUserName=");
|
||||
params.append(URLEncoder.encode(properties.get(wfVarInviteeUserName)));
|
||||
params.append("&siteShortName=");
|
||||
params.append(properties.get(wfVarResourceName));
|
||||
params.append("&inviteTicket=");
|
||||
params.append(properties.get(wfVarInviteTicket));
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
private String getSiteName(Map<String, String> properties)
|
||||
{
|
||||
String siteFullName = properties.get(wfVarResourceName);
|
||||
SiteInfo site = siteService.getSite(siteFullName);
|
||||
if (site == null)
|
||||
throw new InvitationException("The site " + siteFullName + " could not be found.");
|
||||
|
||||
String siteName = site.getShortName();
|
||||
String siteTitle = site.getTitle();
|
||||
if (siteTitle != null && siteTitle.length() > 0)
|
||||
{
|
||||
siteName = siteTitle;
|
||||
}
|
||||
return siteName;
|
||||
}
|
||||
}
|
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
|
||||
/**
|
||||
* @author Nick Smith
|
||||
*/
|
||||
public class InviteSenderTest extends TestCase
|
||||
{
|
||||
private static final StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_TEST, "test");
|
||||
|
||||
private static final Person inviter = new Person("inviter");
|
||||
private static final Person invitee = new Person("invitee");
|
||||
private static final Person whitespaceInvitee = new Person("First Second\tthird\nFourth\r\nFifth");
|
||||
private static final Person specialCharInvitee = new Person("àâæçéèêëîïôœùûüÿñ");
|
||||
|
||||
private static final NodeRef template = new NodeRef(testStore, "template");
|
||||
|
||||
private static final String siteName = "Full Site Name";
|
||||
private static final String siteShortName = "Site Name";
|
||||
private static final String mailText = "Mail Text";
|
||||
|
||||
private static final String acceptUrl = "/accpet";
|
||||
private static final String rejectUrl = "/reject";
|
||||
private static final String role = "Role";
|
||||
private static final String password = "password";
|
||||
private static final String ticket = "Ticket";
|
||||
private static final String path = testStore + "/path";
|
||||
private static final String packageId = testStore + "/Package";
|
||||
private static final String instanceId = "InstanceId";
|
||||
|
||||
private Action mailAction = mock(Action.class);
|
||||
private SiteInfo siteInfo = mock(SiteInfo.class);
|
||||
private TemplateService templateService;
|
||||
private InviteSender sender;
|
||||
|
||||
public void testSendMailWorkingPath() throws Exception
|
||||
{
|
||||
Map<String, String> properties = buildDefaultProperties();
|
||||
sender.sendMail(properties);
|
||||
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_FROM), eq(inviter.email));
|
||||
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TO), eq(invitee.email));
|
||||
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT),
|
||||
eq("Invitation to join '" + siteShortName + "' site"));
|
||||
|
||||
Map<String, String> argsMap = getArgsMap();
|
||||
assertNotNull(argsMap);
|
||||
assertEquals(siteShortName, argsMap.get("siteName"));
|
||||
assertEquals(invitee.node.toString(), argsMap.get("inviteePersonRef"));
|
||||
assertEquals(inviter.node.toString(), argsMap.get("inviterPersonRef"));
|
||||
assertEquals(siteShortName, argsMap.get("siteName"));
|
||||
assertEquals(role, argsMap.get("inviteeSiteRole"));
|
||||
assertEquals(invitee.name, argsMap.get("inviteeUserName"));
|
||||
assertEquals(password, argsMap.get("inviteeGenPassword"));
|
||||
assertEquals(
|
||||
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=invitee&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
argsMap.get("acceptLink"));
|
||||
assertEquals(
|
||||
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=invitee&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
argsMap.get("rejectLink"));
|
||||
}
|
||||
|
||||
public void testSendMailWithWhitespaceUserName() throws Exception
|
||||
{
|
||||
Map<String, String> properties = buildDefaultProperties();
|
||||
properties.put(wfVarInviteeUserName, whitespaceInvitee.name);
|
||||
sender.sendMail(properties);
|
||||
Map<String, String> argsMap = getArgsMap();
|
||||
String acceptLink = argsMap.get("acceptLink");
|
||||
assertEquals(
|
||||
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=First%20Second%09third%0aFourth%0d%0aFifth&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
acceptLink);
|
||||
String rejectLink = argsMap.get("rejectLink");
|
||||
assertEquals(
|
||||
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=First%20Second%09third%0aFourth%0d%0aFifth&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
rejectLink);
|
||||
}
|
||||
|
||||
public void testSendMailWithSpecialCharUserName() throws Exception
|
||||
{
|
||||
Map<String, String> properties = buildDefaultProperties();
|
||||
properties.put(wfVarInviteeUserName, specialCharInvitee.name);
|
||||
sender.sendMail(properties);
|
||||
Map<String, String> argsMap = getArgsMap();
|
||||
String acceptLink = argsMap.get("acceptLink");
|
||||
assertEquals(
|
||||
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=%c3%a0%c3%a2%c3%a6%c3%a7%c3%a9%c3%a8%c3%aa%c3%ab%c3%ae%c3%af%c3%b4%c5%93%c3%b9%c3%bb%c3%bc%c3%bf%c3%b1&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
acceptLink);
|
||||
String rejectLink = argsMap.get("rejectLink");
|
||||
assertEquals(
|
||||
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=%c3%a0%c3%a2%c3%a6%c3%a7%c3%a9%c3%a8%c3%aa%c3%ab%c3%ae%c3%af%c3%b4%c5%93%c3%b9%c3%bb%c3%bc%c3%bf%c3%b1&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||
rejectLink);
|
||||
}
|
||||
|
||||
private Map<String, String> buildDefaultProperties()
|
||||
{
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(wfVarResourceName, siteName);
|
||||
properties.put(wfVarInviteeUserName, invitee.name);
|
||||
properties.put(wfVarInviterUserName, inviter.name);
|
||||
properties.put(wfVarAcceptUrl, acceptUrl);
|
||||
properties.put(wfVarRejectUrl, rejectUrl);
|
||||
properties.put(wfVarRole, role);
|
||||
properties.put(wfVarInviteeGenPassword, password);
|
||||
properties.put(wfVarInviteTicket, ticket);
|
||||
properties.put(wfVarServerPath, path);
|
||||
properties.put(InviteSender.WF_PACKAGE, packageId);
|
||||
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
||||
return properties;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, String> getArgsMap()
|
||||
{
|
||||
ArgumentCaptor<Map> modelCaptor = ArgumentCaptor.forClass(Map.class);
|
||||
verify(templateService).processTemplate(eq(template.toString()), modelCaptor.capture());
|
||||
Map<String, Serializable> model = modelCaptor.getValue();
|
||||
Map<String, String> argsMap = (Map<String, String>) model.get("args");
|
||||
return argsMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
ServiceRegistry services = mockServices();
|
||||
Repository repository = mockRepository();
|
||||
sender = new InviteSender(services, repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up a Repository that will return the inviter as the current user.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Repository mockRepository()
|
||||
{
|
||||
Repository repository = mock(Repository.class);
|
||||
when(repository.getPerson()).thenReturn(inviter.node);
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private ServiceRegistry mockServices()
|
||||
{
|
||||
ActionService mockActionService = mockActionService();
|
||||
NodeService mockNodeService = mockNodeService();
|
||||
PersonService mockPersonService = mockPersonService();
|
||||
SearchService mockSearchService = mockSearchService();
|
||||
SiteService mockSiteService = mockSiteService();
|
||||
TemplateService mockTemplateService = mockTemplateService();
|
||||
|
||||
ServiceRegistry services = mock(ServiceRegistry.class);
|
||||
when(services.getActionService()).thenReturn(mockActionService);
|
||||
when(services.getNodeService()).thenReturn(mockNodeService);
|
||||
when(services.getPersonService()).thenReturn(mockPersonService);
|
||||
when(services.getSearchService()).thenReturn(mockSearchService);
|
||||
when(services.getSiteService()).thenReturn(mockSiteService);
|
||||
when(services.getTemplateService()).thenReturn(mockTemplateService);
|
||||
return services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up a TemplateService that returns an empty HashMap when
|
||||
* buildDefaultModel() is called.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private TemplateService mockTemplateService()
|
||||
{
|
||||
this.templateService = mock(TemplateService.class);
|
||||
when(templateService.buildDefaultModel(inviter.node, null, null, null, null)).thenAnswer(
|
||||
new Answer<Map<String, Object>>()
|
||||
{
|
||||
public Map<String, Object> answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
});
|
||||
when(templateService.processTemplate(anyString(), any())).thenReturn(mailText);
|
||||
return templateService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up a SiteService that returns appropriate SiteInfo.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private SiteService mockSiteService()
|
||||
{
|
||||
SiteService siteService = mock(SiteService.class);
|
||||
when(siteInfo.getShortName()).thenReturn(siteShortName);
|
||||
when(siteService.getSite(siteName)).thenReturn(siteInfo);
|
||||
return siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up a SearchService that will return the template NodeRef when
|
||||
* queried.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private SearchService mockSearchService()
|
||||
{
|
||||
SearchService searchService = mock(SearchService.class);
|
||||
ResultSet results = mock(ResultSet.class);
|
||||
List<NodeRef> nodeRefs = Arrays.asList(template);
|
||||
when(results.getNodeRefs()).thenReturn(nodeRefs);
|
||||
when(searchService.query((SearchParameters) any())).thenReturn(results);
|
||||
return searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up a PersonService that returns the correct NodeRef when given a
|
||||
* user name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private PersonService mockPersonService()
|
||||
{
|
||||
PersonService personService = mock(PersonService.class);
|
||||
when(personService.getPerson(inviter.name)).thenReturn(inviter.node);
|
||||
when(personService.getPerson(invitee.name)).thenReturn(invitee.node);
|
||||
when(personService.getPerson(whitespaceInvitee.name)).thenReturn(whitespaceInvitee.node);
|
||||
when(personService.getPerson(specialCharInvitee.name)).thenReturn(specialCharInvitee.node);
|
||||
return personService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up NodeService to return email adresses for inviter and invitee.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private NodeService mockNodeService()
|
||||
{
|
||||
NodeService nodeService = mock(NodeService.class);
|
||||
when(nodeService.getProperty(inviter.node, ContentModel.PROP_EMAIL)).thenReturn(inviter.email);
|
||||
when(nodeService.getProperty(invitee.node, ContentModel.PROP_EMAIL)).thenReturn(invitee.email);
|
||||
when(nodeService.getProperty(whitespaceInvitee.node, ContentModel.PROP_EMAIL)).thenReturn(
|
||||
whitespaceInvitee.email);
|
||||
when(nodeService.getProperty(specialCharInvitee.node, ContentModel.PROP_EMAIL)).thenReturn(
|
||||
specialCharInvitee.email);
|
||||
return nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks up an ActionService which returns the mailAction field when
|
||||
* createAction() is called.
|
||||
*
|
||||
* @return ActionService
|
||||
*/
|
||||
private ActionService mockActionService()
|
||||
{
|
||||
ActionService actionService = mock(ActionService.class);
|
||||
when(actionService.createAction(MailActionExecuter.NAME)).thenReturn(mailAction);
|
||||
return actionService;
|
||||
}
|
||||
|
||||
private static class Person
|
||||
{
|
||||
public final String name;
|
||||
public final String email;
|
||||
public final NodeRef node;
|
||||
|
||||
public Person(String name)
|
||||
{
|
||||
this.name = name;
|
||||
String encName = URLEncoder.encode(name);
|
||||
this.email = encName + "@test.com";
|
||||
this.node = new NodeRef(testStore, encName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.jbpm.graph.exe.ExecutionContext;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
public class SendInviteAction extends JBPMSpringActionHandler
|
||||
{
|
||||
// TODO Select Version Id.
|
||||
private static final long serialVersionUID = 8133039174866049136L;
|
||||
|
||||
private InviteSender inviteSender;
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
@Override
|
||||
protected void initialiseHandler(BeanFactory factory)
|
||||
{
|
||||
Repository repository = (Repository) factory.getBean("repositoryHelper");
|
||||
ServiceRegistry services = (ServiceRegistry) factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
inviteSender = new InviteSender(services, repository);
|
||||
namespaceService = services.getNamespaceService();
|
||||
}
|
||||
|
||||
public void execute(final ExecutionContext context) throws Exception
|
||||
{
|
||||
|
||||
Collection<String> propertyNames = Arrays.asList(wfVarInviteeUserName,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviterUserName,//
|
||||
wfVarInviteeUserName,//
|
||||
wfVarRole,//
|
||||
wfVarInviteeGenPassword,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviteTicket,//
|
||||
wfVarServerPath,//
|
||||
wfVarAcceptUrl,//
|
||||
wfVarRejectUrl,
|
||||
InviteSender.WF_INSTANCE_ID);
|
||||
Map<String, String> properties = makePropertiesFromContext(context, propertyNames);
|
||||
|
||||
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||
ScriptNode packageNode = (ScriptNode) context.getVariable(packageName);
|
||||
String packageRef = packageNode.getNodeRef().toString();
|
||||
properties.put(InviteSender.WF_PACKAGE, packageRef);
|
||||
|
||||
String instanceName=WorkflowModel.PROP_WORKFLOW_INSTANCE_ID.toPrefixString(namespaceService).replace(":", "_");
|
||||
String instanceId = (String) context.getVariable(instanceName);
|
||||
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
||||
inviteSender.sendMail(properties);
|
||||
}
|
||||
|
||||
private Map<String, String> makePropertiesFromContext(ExecutionContext context, Collection<String> propertyNames)
|
||||
{
|
||||
Map<String, String> props = new HashMap<String, String>();
|
||||
for (String name : propertyNames)
|
||||
{
|
||||
String value = (String) context.getVariable(name);
|
||||
props.put(name, value);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user