mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9621 Added invitation (nominated and moderated) processes and JavaDelegate for activiti (WIP)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29449 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -41,7 +41,6 @@
|
|||||||
<property name="dataSource" ref="wrappedDataSource" />
|
<property name="dataSource" ref="wrappedDataSource" />
|
||||||
<property name="transactionManager" ref="transactionManager" />
|
<property name="transactionManager" ref="transactionManager" />
|
||||||
<property name="databaseSchemaUpdate" value="${db.schema.update}" />
|
<property name="databaseSchemaUpdate" value="${db.schema.update}" />
|
||||||
<property name="databaseSchemaDataSource" ref="dataSource" />
|
|
||||||
<property name="history" value="full" />
|
<property name="history" value="full" />
|
||||||
<property name="jobExecutorActivate" value="true" />
|
<property name="jobExecutorActivate" value="true" />
|
||||||
|
|
||||||
|
@@ -377,6 +377,22 @@
|
|||||||
<prop key="mimetype">text/xml</prop>
|
<prop key="mimetype">text/xml</prop>
|
||||||
<prop key="redeploy">false</prop>
|
<prop key="redeploy">false</prop>
|
||||||
</props>
|
</props>
|
||||||
|
|
||||||
|
<!-- Activiti invitation service workflow definition -->
|
||||||
|
<props>
|
||||||
|
<prop key="engineId">activiti</prop>
|
||||||
|
<prop key="location">alfresco/workflow/invitation-moderated.bpmn20.xml</prop>
|
||||||
|
<prop key="mimetype">text/xml</prop>
|
||||||
|
<prop key="redeploy">false</prop>
|
||||||
|
</props>
|
||||||
|
|
||||||
|
<!-- Activiti invitation service workflow definition -->
|
||||||
|
<props>
|
||||||
|
<prop key="engineId">activiti</prop>
|
||||||
|
<prop key="location">alfresco/workflow/invitation-nominated.bpmn20.xml</prop>
|
||||||
|
<prop key="mimetype">text/xml</prop>
|
||||||
|
<prop key="redeploy">false</prop>
|
||||||
|
</props>
|
||||||
</list>
|
</list>
|
||||||
</property>
|
</property>
|
||||||
<property name="models">
|
<property name="models">
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
<startEvent id="start"
|
<startEvent id="start"
|
||||||
activiti:formKey="wf:submitAdhocTask" />
|
activiti:formKey="wf:submitAdhocTask" />
|
||||||
|
|
||||||
<sequenceFlow id='flow1'
|
<sequenceFlow id='flow1'
|
||||||
sourceRef='start'
|
sourceRef='start'
|
||||||
targetRef='adhocTask' />
|
targetRef='adhocTask' />
|
||||||
|
63
config/alfresco/workflow/invitation-moderated.bpmn20.xml
Normal file
63
config/alfresco/workflow/invitation-moderated.bpmn20.xml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
|
||||||
|
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
|
||||||
|
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
|
||||||
|
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
|
||||||
|
|
||||||
|
<process id="activitiInvitationModerated" name="Moderated activiti invitation process">
|
||||||
|
|
||||||
|
<startEvent id="start" activiti:formKey="imwf:moderatedInvitationSubmitTask" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow1" sourceRef="start" targetRef="reviewTask" />
|
||||||
|
|
||||||
|
<userTask id="reviewTask" name="Review Task"
|
||||||
|
activiti:formKey="imwf:moderatedInvitationReviewTask">
|
||||||
|
<extensionElements>
|
||||||
|
<activiti:taskListener event="create"
|
||||||
|
class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
|
||||||
|
<activiti:field name="script">
|
||||||
|
<activiti:string>
|
||||||
|
if (typeof bpm_workflowDueDate != 'undefined')
|
||||||
|
task.setVariable('bpm_dueDate', bpm_workflowDueDate);
|
||||||
|
if (typeof bpm_workflowPriority != 'undefined')
|
||||||
|
task.priority = bpm_workflowPriority;
|
||||||
|
</activiti:string>
|
||||||
|
</activiti:field>
|
||||||
|
</activiti:taskListener>
|
||||||
|
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
|
||||||
|
<activiti:field name="script">
|
||||||
|
<activiti:string>
|
||||||
|
execution.setVariable('wf_reviewOutcome', task.getVariable('wf_reviewOutcome'));
|
||||||
|
execution.setVariable('imwf_reviewer'), person.properties.userName);
|
||||||
|
</activiti:string>
|
||||||
|
</activiti:field>
|
||||||
|
</activiti:taskListener>
|
||||||
|
</extensionElements>
|
||||||
|
<potentialOwner>
|
||||||
|
<resourceAssignmentExpression>
|
||||||
|
<formalExpression>${bpm_groupAssignee.properties.authorityName}
|
||||||
|
</formalExpression>
|
||||||
|
</resourceAssignmentExpression>
|
||||||
|
</potentialOwner>
|
||||||
|
</userTask>
|
||||||
|
|
||||||
|
<sequenceFlow id="flow2" sourceRef="reviewTask" targetRef="reviewDecision" />
|
||||||
|
|
||||||
|
<exclusiveGateway id="reviewDecision" name="Review Decision" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow3" sourceRef="reviewDecision" targetRef="approved">
|
||||||
|
<conditionExpression xsi:type="tFormalExpression">${wf_reviewOutcome == 'Approve'}</conditionExpression>
|
||||||
|
</sequenceFlow>
|
||||||
|
|
||||||
|
<serviceTask id="approved" name="Approved" activiti:class="org.alfresco.repo.invitation.ModerationApproveDelegate" />
|
||||||
|
<sequenceFlow id="flow5" sourceRef="approved" targetRef="end" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow4" sourceRef="reviewDecision" targetRef="rejected" />
|
||||||
|
|
||||||
|
<serviceTask id="rejected" name="Rejected" activiti:class="org.alfresco.repo.invitation.ModerationRejectDelegate" />
|
||||||
|
<sequenceFlow id='flow6' sourceRef='rejected' targetRef='end' />
|
||||||
|
|
||||||
|
<endEvent id="end" />
|
||||||
|
</process>
|
||||||
|
|
||||||
|
</definitions>
|
66
config/alfresco/workflow/invitation-nominated.bpmn20.xml
Normal file
66
config/alfresco/workflow/invitation-nominated.bpmn20.xml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
|
||||||
|
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
|
||||||
|
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
|
||||||
|
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
|
||||||
|
|
||||||
|
<process id="activitiInvitationNominated" name="Nominated activiti invitation process">
|
||||||
|
|
||||||
|
<startEvent id="start" activiti:formKey="inwf:inviteToSiteTask" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow1" sourceRef="start" targetRef="sendInvite" />
|
||||||
|
|
||||||
|
<serviceTask id="sendInvite" name="Send Invite" activiti:class="org.alfresco.repo.invitation.SendInvitationDelegate" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow2" sourceRef="sendInvite" targetRef="invitePending" />
|
||||||
|
|
||||||
|
<userTask id="invitePending" name="Invite Pending"
|
||||||
|
activiti:formKey="inwf:invitePendingTask">
|
||||||
|
<extensionElements>
|
||||||
|
<activiti:taskListener event="create"
|
||||||
|
class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
|
||||||
|
<activiti:field name="script">
|
||||||
|
<activiti:string>
|
||||||
|
if (typeof bpm_workflowDueDate != 'undefined')
|
||||||
|
task.setVariable('bpm_dueDate', bpm_workflowDueDate);
|
||||||
|
if (typeof bpm_workflowPriority != 'undefined')
|
||||||
|
task.priority = bpm_workflowPriority;
|
||||||
|
</activiti:string>
|
||||||
|
</activiti:field>
|
||||||
|
</activiti:taskListener>
|
||||||
|
</extensionElements>
|
||||||
|
<humanPerformer>
|
||||||
|
<resourceAssignmentExpression>
|
||||||
|
<formalExpression>${bpm_assignee.properties.userName}</formalExpression>
|
||||||
|
</resourceAssignmentExpression>
|
||||||
|
</humanPerformer>
|
||||||
|
</userTask>
|
||||||
|
|
||||||
|
<sequenceFlow id="flow3" sourceRef="invitePending" targetRef="inviteGateway" />
|
||||||
|
|
||||||
|
<exclusiveGateway id="inviteGateway" name="Invite Gateway" />
|
||||||
|
|
||||||
|
<sequenceFlow id="flow4" sourceRef="inviteGateway" targetRef="accepted">
|
||||||
|
<conditionExpression xsi:type="tFormalExpression">${inwf_inviteOutcome == 'accept'}</conditionExpression>
|
||||||
|
</sequenceFlow>
|
||||||
|
|
||||||
|
<sequenceFlow id="flow5" sourceRef="inviteGateway" targetRef="rejected">
|
||||||
|
<conditionExpression xsi:type="tFormalExpression">${inwf_inviteOutcome == 'reject'}</conditionExpression>
|
||||||
|
</sequenceFlow>
|
||||||
|
|
||||||
|
<sequenceFlow id="flow7" sourceRef="inviteGateway" targetRef="cancelled" />
|
||||||
|
|
||||||
|
|
||||||
|
<serviceTask id="accepted" name="Accepted" activiti:class="org.alfresco.repo.invitation.AcceptInviteDelegate" />
|
||||||
|
<sequenceFlow id="flow6" sourceRef="accepted" targetRef="end" />
|
||||||
|
|
||||||
|
<serviceTask id="rejected" name="Rejected" activiti:class="org.alfresco.repo.invitation.RejectInviteDelegate" />
|
||||||
|
<sequenceFlow id="flow8" sourceRef="rejected" targetRef="end" />
|
||||||
|
|
||||||
|
<serviceTask id="cancelled" name="Cancelled" activiti:class="org.alfresco.repo.invitation.CancelInviteDelegate" />
|
||||||
|
<sequenceFlow id="flow9" sourceRef="cancelled" targetRef="end" />
|
||||||
|
|
||||||
|
<endEvent id="end" />
|
||||||
|
</process>
|
||||||
|
|
||||||
|
</definitions>
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
|
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation request has
|
||||||
|
* been accepted.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class AcceptInviteDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
final ServiceRegistry serviceRegistry = getServiceRegistry();
|
||||||
|
final MutableAuthenticationDao mutableAuthenticationDao = null; // TODO: (MutableAuthenticationDao) factory.getBean("authenticationDao");
|
||||||
|
final SiteService siteService = serviceRegistry.getSiteService();
|
||||||
|
|
||||||
|
final String inviteeUserName = (String) execution.getVariable(WorkflowModelNominatedInvitation.wfVarInviteeUserName);
|
||||||
|
final String siteShortName = (String) execution.getVariable(WorkflowModelNominatedInvitation.wfVarResourceName);
|
||||||
|
final String inviterUserName = (String) execution.getVariable(WorkflowModelNominatedInvitation.wfVarInviterUserName);
|
||||||
|
final String inviteeSiteRole = (String) execution.getVariable(WorkflowModelNominatedInvitation.wfVarRole);
|
||||||
|
|
||||||
|
// If there is already a user account for the invitee and that account
|
||||||
|
// is disabled, then enable the account because he/she has accepted the
|
||||||
|
// site invitation
|
||||||
|
if ((mutableAuthenticationDao.userExists(inviteeUserName))
|
||||||
|
&& !(mutableAuthenticationDao.getEnabled(inviteeUserName)))
|
||||||
|
{
|
||||||
|
mutableAuthenticationDao.setEnabled(inviteeUserName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Invitee to Site with the site role that the inviter "started" the invite process with
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||||
|
{
|
||||||
|
public Object doWork() throws Exception
|
||||||
|
{
|
||||||
|
siteService.setMembership(siteShortName,
|
||||||
|
inviteeUserName, inviteeSiteRole);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, inviterUserName);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.invitation.site.InviteHelper;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||||
|
import org.alfresco.repo.site.SiteModel;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.invitation.InvitationExceptionForbidden;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation request has
|
||||||
|
* been cancelled.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class CancelInviteDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
private final String MSG_NOT_SITE_MANAGER = "invitation.cancel.not_site_manager";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
// Get the invitee user name and site short name variables off the execution context
|
||||||
|
final String inviteeUserName = (String) execution.getVariable(
|
||||||
|
WorkflowModelNominatedInvitation.wfVarInviteeUserName);
|
||||||
|
final String siteShortName = (String) execution.getVariable(
|
||||||
|
WorkflowModelNominatedInvitation.wfVarResourceName);
|
||||||
|
final String inviteId = (String) execution.getVariable(
|
||||||
|
WorkflowModelNominatedInvitation.wfVarWorkflowInstanceId);
|
||||||
|
|
||||||
|
ServiceRegistry serviceRegistry = getServiceRegistry();
|
||||||
|
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||||
|
PersonService personService = serviceRegistry.getPersonService();
|
||||||
|
SiteService siteService = serviceRegistry.getSiteService();
|
||||||
|
MutableAuthenticationDao mutableAuthenticationDao = null; // TODO: (MutableAuthenticationDao) factory.getBean("authenticationDao");
|
||||||
|
|
||||||
|
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
|
String currentUserSiteRole = siteService.getMembersRole(siteShortName, currentUserName);
|
||||||
|
if ((currentUserSiteRole == null) || (currentUserSiteRole.equals(SiteModel.SITE_MANAGER) == false))
|
||||||
|
{
|
||||||
|
// The current user is not the site manager
|
||||||
|
Object[] args = {currentUserName, inviteId, siteShortName};
|
||||||
|
throw new InvitationExceptionForbidden(MSG_NOT_SITE_MANAGER, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up invitee's user account and person node if they are not in use i.e.
|
||||||
|
// account is still disabled and there are no pending invites outstanding for the
|
||||||
|
// invitee
|
||||||
|
InviteHelper.cleanUpStaleInviteeResources(inviteeUserName, mutableAuthenticationDao, personService,
|
||||||
|
workflowService);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -39,6 +39,8 @@ import org.springframework.beans.factory.BeanFactory;
|
|||||||
* Note - uses a classpath template, rather than a data dictionary template,
|
* Note - uses a classpath template, rather than a data dictionary template,
|
||||||
* so behaves slightly differently to many other mail actions, and can't
|
* so behaves slightly differently to many other mail actions, and can't
|
||||||
* currently be localised easily.
|
* currently be localised easily.
|
||||||
|
*
|
||||||
|
* <b>Same behaviour as {@link ModerationRejectDelegate}</b>
|
||||||
*/
|
*/
|
||||||
public class ModeratedActionReject extends JBPMSpringActionHandler
|
public class ModeratedActionReject extends JBPMSpringActionHandler
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation-moderated process is reviewed
|
||||||
|
* and approved.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class ModerationApproveDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
final String resourceName = (String)execution.getVariable(WorkflowModelModeratedInvitation.wfVarResourceName);
|
||||||
|
final String inviteeUserName = (String)execution.getVariable(WorkflowModelModeratedInvitation.wfVarInviteeUserName);
|
||||||
|
final String inviteeRole = (String)execution.getVariable(WorkflowModelModeratedInvitation.wfVarInviteeRole);
|
||||||
|
final String reviewer = (String)execution.getVariable(WorkflowModelModeratedInvitation.wfVarReviewer);
|
||||||
|
|
||||||
|
final SiteService siteService = getServiceRegistry().getSiteService();
|
||||||
|
|
||||||
|
// Add invitee to the site
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Object>()
|
||||||
|
{
|
||||||
|
public Object doWork() throws Exception
|
||||||
|
{
|
||||||
|
// Add the new user to the web site
|
||||||
|
siteService.setMembership(resourceName, inviteeUserName, inviteeRole);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, reviewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
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.TemplateService;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation-moderated process is reviewed
|
||||||
|
* and rejected.
|
||||||
|
*
|
||||||
|
* <b>Same behaviour as {@link ModeratedActionReject}</b>
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class ModerationRejectDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
private static final String REJECT_TEMPLATE = "/alfresco/bootstrap/invite/moderated-reject-email.ftl";
|
||||||
|
private static final Log logger = LogFactory.getLog(ModerationRejectDelegate.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
final ServiceRegistry serviceRegistry = getServiceRegistry();
|
||||||
|
|
||||||
|
// Do nothing if emails disabled.
|
||||||
|
if(!serviceRegistry.getInvitationService().isSendEmails())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String resourceType = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarResourceType);
|
||||||
|
final String resourceName = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarResourceName);
|
||||||
|
final String inviteeUserName = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarInviteeUserName);
|
||||||
|
final String inviteeRole = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarInviteeRole);
|
||||||
|
final String reviewer = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarReviewer);
|
||||||
|
final String reviewComments = (String) execution.getVariable(WorkflowModelModeratedInvitation.wfVarReviewComments);
|
||||||
|
|
||||||
|
final TemplateService templateService = serviceRegistry.getTemplateService();
|
||||||
|
final ActionService actionService = serviceRegistry.getActionService();
|
||||||
|
|
||||||
|
// send email to the invitee if possible - but don't fail the rejection if email cannot be sent
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Build our model
|
||||||
|
Map<String, Serializable> model = new HashMap<String, Serializable>(8, 1.0f);
|
||||||
|
model.put("resourceName", resourceName);
|
||||||
|
model.put("resourceType", resourceType);
|
||||||
|
model.put("inviteeRole", inviteeRole);
|
||||||
|
model.put("reviewComments", reviewComments);
|
||||||
|
model.put("reviewer", reviewer);
|
||||||
|
model.put("inviteeUserName", inviteeUserName);
|
||||||
|
|
||||||
|
// Process the template
|
||||||
|
// Note - because we use a classpath template, rather than a Data Dictionary
|
||||||
|
// one, we can't have the MailActionExecutor do the template for us
|
||||||
|
String emailMsg = templateService.processTemplate("freemarker", REJECT_TEMPLATE, model);
|
||||||
|
|
||||||
|
// Send
|
||||||
|
Action emailAction = actionService.createAction("mail");
|
||||||
|
emailAction.setParameterValue(MailActionExecuter.PARAM_TO, inviteeUserName);
|
||||||
|
emailAction.setParameterValue(MailActionExecuter.PARAM_FROM, reviewer);
|
||||||
|
emailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Rejected invitation to web site:" + resourceName);
|
||||||
|
emailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, emailMsg);
|
||||||
|
emailAction.setExecuteAsynchronously(true);
|
||||||
|
actionService.executeAction(emailAction, null);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
// Swallow exception
|
||||||
|
logger.error("unable to send reject email", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.invitation.site.InviteHelper;
|
||||||
|
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation request has
|
||||||
|
* been rejected.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class RejectInviteDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
// Get the invitee user name
|
||||||
|
final String inviteeUserName = (String) execution.getVariable(WorkflowModelNominatedInvitation.wfVarInviteeUserName);
|
||||||
|
|
||||||
|
ServiceRegistry serviceRegistry = getServiceRegistry();
|
||||||
|
WorkflowService workflowService = serviceRegistry.getWorkflowService();
|
||||||
|
PersonService personService = serviceRegistry.getPersonService();
|
||||||
|
MutableAuthenticationDao mutableAuthenticationDao = null; // TODO: (MutableAuthenticationDao) factory.getBean("authenticationDao");
|
||||||
|
|
||||||
|
// Clean up invitee's user account and person node if they are not in use i.e.
|
||||||
|
// account is still disabled and there are no pending invites outstanding for the
|
||||||
|
// invitee
|
||||||
|
InviteHelper.cleanUpStaleInviteeResources(inviteeUserName, mutableAuthenticationDao, personService,
|
||||||
|
workflowService);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
|
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.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
|
import org.alfresco.repo.invitation.site.InviteSender;
|
||||||
|
import org.alfresco.repo.jscript.ScriptNode;
|
||||||
|
import org.alfresco.repo.workflow.WorkflowModel;
|
||||||
|
import org.alfresco.repo.workflow.activiti.BaseJavaDelegate;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activiti delegate that is executed when a invitation request has
|
||||||
|
* been sent.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public class SendInvitationDelegate extends BaseJavaDelegate
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(DelegateExecution execution) throws Exception
|
||||||
|
{
|
||||||
|
ServiceRegistry serviceRegistry = getServiceRegistry();
|
||||||
|
|
||||||
|
if(serviceRegistry.getInvitationService().isSendEmails())
|
||||||
|
{
|
||||||
|
// TODO: Get hold of beans
|
||||||
|
// Repository repository = (Repository) factory.getBean("repositoryHelper");
|
||||||
|
// MessageService messageService = (MessageService) factory.getBean("messageService");
|
||||||
|
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
|
||||||
|
|
||||||
|
// TODO: revive, once dependencies can be obtained
|
||||||
|
// InviteSender inviteSender = new InviteSender(serviceRegistry, repository, messageService);
|
||||||
|
|
||||||
|
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(execution, propertyNames);
|
||||||
|
|
||||||
|
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||||
|
ScriptNode packageNode = (ScriptNode) execution.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) execution.getVariable(instanceName);
|
||||||
|
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
||||||
|
|
||||||
|
// TODO: revive, once dependencies can be obtained
|
||||||
|
//inviteSender.sendMail(properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> makePropertiesFromContext(DelegateExecution execution, Collection<String> propertyNames)
|
||||||
|
{
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
for (String name : propertyNames)
|
||||||
|
{
|
||||||
|
String value = (String) execution.getVariable(name);
|
||||||
|
props.put(name, value);
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.workflow.activiti;
|
||||||
|
|
||||||
|
import org.activiti.engine.delegate.JavaDelegate;
|
||||||
|
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||||
|
import org.activiti.engine.impl.context.Context;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all {@link JavaDelegate} used in Alfresco-context.
|
||||||
|
*
|
||||||
|
* @author Frederik Heremans
|
||||||
|
*/
|
||||||
|
public abstract class BaseJavaDelegate implements JavaDelegate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the service-registry from the current Activiti-context.
|
||||||
|
*
|
||||||
|
* @return service registry
|
||||||
|
*/
|
||||||
|
protected ServiceRegistry getServiceRegistry()
|
||||||
|
{
|
||||||
|
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
|
||||||
|
if(config != null)
|
||||||
|
{
|
||||||
|
// Fetch the registry that is injected in the activiti spring-configuration
|
||||||
|
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
|
||||||
|
if(registry == null)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(
|
||||||
|
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
|
||||||
|
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
|
||||||
|
}
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user