Merged 1.4 to HEAD (More workflow)

svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4166 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4167 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4183 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4184 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4206 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4207 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4215 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4216 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4301 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4302 .


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4534 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-12-06 18:34:19 +00:00
parent c4e2cabb12
commit 6e7b8ad98e
11 changed files with 313 additions and 18 deletions

View File

@@ -47,6 +47,7 @@ import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
@@ -71,6 +72,7 @@ import org.jbpm.context.exe.ContextInstance;
import org.jbpm.context.exe.TokenVariableMap;
import org.jbpm.db.GraphSession;
import org.jbpm.db.TaskMgmtSession;
import org.jbpm.file.def.FileDefinition;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.def.Transition;
@@ -106,6 +108,10 @@ public class JBPMEngine extends BPMEngine
protected ServiceRegistry serviceRegistry;
protected PersonService personService;
protected JbpmTemplate jbpmTemplate;
// Company Home
protected StoreRef companyHomeStore;
protected String companyHomePath;
// Note: jBPM query which is not provided out-of-the-box
// TODO: Check jBPM 3.2 and get this implemented in jBPM
@@ -186,6 +192,26 @@ public class JBPMEngine extends BPMEngine
this.serviceRegistry = serviceRegistry;
}
/**
* Sets the Company Home Path
*
* @param companyHomePath
*/
public void setCompanyHomePath(String companyHomePath)
{
this.companyHomePath = companyHomePath;
}
/**
* Sets the Company Home Store
*
* @param companyHomeStore
*/
public void setCompanyHomeStore(String companyHomeStore)
{
this.companyHomeStore = new StoreRef(companyHomeStore);
}
//
// Workflow Definition...
@@ -357,6 +383,31 @@ public class JBPMEngine extends BPMEngine
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.workflow.WorkflowComponent#getDefinitionImage(java.lang.String)
*/
public byte[] getDefinitionImage(final String workflowDefinitionId)
{
try
{
return (byte[])jbpmTemplate.execute(new JbpmCallback()
{
@SuppressWarnings("synthetic-access")
public Object doInJbpm(JbpmContext context)
{
GraphSession graphSession = context.getGraphSession();
ProcessDefinition processDefinition = getProcessDefinition(graphSession, workflowDefinitionId);
FileDefinition fileDefinition = processDefinition.getFileDefinition();
return (fileDefinition == null) ? null : fileDefinition.getBytes("processimage.jpg");
}
});
}
catch(JbpmException e)
{
throw new WorkflowException("Failed to retrieve workflow definition image for '" + workflowDefinitionId + "'", e);
}
}
/**
* Gets a jBPM process definition
*
@@ -404,10 +455,18 @@ public class JBPMEngine extends BPMEngine
// assign initial process context
ContextInstance processContext = processInstance.getContextInstance();
processContext.setVariable("cancelled", false);
NodeRef companyHome = getCompanyHome();
processContext.setVariable("companyhome", new JBPMNode(companyHome, serviceRegistry));
NodeRef initiatorPerson = mapNameToAuthority(currentUserName);
if (initiatorPerson != null)
{
processContext.setVariable("initiator", new JBPMNode(initiatorPerson, serviceRegistry));
NodeRef initiatorHome = (NodeRef)nodeService.getProperty(initiatorPerson, ContentModel.PROP_HOMEFOLDER);
if (initiatorHome != null)
{
processContext.setVariable("initiatorhome", new JBPMNode(initiatorHome, serviceRegistry));
}
}
// create the start task if one exists
@@ -558,10 +617,41 @@ public class JBPMEngine extends BPMEngine
// retrieve and cancel process instance
GraphSession graphSession = context.getGraphSession();
ProcessInstance processInstance = getProcessInstance(graphSession, workflowId);
processInstance.getContextInstance().setVariable("cancelled", true);
processInstance.end();
// TODO: Determine if this is the most appropriate way to cancel workflow...
// It might be useful to record point at which it was cancelled etc
WorkflowInstance workflowInstance = createWorkflowInstance(processInstance);
// delete the process instance
graphSession.deleteProcessInstance(processInstance, true, true, true);
return workflowInstance;
}
});
}
catch(JbpmException e)
{
throw new WorkflowException("Failed to cancel workflow instance '" + workflowId + "'", e);
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.workflow.WorkflowComponent#cancelWorkflow(java.lang.String)
*/
public WorkflowInstance deleteWorkflow(final String workflowId)
{
try
{
return (WorkflowInstance) jbpmTemplate.execute(new JbpmCallback()
{
@SuppressWarnings("unchecked")
public Object doInJbpm(JbpmContext context)
{
// retrieve and cancel process instance
GraphSession graphSession = context.getGraphSession();
ProcessInstance processInstance = getProcessInstance(graphSession, workflowId);
WorkflowInstance workflowInstance = createWorkflowInstance(processInstance);
// delete the process instance
graphSession.deleteProcessInstance(processInstance, true, true, true);
workflowInstance.active = false;
@@ -1755,7 +1845,22 @@ public class JBPMEngine extends BPMEngine
return (label == null) ? defaultLabel : label;
}
/**
* Gets the Company Home
*
* @return company home node ref
*/
private NodeRef getCompanyHome()
{
// TODO: Determine if caching is required
List<NodeRef> refs = serviceRegistry.getSearchService().selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
if (refs.size() != 1)
{
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
}
return refs.get(0);
}
//
// Workflow Data Object Creation...
//
@@ -1888,7 +1993,7 @@ public class JBPMEngine extends BPMEngine
final String title = getLabel(name + ".workflow", TITLE_LABEL, name);
final String description = getLabel(name + ".workflow", DESC_LABEL, title);
return new WorkflowDefinition(createGlobalId(new Long(definition.getId()).toString()),
name,
createGlobalId(name),
new Integer(definition.getVersion()).toString(),
title,
description,

View File

@@ -87,7 +87,7 @@ public class JBPMEngineTest extends BaseSpringTest
WorkflowDeployment deployment = workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
testWorkflowDef = deployment.definition;
assertNotNull(testWorkflowDef);
assertEquals("test", testWorkflowDef.name);
assertEquals("jbpm$test", testWorkflowDef.name);
assertEquals("1", testWorkflowDef.version);
assertTrue(workflowComponent.isDefinitionDeployed(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML));
@@ -119,7 +119,7 @@ public class JBPMEngineTest extends BaseSpringTest
WorkflowDeployment deployment = workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
testWorkflowDef = deployment.definition;
assertNotNull(testWorkflowDef);
assertEquals("test", testWorkflowDef.name);
assertEquals("jbpm$test", testWorkflowDef.name);
assertEquals("2", testWorkflowDef.version);
}

View File

@@ -34,6 +34,8 @@
<task-node name="review">
<event type="node-enter">
<script>
System.out.println("company home: " + companyhome.name);
System.out.println("initiator home: " + initiatorhome.name);
System.out.println("the reviewer is " + reviewer);
System.out.println("node " + testNode.name + " contains " + testNode.children.length + " children");
System.out.println("scriptResult = " + scriptResult);

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="test_processevents">
<event type="process-start">
<script>
System.out.println("Process start");
</script>
</event>
<start-state name="start">
<transition to="end"/>
</start-state>
<end-state name="end"/>
<event type="process-end">
<script>
if (cancelled) { System.out.println("cancelled"); }
System.out.println("Process end: " + cancelled);
</script>
</event>
</process-definition>