mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Workflow:
- Add workflow initiator process variable (Person Node) - Add workflow initiator to WorkflowInstance API Object git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3611 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -66,6 +66,7 @@ import org.hibernate.Session;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.JbpmException;
|
||||
import org.jbpm.context.exe.ContextInstance;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.db.TaskMgmtSession;
|
||||
import org.jbpm.graph.def.Node;
|
||||
@@ -356,18 +357,28 @@ public class JBPMEngine extends BPMEngine
|
||||
{
|
||||
return (WorkflowPath) jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
// initialise jBPM actor (for any processes that wish to record the initiator)
|
||||
context.setActorId(AuthenticationUtil.getCurrentUserName());
|
||||
|
||||
String currentUserName = AuthenticationUtil.getCurrentUserName();
|
||||
context.setActorId(currentUserName);
|
||||
|
||||
// construct a new process
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(getJbpmId(workflowDefinitionId));
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
Token token = processInstance.getRootToken();
|
||||
|
||||
// assign initial process context
|
||||
ContextInstance processContext = processInstance.getContextInstance();
|
||||
NodeRef initiatorPerson = mapNameToAuthority(currentUserName);
|
||||
if (initiatorPerson != null)
|
||||
{
|
||||
processContext.setVariable("initiator", new JBPMNode(initiatorPerson, serviceRegistry));
|
||||
}
|
||||
|
||||
// create the start task if one exists
|
||||
Token token = processInstance.getRootToken();
|
||||
Task startTask = processInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getStartTask();
|
||||
if (startTask != null)
|
||||
{
|
||||
@@ -1507,6 +1518,11 @@ public class JBPMEngine extends BPMEngine
|
||||
workflowInstance.id = createGlobalId(new Long(instance.getId()).toString());
|
||||
workflowInstance.definition = createWorkflowDefinition(instance.getProcessDefinition());
|
||||
workflowInstance.active = !instance.hasEnded();
|
||||
JBPMNode initiator = (JBPMNode)instance.getContextInstance().getVariable("initiator");
|
||||
if (initiator != null)
|
||||
{
|
||||
workflowInstance.initiator = initiator.getNodeRef();
|
||||
}
|
||||
workflowInstance.startDate = instance.getStart();
|
||||
workflowInstance.endDate = instance.getEnd();
|
||||
return workflowInstance;
|
||||
|
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.TaskComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowComponent;
|
||||
@@ -55,6 +56,8 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*/
|
||||
public class JBPMEngineTest extends BaseSpringTest
|
||||
{
|
||||
AuthenticationComponent authenticationComponent;
|
||||
NodeService nodeService;
|
||||
WorkflowComponent workflowComponent;
|
||||
TaskComponent taskComponent;
|
||||
WorkflowDefinition testWorkflowDef;
|
||||
@@ -64,6 +67,10 @@ public class JBPMEngineTest extends BaseSpringTest
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
// run as system
|
||||
authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
|
||||
authenticationComponent.setCurrentUser("admin");
|
||||
|
||||
BPMEngineRegistry registry = (BPMEngineRegistry)applicationContext.getBean("bpm_engineRegistry");
|
||||
workflowComponent = registry.getWorkflowComponent("jbpm");
|
||||
taskComponent = registry.getTaskComponent("jbpm");
|
||||
@@ -82,12 +89,19 @@ public class JBPMEngineTest extends BaseSpringTest
|
||||
assertTrue(workflowComponent.isDefinitionDeployed(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML));
|
||||
|
||||
// get valid node ref
|
||||
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
testNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "spacesStore"));
|
||||
nodeService.setProperty(testNodeRef, ContentModel.PROP_CREATED, new Date());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction()
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
public void testGetWorkflowDefinitions()
|
||||
{
|
||||
List<WorkflowDefinition> workflowDefs = workflowComponent.getDefinitions();
|
||||
@@ -168,6 +182,10 @@ public class JBPMEngineTest extends BaseSpringTest
|
||||
assertTrue(task.properties.containsKey(WorkflowModel.PROP_PRIORITY));
|
||||
assertTrue(task.properties.containsKey(WorkflowModel.PROP_PERCENT_COMPLETE));
|
||||
assertTrue(task.properties.containsKey(ContentModel.PROP_OWNER));
|
||||
|
||||
NodeRef initiator = path.instance.initiator;
|
||||
String initiatorUsername = (String)nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
|
||||
assertEquals("admin", initiatorUsername);
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +341,7 @@ public class JBPMEngineTest extends BaseSpringTest
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask updatedTask = taskComponent.endTask(tasks.get(0).id, path.node.transitions[0].id);
|
||||
assertNotNull(updatedTask);
|
||||
List<WorkflowTask> completedTasks = taskComponent.getAssignedTasks("System", WorkflowTaskState.COMPLETED);
|
||||
List<WorkflowTask> completedTasks = taskComponent.getAssignedTasks("admin", WorkflowTaskState.COMPLETED);
|
||||
assertNotNull(completedTasks);
|
||||
completedTasks = filterTasksByWorkflowInstance(completedTasks, path.instance.id);
|
||||
assertEquals(1, completedTasks.size());
|
||||
@@ -351,7 +369,7 @@ public class JBPMEngineTest extends BaseSpringTest
|
||||
WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).id, null);
|
||||
assertNotNull(updatedTask);
|
||||
assertEquals(WorkflowTaskState.COMPLETED, updatedTask.state);
|
||||
List<WorkflowTask> completedTasks = taskComponent.getAssignedTasks("System", WorkflowTaskState.COMPLETED);
|
||||
List<WorkflowTask> completedTasks = taskComponent.getAssignedTasks("admin", WorkflowTaskState.COMPLETED);
|
||||
assertNotNull(completedTasks);
|
||||
completedTasks = filterTasksByWorkflowInstance(completedTasks, path.instance.id);
|
||||
assertEquals(1, completedTasks.size());
|
||||
|
@@ -19,7 +19,6 @@ package org.alfresco.repo.workflow.jbpm;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.repo.jscript.Node;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
<expression>
|
||||
function result()
|
||||
{
|
||||
return ("Process instance = " + executionContext.processInstance.id + ", testNode children = " + testNode.children.length);
|
||||
return ("Initiator: " + initiator.properties["cm:userName"] + ", process instance = " + executionContext.processInstance.id + ", testNode children = " + testNode.children.length);
|
||||
}
|
||||
result();
|
||||
</expression>
|
||||
|
@@ -18,6 +18,8 @@ package org.alfresco.service.cmr.workflow;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
|
||||
/**
|
||||
* Workflow Instance Data Object
|
||||
@@ -34,11 +36,8 @@ public class WorkflowInstance
|
||||
/** Is this Workflow instance still "in-flight" or has it completed? */
|
||||
public boolean active;
|
||||
|
||||
/** Workflow Definition */
|
||||
public WorkflowDefinition definition;
|
||||
|
||||
/** Start Task Instance (optional) */
|
||||
public WorkflowTask startTask;
|
||||
/** Initiator (cm:person) - null if System initiated */
|
||||
public NodeRef initiator;
|
||||
|
||||
/** Workflow Start Date */
|
||||
public Date startDate;
|
||||
@@ -46,6 +45,9 @@ public class WorkflowInstance
|
||||
/** Workflow End Date */
|
||||
public Date endDate;
|
||||
|
||||
/** Workflow Definition */
|
||||
public WorkflowDefinition definition;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
Reference in New Issue
Block a user