mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
SHA-1627 : CLONE - Create email template
- Hooked a new step into the invite moderated workflow, so as to notify by email all site managers of site join requests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129048 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,7 +35,7 @@ import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVa
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRole;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarServerPath;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -47,13 +47,15 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.admin.SysAdminParams;
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
||||
import org.alfresco.repo.invitation.site.InviteSender;
|
||||
import org.alfresco.repo.invitation.site.InviteNominatedSender;
|
||||
import org.alfresco.repo.invitation.site.InviteModeratedSender;
|
||||
import org.alfresco.repo.invitation.site.InviteSender;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
@@ -126,7 +128,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
||||
private static final Log logger = LogFactory.getLog(InvitationServiceImpl.class);
|
||||
private static final String REJECT_TEMPLATE = "/alfresco/bootstrap/invite/moderated-reject-email.ftl";
|
||||
private static final String MSG_NOT_SITE_MANAGER = "invitation.cancel.not_site_manager";
|
||||
private static final Collection<String> sendInvitePropertyNames = Arrays.asList(wfVarInviteeUserName,//
|
||||
private static final List<String> SEND_INVITE_NOMINATED_PROP_NAMES = Arrays.asList(wfVarInviteeUserName,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviterUserName,//
|
||||
wfVarInviteeUserName,//
|
||||
@@ -137,7 +139,15 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
||||
wfVarServerPath,//
|
||||
wfVarAcceptUrl,//
|
||||
wfVarRejectUrl,
|
||||
InviteSender.WF_INSTANCE_ID);
|
||||
InviteNominatedSender.WF_INSTANCE_ID);
|
||||
|
||||
private static final List<String> SEND_INVITE_MODERATED_PROP_NAMES = Arrays.asList(
|
||||
WorkflowModelModeratedInvitation.wfVarInviteeUserName,
|
||||
WorkflowModelModeratedInvitation.wfVarInviteeRole,
|
||||
WorkflowModelModeratedInvitation.wfVarResourceName,
|
||||
WorkflowModelModeratedInvitation.bpmGroupAssignee,
|
||||
WorkflowModelModeratedInvitation.wfVarResourceType);
|
||||
|
||||
|
||||
/**
|
||||
* Services
|
||||
@@ -161,7 +171,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
||||
private Repository repositoryHelper;
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private MessageService messageService;
|
||||
private InviteSender inviteSender;
|
||||
private InviteNominatedSender inviteNominatedSender;
|
||||
private InviteModeratedSender inviteModeratedSender;
|
||||
|
||||
// maximum number of tries to generate a invitee user name which
|
||||
// does not already belong to an existing person
|
||||
@@ -243,7 +254,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
||||
PropertyCheck.mandatory(this, "PolicyComponent", policyComponent);
|
||||
PropertyCheck.mandatory(this, "templateService", templateService);
|
||||
|
||||
this.inviteSender = new InviteSender(serviceRegistry, repositoryHelper, messageService);
|
||||
this.inviteNominatedSender = new InviteNominatedSender(serviceRegistry, repositoryHelper, messageService);
|
||||
this.inviteModeratedSender = new InviteModeratedSender(serviceRegistry, repositoryHelper, messageService);
|
||||
|
||||
//
|
||||
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
|
||||
@@ -2011,20 +2023,39 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
||||
public void sendNominatedInvitation(String inviteId, String emailTemplateXpath,
|
||||
String emailSubjectKey, Map<String, Object> executionVariables)
|
||||
{
|
||||
sendInviteEmail(inviteNominatedSender, SEND_INVITE_NOMINATED_PROP_NAMES, inviteId, emailTemplateXpath, emailSubjectKey, executionVariables);
|
||||
}
|
||||
|
||||
private void sendInviteEmail(InviteSender inviteSender, List<String> invitePropNames, String inviteId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> executionVariables)
|
||||
{
|
||||
if (isSendEmails())
|
||||
{
|
||||
Map<String, String> properties = makePropertiesFromContextVariables(executionVariables, sendInvitePropertyNames);
|
||||
Map<String, String> properties = makePropertiesFromContextVariables(executionVariables, invitePropNames);
|
||||
|
||||
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||
ScriptNode packageNode = (ScriptNode) executionVariables.get(packageName);
|
||||
String packageRef = packageNode.getNodeRef().toString();
|
||||
properties.put(InviteSender.WF_PACKAGE, packageRef);
|
||||
String packageRef = getPackageRef(executionVariables);
|
||||
properties.put(InviteNominatedSender.WF_PACKAGE, packageRef);
|
||||
|
||||
properties.put(InviteSender.WF_INSTANCE_ID, inviteId);
|
||||
properties.put(InviteNominatedSender.WF_INSTANCE_ID, inviteId);
|
||||
|
||||
inviteSender.sendMail(emailTemplateXpath, emailSubjectKey, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendModeratedInvitation(String inviteId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> executionVariables)
|
||||
{
|
||||
sendInviteEmail(inviteModeratedSender, SEND_INVITE_MODERATED_PROP_NAMES, inviteId, emailTemplateXpath, emailSubjectKey, executionVariables);
|
||||
|
||||
}
|
||||
|
||||
private String getPackageRef(Map<String, Object> executionVariables)
|
||||
{
|
||||
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||
ScriptNode packageNode = (ScriptNode) executionVariables.get(packageName);
|
||||
String packageRef = packageNode.getNodeRef().toString();
|
||||
return packageRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelInvitation(String siteName, String invitee, String inviteId, String currentInviteId)
|
||||
|
@@ -75,5 +75,6 @@ public interface WorkflowModelModeratedInvitation
|
||||
public static final String wfVarResourceName = "imwf_resourceName";
|
||||
public static final String wfVarResourceType = "imwf_resourceType";
|
||||
public static final String wfVarReviewer = "imwf_reviewer";
|
||||
public static final String wfVarReviewComments = "imwf_reviewComments";
|
||||
public static final String wfVarReviewComments = "imwf_reviewComments";
|
||||
public static final String bpmGroupAssignee = "bpm_groupAssignee";
|
||||
}
|
||||
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.invitation.activiti;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.activiti.engine.delegate.DelegateExecution;
|
||||
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
|
||||
|
||||
/**
|
||||
* Activiti delegate that is executed when a invitation request has been sent.
|
||||
*
|
||||
* @author Constantin Popa
|
||||
*/
|
||||
public class SendModeratedInviteDelegate extends AbstractInvitationDelegate
|
||||
{
|
||||
public static final String EMAIL_TEMPLATE_XPATH =
|
||||
"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email-moderated.html.ftl";
|
||||
public static final String EMAIL_SUBJECT_KEY =
|
||||
"invitation.moderated.email.subject";
|
||||
|
||||
@Override
|
||||
public void execute(DelegateExecution execution) throws Exception
|
||||
{
|
||||
String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId();
|
||||
Map<String, Object> variables = execution.getVariables();
|
||||
invitationService.sendModeratedInvitation(invitationId, EMAIL_TEMPLATE_XPATH, EMAIL_SUBJECT_KEY, variables);
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelModeratedInvitation.bpmGroupAssignee;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
import org.alfresco.repo.invitation.WorkflowModelModeratedInvitation;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.util.ModelUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* This class is responsible for sending email notifications to site managers informing about users requesting access.
|
||||
*
|
||||
* @author Constantin Popa
|
||||
*/
|
||||
public class InviteModeratedSender extends InviteSender
|
||||
{
|
||||
public static final String WF_PACKAGE = "wf_package";
|
||||
public static final String SHARE_PENDING_INVITES_LINK = "page/site/{0}/pending-invites";
|
||||
|
||||
private static final List<String> INVITE_MODERATED_EXPECTED_PROPERTIES = Arrays.asList(
|
||||
WorkflowModelModeratedInvitation.wfVarInviteeUserName,
|
||||
WorkflowModelModeratedInvitation.wfVarInviteeRole,
|
||||
WorkflowModelModeratedInvitation.wfVarResourceName,
|
||||
WorkflowModelModeratedInvitation.bpmGroupAssignee,
|
||||
WorkflowModelModeratedInvitation.wfVarResourceType);
|
||||
|
||||
|
||||
public InviteModeratedSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||
{
|
||||
super(services, repository, messageService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties)
|
||||
{
|
||||
checkProperties(properties);
|
||||
NodeRef invitee = personService.getPerson(properties.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName));
|
||||
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_FROM, (String) nodeService.getProperty(invitee, ContentModel.PROP_EMAIL));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TO_MANY, properties.get(bpmGroupAssignee));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, emailSubjectKey);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { getSiteName(properties) });
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) buildMailTextModel(properties));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
||||
actionService.executeAction(mail, new NodeRef(properties.get(WF_PACKAGE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Serializable> buildMailTextModel(Map<String, String> properties)
|
||||
{
|
||||
NodeRef invitee = personService.getPerson(properties.get(WorkflowModelModeratedInvitation.wfVarInviteeUserName));
|
||||
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
||||
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
||||
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
||||
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
||||
|
||||
PersonInfo inviteePerson = personService.getPerson(invitee);
|
||||
model.put("inviteeName", StringUtils.join(new String[] { inviteePerson.getFirstName(), inviteePerson.getLastName() }, " "));
|
||||
model.put("siteName", getSiteName(properties));
|
||||
model.put("sharePendingInvitesLink", MessageFormat.format(SHARE_PENDING_INVITES_LINK, properties.get(WorkflowModelModeratedInvitation.wfVarResourceName)));
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredProperties()
|
||||
{
|
||||
return INVITE_MODERATED_EXPECTED_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getWorkflowPropForSiteName()
|
||||
{
|
||||
return WorkflowModelModeratedInvitation.wfVarResourceName;
|
||||
}
|
||||
}
|
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarAcceptUrl;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteTicket;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeGenPassword;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeUserName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviterUserName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRejectUrl;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRole;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarServerPath;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.util.ModelUtil;
|
||||
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 InviteNominatedSender extends InviteSender
|
||||
{
|
||||
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
||||
public static final String WF_PACKAGE = "wf_package";
|
||||
public static final String SITE_LEAVE_HASH = "#leavesite";
|
||||
private static final String SITE_DASHBOARD_ENDPOINT_PATTERN = "/page/site/{0}/dashboard";
|
||||
|
||||
private static final List<String> INVITE_NOMINATED_EXPECTED_PROPERTIES = Arrays.asList(wfVarInviteeUserName,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviterUserName,//
|
||||
wfVarInviteeUserName,//
|
||||
wfVarRole,//
|
||||
wfVarInviteeGenPassword,//
|
||||
wfVarResourceName,//
|
||||
wfVarInviteTicket,//
|
||||
wfVarServerPath,//
|
||||
wfVarAcceptUrl,//
|
||||
wfVarRejectUrl, WF_INSTANCE_ID,//
|
||||
WF_PACKAGE);
|
||||
|
||||
public InviteNominatedSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||
{
|
||||
super(services, repository, messageService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented for backwards compatibility
|
||||
*
|
||||
* @param properties
|
||||
* @deprecated
|
||||
* @see {@link #sendMail(String, String, Map)}
|
||||
*/
|
||||
public void sendMail(Map<String, String> properties)
|
||||
{
|
||||
sendMail(SendNominatedInviteDelegate.EMAIL_TEMPLATE_XPATH, SendNominatedInviteDelegate.EMAIL_SUBJECT_KEY, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMail(String emailTemplateXpath, String emailSubjectKey, 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, emailSubjectKey);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { ModelUtil.getProductName(repoAdminService), getSiteName(properties) });
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) buildMailTextModel(properties));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
||||
actionService.executeAction(mail, getWorkflowPackage(properties));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Serializable> buildMailTextModel(Map<String, String> properties)
|
||||
{
|
||||
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
||||
NodeRef invitee = personService.getPerson(properties.get(wfVarInviteeUserName));
|
||||
// Set the core model parts
|
||||
// Note - the user part is skipped, as that's implied via the run-as
|
||||
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
||||
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
||||
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
||||
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
||||
|
||||
// Build up the args for rendering inside the template
|
||||
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
||||
model.put("args", (Serializable) args);
|
||||
|
||||
// All done
|
||||
return model;
|
||||
}
|
||||
|
||||
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||
{
|
||||
String params = buildUrlParamString(properties);
|
||||
String acceptLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarAcceptUrl), params, null);
|
||||
String rejectLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarRejectUrl), params, null);
|
||||
|
||||
String siteDashboardEndpoint = getSiteDashboardEndpoint(properties);
|
||||
String siteDashboardLink = makeLink(properties.get(wfVarServerPath), siteDashboardEndpoint, null, null);
|
||||
String siteLeaveLink = makeLink(properties.get(wfVarServerPath), siteDashboardEndpoint, null, SITE_LEAVE_HASH);
|
||||
|
||||
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", getRoleName(properties));
|
||||
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
||||
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
||||
args.put("acceptLink", acceptLink);
|
||||
args.put("rejectLink", rejectLink);
|
||||
args.put("siteDashboardLink", siteDashboardLink);
|
||||
args.put("siteLeaveLink", siteLeaveLink);
|
||||
return args;
|
||||
}
|
||||
|
||||
protected String makeLink(String location, String endpoint, String queryParams, String hashParam)
|
||||
{
|
||||
location = location.endsWith("/") ? location : location + "/";
|
||||
endpoint = endpoint.startsWith("/") ? endpoint.substring(1) : endpoint;
|
||||
if (queryParams != null)
|
||||
{
|
||||
queryParams = queryParams.startsWith("?") ? queryParams : "?" + queryParams;
|
||||
}
|
||||
else
|
||||
{
|
||||
queryParams = "";
|
||||
}
|
||||
if (hashParam != null)
|
||||
{
|
||||
hashParam = hashParam.startsWith("#") ? hashParam : "#" + hashParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashParam = "";
|
||||
}
|
||||
return location + endpoint + queryParams + hashParam;
|
||||
}
|
||||
|
||||
private String getRoleName(Map<String, String> properties)
|
||||
{
|
||||
String roleName = properties.get(wfVarRole);
|
||||
String role = messageService.getMessage("invitation.invitesender.email.role." + roleName);
|
||||
if (role == null)
|
||||
{
|
||||
role = roleName;
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
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 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 getSiteDashboardEndpoint(Map<String, String> properties)
|
||||
{
|
||||
String siteName = properties.get(wfVarResourceName);
|
||||
return MessageFormat.format(SITE_DASHBOARD_ENDPOINT_PATTERN, siteName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredProperties()
|
||||
{
|
||||
return INVITE_NOMINATED_EXPECTED_PROPERTIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getWorkflowPropForSiteName()
|
||||
{
|
||||
return wfVarResourceName;
|
||||
}
|
||||
}
|
@@ -26,85 +26,46 @@
|
||||
|
||||
package org.alfresco.repo.invitation.site;
|
||||
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarAcceptUrl;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteTicket;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeGenPassword;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviteeUserName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarInviterUserName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRejectUrl;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarRole;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarServerPath;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
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.i18n.MessageService;
|
||||
import org.alfresco.repo.invitation.activiti.SendNominatedInviteDelegate;
|
||||
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.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
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.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.util.ModelUtil;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
import org.springframework.extensions.surf.util.URLEncoder;
|
||||
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.wfVarResourceName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
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.alfresco.service.namespace.NamespaceService;
|
||||
|
||||
/**
|
||||
* This class is responsible for sending email invitations, allowing nominated
|
||||
* user's to join a Site.
|
||||
* Notifies the necessary user(s) of a pending site membership invitation/request.
|
||||
*
|
||||
* @author Nick Smith
|
||||
*/
|
||||
public class InviteSender
|
||||
public abstract class InviteSender
|
||||
{
|
||||
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
||||
public static final String WF_PACKAGE = "wf_package";
|
||||
public static final String SITE_LEAVE_HASH = "#leavesite";
|
||||
private static final String SITE_DASHBOARD_ENDPOINT_PATTERN = "/page/site/{0}/dashboard";
|
||||
|
||||
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 Repository repository;
|
||||
private final MessageService messageService;
|
||||
private final FileFolderService fileFolderService;
|
||||
// private final SysAdminParams sysAdminParams;
|
||||
private final RepoAdminService repoAdminService;
|
||||
private final NamespaceService namespaceService;
|
||||
protected final ActionService actionService;
|
||||
protected final NodeService nodeService;
|
||||
protected final PersonService personService;
|
||||
protected final SearchService searchService;
|
||||
protected final SiteService siteService;
|
||||
protected final Repository repository;
|
||||
protected final MessageService messageService;
|
||||
protected final FileFolderService fileFolderService;
|
||||
protected final RepoAdminService repoAdminService;
|
||||
protected final NamespaceService namespaceService;
|
||||
|
||||
public InviteSender(ServiceRegistry services, Repository repository, MessageService messageService)
|
||||
{
|
||||
@@ -114,24 +75,11 @@ public class InviteSender
|
||||
this.searchService = services.getSearchService();
|
||||
this.siteService = services.getSiteService();
|
||||
this.fileFolderService = services.getFileFolderService();
|
||||
// this.sysAdminParams = services.getSysAdminParams();
|
||||
this.repoAdminService = services.getRepoAdminService();
|
||||
this.namespaceService = services.getNamespaceService();
|
||||
this.repository = repository;
|
||||
this.messageService = messageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented for backwards compatibility
|
||||
*
|
||||
* @param properties
|
||||
* @deprecated
|
||||
* @see {@link #sendMail(String, String, Map)}
|
||||
*/
|
||||
public void sendMail(Map<String, String> properties)
|
||||
{
|
||||
sendMail(SendNominatedInviteDelegate.EMAIL_TEMPLATE_XPATH, SendNominatedInviteDelegate.EMAIL_SUBJECT_KEY, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an invitation email.
|
||||
@@ -140,128 +88,27 @@ public class InviteSender
|
||||
* @param emailSubjectKey the subject of the email
|
||||
* @param properties A Map containing the properties needed to send the email.
|
||||
*/
|
||||
public void sendMail(String emailTemplateXpath, String emailSubjectKey, 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, emailSubjectKey);
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] {ModelUtil.getProductName(repoAdminService), getSiteName(properties)});
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, getEmailTemplateNodeRef(emailTemplateXpath));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL,
|
||||
(Serializable)buildMailTextModel(properties, inviter, invitee));
|
||||
mail.setParameterValue(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, true);
|
||||
actionService.executeAction(mail, getWorkflowPackage(properties));
|
||||
}
|
||||
public abstract void sendMail(String emailTemplateXpath, String emailSubjectKey, Map<String, String> properties);
|
||||
|
||||
protected abstract Map<String, Serializable> buildMailTextModel(Map<String, String> properties);
|
||||
|
||||
protected abstract List<String> getRequiredProperties();
|
||||
|
||||
/**
|
||||
* @param properties Map<String, String>
|
||||
*/
|
||||
private void checkProperties(Map<String, String> properties)
|
||||
protected void checkProperties(Map<String, String> properties)
|
||||
{
|
||||
Set<String> keys = properties.keySet();
|
||||
if (!keys.containsAll(expectedProperties))
|
||||
if (!keys.containsAll(getRequiredProperties()))
|
||||
{
|
||||
LinkedList<String> missingProperties = new LinkedList<String>(expectedProperties);
|
||||
LinkedList<String> missingProperties = new LinkedList<String>(getRequiredProperties());
|
||||
missingProperties.removeAll(keys);
|
||||
throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Serializable> buildMailTextModel(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||
{
|
||||
// Set the core model parts
|
||||
// Note - the user part is skipped, as that's implied via the run-as
|
||||
Map<String, Serializable> model = new HashMap<String, Serializable>();
|
||||
model.put(TemplateService.KEY_COMPANY_HOME, repository.getCompanyHome());
|
||||
model.put(TemplateService.KEY_USER_HOME, repository.getUserHome(repository.getPerson()));
|
||||
model.put(TemplateService.KEY_PRODUCT_NAME, ModelUtil.getProductName(repoAdminService));
|
||||
|
||||
// Build up the args for rendering inside the template
|
||||
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
||||
model.put("args", (Serializable)args);
|
||||
|
||||
// All done
|
||||
return model;
|
||||
}
|
||||
|
||||
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||
{
|
||||
String params = buildUrlParamString(properties);
|
||||
String acceptLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarAcceptUrl), params, null);
|
||||
String rejectLink = makeLink(properties.get(wfVarServerPath), properties.get(wfVarRejectUrl), params, null);
|
||||
|
||||
String siteDashboardEndpoint = getSiteDashboardEndpoint(properties);
|
||||
String siteDashboardLink = makeLink(properties.get(wfVarServerPath),
|
||||
siteDashboardEndpoint, null, null);
|
||||
String siteLeaveLink = makeLink(properties.get(wfVarServerPath),
|
||||
siteDashboardEndpoint, null, SITE_LEAVE_HASH);
|
||||
|
||||
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", getRoleName(properties));
|
||||
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
||||
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
||||
args.put("acceptLink", acceptLink);
|
||||
args.put("rejectLink", rejectLink);
|
||||
args.put("siteDashboardLink", siteDashboardLink);
|
||||
args.put("siteLeaveLink", siteLeaveLink);
|
||||
return args;
|
||||
}
|
||||
|
||||
protected String makeLink(String location, String endpoint, String queryParams, String hashParam)
|
||||
{
|
||||
location = location.endsWith("/") ? location : location + "/";
|
||||
endpoint = endpoint.startsWith("/") ? endpoint.substring(1) : endpoint;
|
||||
if (queryParams != null)
|
||||
{
|
||||
queryParams = queryParams.startsWith("?") ? queryParams : "?" + queryParams;
|
||||
}
|
||||
else
|
||||
{
|
||||
queryParams = "";
|
||||
}
|
||||
if (hashParam != null)
|
||||
{
|
||||
hashParam = hashParam.startsWith("#") ? hashParam : "#" + hashParam;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashParam = "";
|
||||
}
|
||||
return location + endpoint + queryParams + hashParam;
|
||||
}
|
||||
|
||||
private String getRoleName(Map<String, String> properties)
|
||||
{
|
||||
String roleName = properties.get(wfVarRole);
|
||||
String role = messageService.getMessage("invitation.invitesender.email.role." + roleName);
|
||||
if (role == null)
|
||||
{
|
||||
role = roleName;
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
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(String emailTemplateXPath)
|
||||
protected NodeRef getEmailTemplateNodeRef(String emailTemplateXPath)
|
||||
{
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(repository.getRootHome(),
|
||||
emailTemplateXPath, null,
|
||||
@@ -280,22 +127,9 @@ public class InviteSender
|
||||
}
|
||||
}
|
||||
|
||||
private String buildUrlParamString(Map<String, String> properties)
|
||||
protected String getSiteName(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);
|
||||
String siteFullName = properties.get(getWorkflowPropForSiteName());
|
||||
SiteInfo site = siteService.getSite(siteFullName);
|
||||
if (site == null)
|
||||
throw new InvitationException("The site " + siteFullName + " could not be found.");
|
||||
@@ -307,11 +141,8 @@ public class InviteSender
|
||||
siteName = siteTitle;
|
||||
}
|
||||
return siteName;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getWorkflowPropForSiteName();
|
||||
|
||||
private String getSiteDashboardEndpoint(Map<String, String> properties)
|
||||
{
|
||||
String siteName = properties.get(wfVarResourceName);
|
||||
return MessageFormat.format(SITE_DASHBOARD_ENDPOINT_PATTERN, siteName);
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ package org.alfresco.service.cmr.invitation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.alfresco.service.Auditable;
|
||||
import org.alfresco.service.NotAuditable;
|
||||
|
||||
@@ -324,6 +324,17 @@ public interface InvitationService
|
||||
* @return true if emails are sent on invite.
|
||||
*/
|
||||
@NotAuditable
|
||||
boolean isSendEmails();
|
||||
|
||||
boolean isSendEmails();
|
||||
|
||||
/**
|
||||
*
|
||||
* Sends the site join request notification email using the given template, subject localization key, and variables.
|
||||
*
|
||||
* @param invitationId
|
||||
* @param emailTemplateXpath
|
||||
* @param emailSubjectKey
|
||||
* @param variables
|
||||
*/
|
||||
@Auditable(parameters = { "inviteId" })
|
||||
public void sendModeratedInvitation(String invitationId, String emailTemplateXpath, String emailSubjectKey, Map<String, Object> variables);
|
||||
}
|
||||
|
Reference in New Issue
Block a user