mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,163 +1,163 @@
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.springmodules.workflow.jbpm31.JbpmCallback;
|
||||
import org.springmodules.workflow.jbpm31.JbpmTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* Test Usage of jBPM within Alfresco Spring Context
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class JBPMSpringTest extends BaseSpringTest
|
||||
{
|
||||
JbpmTemplate jbpmTemplate;
|
||||
DescriptorService descriptorService;
|
||||
|
||||
|
||||
//@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpm_template");
|
||||
descriptorService = (DescriptorService)applicationContext.getBean("DescriptorService");
|
||||
}
|
||||
|
||||
public void testHelloWorld()
|
||||
throws Exception
|
||||
{
|
||||
deployProcessDefinition();
|
||||
processInstanceIsCreatedWhenUserSubmitsWebappForm();
|
||||
theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
|
||||
undeployProcessDefinition();
|
||||
}
|
||||
|
||||
private void deployProcessDefinition()
|
||||
{
|
||||
// This test shows a process definition and one execution
|
||||
// of the process definition. The process definition has
|
||||
// 3 nodes: an unnamed start-state, a state 's' and an
|
||||
// end-state named 'end'.
|
||||
final ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
|
||||
"<process-definition name='hello world'>" +
|
||||
" <start-state name='start'>" +
|
||||
" <transition to='s' />" +
|
||||
" </start-state>" +
|
||||
" <node name='s'>" +
|
||||
" <action class='org.alfresco.repo.workflow.jbpm.JBPMTestSpringActionHandler' config-type='bean'>" +
|
||||
" <value>a test value</value>" +
|
||||
" </action>" +
|
||||
" <transition to='end' />" +
|
||||
" </node>" +
|
||||
" <end-state name='end' />" +
|
||||
"</process-definition>"
|
||||
);
|
||||
|
||||
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
context.deployProcessDefinition(processDefinition);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void undeployProcessDefinition()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
graphSession.deleteProcessDefinition(processDefinition.getId());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processInstanceIsCreatedWhenUserSubmitsWebappForm()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// With the processDefinition that we retrieved from the database, we
|
||||
// can create an execution of the process definition just like in the
|
||||
// hello world example (which was without persistence).
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
|
||||
Token token = processInstance.getRootToken();
|
||||
assertEquals("start", token.getNode().getName());
|
||||
// Let's start the process execution
|
||||
token.signal();
|
||||
// Now the process is in the state 's'.
|
||||
assertEquals("s", token.getNode().getName());
|
||||
// Spring based action has been called, check the result by looking at the
|
||||
// process variable set by the action
|
||||
String result = "Repo: " + descriptorService.getServerDescriptor().getVersion() + ", Value: a test value, Node: s, Token: /";
|
||||
assertEquals(result, processInstance.getContextInstance().getVariable("jbpm.test.action.result"));
|
||||
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
|
||||
// First, we need to get the process instance back out of the database.
|
||||
// There are several options to know what process instance we are dealing
|
||||
// with here. The easiest in this simple test case is just to look for
|
||||
// the full list of process instances. That should give us only one
|
||||
// result. So let's look up the process definition.
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// Now, we search for all process instances of this process definition.
|
||||
List<?> processInstances = graphSession.findProcessInstances(processDefinition.getId());
|
||||
|
||||
// Because we know that in the context of this unit test, there is
|
||||
// only one execution. In real life, the processInstanceId can be
|
||||
// extracted from the content of the message that arrived or from
|
||||
// the user making a choice.
|
||||
ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
|
||||
|
||||
// Now we can continue the execution. Note that the processInstance
|
||||
// delegates signals to the main path of execution (=the root token).
|
||||
processInstance.signal();
|
||||
|
||||
// After this signal, we know the process execution should have
|
||||
// arrived in the end-state.
|
||||
assertTrue(processInstance.hasEnded());
|
||||
|
||||
// Now we can update the state of the execution in the database
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.springmodules.workflow.jbpm31.JbpmCallback;
|
||||
import org.springmodules.workflow.jbpm31.JbpmTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* Test Usage of jBPM within Alfresco Spring Context
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class JBPMSpringTest extends BaseSpringTest
|
||||
{
|
||||
JbpmTemplate jbpmTemplate;
|
||||
DescriptorService descriptorService;
|
||||
|
||||
|
||||
//@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
jbpmTemplate = (JbpmTemplate)applicationContext.getBean("jbpm_template");
|
||||
descriptorService = (DescriptorService)applicationContext.getBean("DescriptorService");
|
||||
}
|
||||
|
||||
public void testHelloWorld()
|
||||
throws Exception
|
||||
{
|
||||
deployProcessDefinition();
|
||||
processInstanceIsCreatedWhenUserSubmitsWebappForm();
|
||||
theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
|
||||
undeployProcessDefinition();
|
||||
}
|
||||
|
||||
private void deployProcessDefinition()
|
||||
{
|
||||
// This test shows a process definition and one execution
|
||||
// of the process definition. The process definition has
|
||||
// 3 nodes: an unnamed start-state, a state 's' and an
|
||||
// end-state named 'end'.
|
||||
final ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
|
||||
"<process-definition name='hello world'>" +
|
||||
" <start-state name='start'>" +
|
||||
" <transition to='s' />" +
|
||||
" </start-state>" +
|
||||
" <node name='s'>" +
|
||||
" <action class='org.alfresco.repo.workflow.jbpm.JBPMTestSpringActionHandler' config-type='bean'>" +
|
||||
" <value>a test value</value>" +
|
||||
" </action>" +
|
||||
" <transition to='end' />" +
|
||||
" </node>" +
|
||||
" <end-state name='end' />" +
|
||||
"</process-definition>"
|
||||
);
|
||||
|
||||
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
context.deployProcessDefinition(processDefinition);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void undeployProcessDefinition()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
graphSession.deleteProcessDefinition(processDefinition.getId());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processInstanceIsCreatedWhenUserSubmitsWebappForm()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// With the processDefinition that we retrieved from the database, we
|
||||
// can create an execution of the process definition just like in the
|
||||
// hello world example (which was without persistence).
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
|
||||
Token token = processInstance.getRootToken();
|
||||
assertEquals("start", token.getNode().getName());
|
||||
// Let's start the process execution
|
||||
token.signal();
|
||||
// Now the process is in the state 's'.
|
||||
assertEquals("s", token.getNode().getName());
|
||||
// Spring based action has been called, check the result by looking at the
|
||||
// process variable set by the action
|
||||
String result = "Repo: " + descriptorService.getServerDescriptor().getVersion() + ", Value: a test value, Node: s, Token: /";
|
||||
assertEquals(result, processInstance.getContextInstance().getVariable("jbpm.test.action.result"));
|
||||
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived()
|
||||
{
|
||||
jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
GraphSession graphSession = context.getGraphSession();
|
||||
|
||||
// First, we need to get the process instance back out of the database.
|
||||
// There are several options to know what process instance we are dealing
|
||||
// with here. The easiest in this simple test case is just to look for
|
||||
// the full list of process instances. That should give us only one
|
||||
// result. So let's look up the process definition.
|
||||
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("hello world");
|
||||
|
||||
// Now, we search for all process instances of this process definition.
|
||||
List<?> processInstances = graphSession.findProcessInstances(processDefinition.getId());
|
||||
|
||||
// Because we know that in the context of this unit test, there is
|
||||
// only one execution. In real life, the processInstanceId can be
|
||||
// extracted from the content of the message that arrived or from
|
||||
// the user making a choice.
|
||||
ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
|
||||
|
||||
// Now we can continue the execution. Note that the processInstance
|
||||
// delegates signals to the main path of execution (=the root token).
|
||||
processInstance.signal();
|
||||
|
||||
// After this signal, we know the process execution should have
|
||||
// arrived in the end-state.
|
||||
assertTrue(processInstance.hasEnded());
|
||||
|
||||
// Now we can update the state of the execution in the database
|
||||
context.save(processInstance);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,138 +1,138 @@
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* JBPM Workflow Service Implementation Tests
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 3.4.e
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class JbpmWorkflowServiceIntegrationTest extends AbstractWorkflowServiceIntegrationTest
|
||||
{
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void disabledTestAsynchronousTaskExecutes() throws Exception
|
||||
{
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
String defId = null;
|
||||
String instanceId = null;
|
||||
try
|
||||
{
|
||||
WorkflowDefinition def = deployDefinition(getAsyncAdhocPath());
|
||||
defId = def.getId();
|
||||
|
||||
// Create workflow parameters
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
Serializable wfPackage = workflowService.createPackage(null);
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage);
|
||||
Date dueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
|
||||
NodeRef assignee = personManager.get(USER2);
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
|
||||
|
||||
WorkflowPath path = workflowService.startWorkflow(defId, params);
|
||||
instanceId = path.getInstance().getId();
|
||||
|
||||
// End the Start Task.
|
||||
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask startTask = tasks.get(0);
|
||||
workflowService.endTask(startTask.getId(), null);
|
||||
|
||||
// Wait for async execution to occur.
|
||||
Thread.sleep(1000);
|
||||
|
||||
// Should move past the asynchronous adhoc task.
|
||||
tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask endTask = tasks.get(0);
|
||||
assertEquals("wf:completedAdhocTask", endTask.getName());
|
||||
|
||||
// Check async task assigned to USER2
|
||||
tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask adhocTask = tasks.get(0);
|
||||
assertEquals("wf:adhocTask", adhocTask.getName());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(instanceId != null)
|
||||
{
|
||||
workflowService.cancelWorkflow(instanceId);
|
||||
}
|
||||
if(defId != null)
|
||||
{
|
||||
workflowService.undeployDefinition(defId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String getAsyncAdhocPath()
|
||||
{
|
||||
return "jbpmresources/async_adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEngine()
|
||||
{
|
||||
return JBPMEngine.ENGINE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_simple_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAdhocDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPooledReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/review_pooled_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getParallelReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/parallelreview_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestTimerDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_timer.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QName getAdhocProcessName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhoc");
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* JBPM Workflow Service Implementation Tests
|
||||
*
|
||||
* @author Nick Smith
|
||||
* @since 3.4.e
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class JbpmWorkflowServiceIntegrationTest extends AbstractWorkflowServiceIntegrationTest
|
||||
{
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void disabledTestAsynchronousTaskExecutes() throws Exception
|
||||
{
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
String defId = null;
|
||||
String instanceId = null;
|
||||
try
|
||||
{
|
||||
WorkflowDefinition def = deployDefinition(getAsyncAdhocPath());
|
||||
defId = def.getId();
|
||||
|
||||
// Create workflow parameters
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
Serializable wfPackage = workflowService.createPackage(null);
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage);
|
||||
Date dueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
|
||||
NodeRef assignee = personManager.get(USER2);
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
|
||||
|
||||
WorkflowPath path = workflowService.startWorkflow(defId, params);
|
||||
instanceId = path.getInstance().getId();
|
||||
|
||||
// End the Start Task.
|
||||
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask startTask = tasks.get(0);
|
||||
workflowService.endTask(startTask.getId(), null);
|
||||
|
||||
// Wait for async execution to occur.
|
||||
Thread.sleep(1000);
|
||||
|
||||
// Should move past the asynchronous adhoc task.
|
||||
tasks = workflowService.getTasksForWorkflowPath(path.getId());
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask endTask = tasks.get(0);
|
||||
assertEquals("wf:completedAdhocTask", endTask.getName());
|
||||
|
||||
// Check async task assigned to USER2
|
||||
tasks = workflowService.getAssignedTasks(USER2, WorkflowTaskState.IN_PROGRESS);
|
||||
assertEquals(1, tasks.size());
|
||||
WorkflowTask adhocTask = tasks.get(0);
|
||||
assertEquals("wf:adhocTask", adhocTask.getName());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(instanceId != null)
|
||||
{
|
||||
workflowService.cancelWorkflow(instanceId);
|
||||
}
|
||||
if(defId != null)
|
||||
{
|
||||
workflowService.undeployDefinition(defId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String getAsyncAdhocPath()
|
||||
{
|
||||
return "jbpmresources/async_adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEngine()
|
||||
{
|
||||
return JBPMEngine.ENGINE_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_simple_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAdhocDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/adhoc_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPooledReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/review_pooled_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getParallelReviewDefinitionPath()
|
||||
{
|
||||
return "alfresco/workflow/parallelreview_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestTimerDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_timer.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QName getAdhocProcessName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhoc");
|
||||
}
|
||||
}
|
||||
|
@@ -1,163 +1,163 @@
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.TaskComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
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.security.PersonService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.BaseSpringTestsCategory;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
/**
|
||||
* Review and Approve workflow specific Tests
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@Category(BaseSpringTestsCategory.class)
|
||||
public class ReviewAndApproveTest extends BaseSpringTest
|
||||
{
|
||||
AuthenticationComponent authenticationComponent;
|
||||
PersonService personService;
|
||||
WorkflowComponent workflowComponent;
|
||||
TaskComponent taskComponent;
|
||||
WorkflowDefinition testWorkflowDef;
|
||||
NodeRef testNodeRef;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
personService = (PersonService)applicationContext.getBean("personService");
|
||||
BPMEngineRegistry registry = (BPMEngineRegistry)applicationContext.getBean("bpm_engineRegistry");
|
||||
workflowComponent = registry.getWorkflowComponent(JBPMEngine.ENGINE_ID);
|
||||
taskComponent = registry.getTaskComponent(JBPMEngine.ENGINE_ID);
|
||||
|
||||
// deploy latest review and approve process definition
|
||||
ClassPathResource processDef = new ClassPathResource("alfresco/workflow/review_processdefinition.xml");
|
||||
WorkflowDeployment deployment = workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
|
||||
testWorkflowDef = deployment.getDefinition();
|
||||
assertNotNull(testWorkflowDef);
|
||||
|
||||
// run as system
|
||||
authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
// get valid node ref
|
||||
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
testNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction()
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
public void testSubmitForReview()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Test review");
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.ASSOC_PACKAGE));
|
||||
WorkflowTask endedTask = taskComponent.endTask(task.getId(), null);
|
||||
assertNotNull(endedTask);
|
||||
assertTrue(endedTask.getProperties().containsKey(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("", endedTask.getProperties().get(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("Test review", endedTask.getProperties().get(WorkflowModel.PROP_DESCRIPTION));
|
||||
assertEquals("Test review", endedTask.getPath().getInstance().getDescription());
|
||||
|
||||
List<WorkflowTask> assignedTasks = taskComponent.getAssignedTasks(AuthenticationUtil.getAdminUserName(), WorkflowTaskState.IN_PROGRESS, false);
|
||||
assertNotNull(assignedTasks);
|
||||
assignedTasks = filterTasksByWorkflowInstance(assignedTasks, path.getInstance().getId());
|
||||
|
||||
assertEquals(testNodeRef, assignedTasks.get(0).getProperties().get(WorkflowModel.ASSOC_PACKAGE));
|
||||
assertEquals(reviewDueDate, assignedTasks.get(0).getProperties().get(WorkflowModel.PROP_DUE_DATE));
|
||||
}
|
||||
|
||||
public void testCompletedItems()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
List<NodeRef> nodeRefs = new ArrayList<NodeRef>();
|
||||
nodeRefs.add(testNodeRef);
|
||||
nodeRefs.add(testNodeRef);
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
params.put(WorkflowModel.PROP_COMPLETED_ITEMS, (Serializable)nodeRefs);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_COMPLETED_ITEMS));
|
||||
assertEquals(2, ((List<?>)task.getProperties().get(WorkflowModel.PROP_COMPLETED_ITEMS)).size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter task list by workflow instance
|
||||
*
|
||||
* @param tasks
|
||||
* @param workflowInstanceId
|
||||
* @return
|
||||
*/
|
||||
private List<WorkflowTask> filterTasksByWorkflowInstance(List<WorkflowTask> tasks, String workflowInstanceId)
|
||||
{
|
||||
List<WorkflowTask> filteredTasks = new ArrayList<WorkflowTask>();
|
||||
for (WorkflowTask task : tasks)
|
||||
{
|
||||
if (task.getPath().getInstance().getId().equals(workflowInstanceId))
|
||||
{
|
||||
filteredTasks.add(task);
|
||||
}
|
||||
}
|
||||
return filteredTasks;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.TaskComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowComponent;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
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.security.PersonService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDeployment;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowPath;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.BaseSpringTestsCategory;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
|
||||
/**
|
||||
* Review and Approve workflow specific Tests
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@Category(BaseSpringTestsCategory.class)
|
||||
public class ReviewAndApproveTest extends BaseSpringTest
|
||||
{
|
||||
AuthenticationComponent authenticationComponent;
|
||||
PersonService personService;
|
||||
WorkflowComponent workflowComponent;
|
||||
TaskComponent taskComponent;
|
||||
WorkflowDefinition testWorkflowDef;
|
||||
NodeRef testNodeRef;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
personService = (PersonService)applicationContext.getBean("personService");
|
||||
BPMEngineRegistry registry = (BPMEngineRegistry)applicationContext.getBean("bpm_engineRegistry");
|
||||
workflowComponent = registry.getWorkflowComponent(JBPMEngine.ENGINE_ID);
|
||||
taskComponent = registry.getTaskComponent(JBPMEngine.ENGINE_ID);
|
||||
|
||||
// deploy latest review and approve process definition
|
||||
ClassPathResource processDef = new ClassPathResource("alfresco/workflow/review_processdefinition.xml");
|
||||
WorkflowDeployment deployment = workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
|
||||
testWorkflowDef = deployment.getDefinition();
|
||||
assertNotNull(testWorkflowDef);
|
||||
|
||||
// run as system
|
||||
authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
|
||||
// get valid node ref
|
||||
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
testNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction()
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
public void testSubmitForReview()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "Test review");
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.ASSOC_PACKAGE));
|
||||
WorkflowTask endedTask = taskComponent.endTask(task.getId(), null);
|
||||
assertNotNull(endedTask);
|
||||
assertTrue(endedTask.getProperties().containsKey(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("", endedTask.getProperties().get(WorkflowModel.PROP_OUTCOME));
|
||||
assertEquals("Test review", endedTask.getProperties().get(WorkflowModel.PROP_DESCRIPTION));
|
||||
assertEquals("Test review", endedTask.getPath().getInstance().getDescription());
|
||||
|
||||
List<WorkflowTask> assignedTasks = taskComponent.getAssignedTasks(AuthenticationUtil.getAdminUserName(), WorkflowTaskState.IN_PROGRESS, false);
|
||||
assertNotNull(assignedTasks);
|
||||
assignedTasks = filterTasksByWorkflowInstance(assignedTasks, path.getInstance().getId());
|
||||
|
||||
assertEquals(testNodeRef, assignedTasks.get(0).getProperties().get(WorkflowModel.ASSOC_PACKAGE));
|
||||
assertEquals(reviewDueDate, assignedTasks.get(0).getProperties().get(WorkflowModel.PROP_DUE_DATE));
|
||||
}
|
||||
|
||||
public void testCompletedItems()
|
||||
{
|
||||
WorkflowDefinition workflowDef = testWorkflowDef;
|
||||
|
||||
List<NodeRef> nodeRefs = new ArrayList<NodeRef>();
|
||||
nodeRefs.add(testNodeRef);
|
||||
nodeRefs.add(testNodeRef);
|
||||
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, testNodeRef);
|
||||
params.put(WorkflowModel.PROP_COMPLETED_ITEMS, (Serializable)nodeRefs);
|
||||
Date reviewDueDate = new Date();
|
||||
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, reviewDueDate);
|
||||
NodeRef reviewer = personService.getPerson(AuthenticationUtil.getAdminUserName());
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, reviewer);
|
||||
|
||||
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
|
||||
assertNotNull(path);
|
||||
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
|
||||
assertNotNull(tasks1);
|
||||
assertEquals(1, tasks1.size());
|
||||
|
||||
WorkflowTask task = tasks1.get(0);
|
||||
assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_COMPLETED_ITEMS));
|
||||
assertEquals(2, ((List<?>)task.getProperties().get(WorkflowModel.PROP_COMPLETED_ITEMS)).size());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter task list by workflow instance
|
||||
*
|
||||
* @param tasks
|
||||
* @param workflowInstanceId
|
||||
* @return
|
||||
*/
|
||||
private List<WorkflowTask> filterTasksByWorkflowInstance(List<WorkflowTask> tasks, String workflowInstanceId)
|
||||
{
|
||||
List<WorkflowTask> filteredTasks = new ArrayList<WorkflowTask>();
|
||||
for (WorkflowTask task : tasks)
|
||||
{
|
||||
if (task.getPath().getInstance().getId().equals(workflowInstanceId))
|
||||
{
|
||||
filteredTasks.add(task);
|
||||
}
|
||||
}
|
||||
return filteredTasks;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user