First cut of Alfresco Node support in jBPM process instances:

- NodeRefs placed into process context are converted to Script Nodes (as used in javascript)
- jBPM persistence of Nodes configured to serialize/deserialize as NodeRef strings
- jBPM process script (Beanshell) can access Alfresco Nodes in same manner as Alfresco Javascript

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3484 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-08-11 14:08:49 +00:00
parent 0b74cbb36c
commit 17ab601380
10 changed files with 402 additions and 31 deletions

View File

@@ -16,7 +16,6 @@
*/
package org.alfresco.repo.workflow;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

View File

@@ -36,6 +36,7 @@ import org.alfresco.repo.workflow.TaskComponent;
import org.alfresco.repo.workflow.WorkflowComponent;
import org.alfresco.repo.workflow.WorkflowDefinitionComponent;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -86,6 +87,7 @@ public class JBPMEngine extends BPMEngine
protected DictionaryService dictionaryService;
protected NamespaceService namespaceService;
protected NodeService nodeService;
protected ServiceRegistry serviceRegistry;
protected PersonService personService;
private JbpmTemplate jbpmTemplate;
@@ -139,6 +141,16 @@ public class JBPMEngine extends BPMEngine
this.personService = personService;
}
/**
* Sets the Service Registry
*
* @param serviceRegistry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
//
// Workflow Definition...
@@ -907,9 +919,18 @@ public class JBPMEngine extends BPMEngine
{
String key = entry.getKey();
Object value = entry.getValue();
//
// perform data conversions
// NOTE: Only convert Authority name to NodeRef for now
//
// Convert Nodes to NodeRefs
if (value instanceof org.alfresco.repo.jscript.Node)
{
value = ((org.alfresco.repo.jscript.Node)value).getNodeRef();
}
// Convert Authority name to NodeRefs
QName qname = QName.createQName(key, this.namespaceService);
AssociationDefinition assocDef = taskAssocs.get(qname);
if (assocDef != null && assocDef.getTargetClass().equals(ContentModel.TYPE_PERSON))
@@ -1030,13 +1051,29 @@ public class JBPMEngine extends BPMEngine
if (assocDef.getTargetClass().getName().equals(ContentModel.TYPE_PERSON))
{
String[] authorityNames = mapAuthorityToName((List<NodeRef>)value);
value = ((assocDef.isTargetMany()) ? authorityNames : authorityNames[0]);
if (authorityNames != null && authorityNames.length > 0)
{
value = (Serializable) (assocDef.isTargetMany() ? authorityNames : authorityNames[0]);
}
}
// map association to specific jBPM task instance field
if (key.equals(WorkflowModel.ASSOC_POOLED_ACTORS))
{
instance.setPooledActors((String[])value);
String[] pooledActors = null;
if (value instanceof String[])
{
pooledActors = (String[])value;
}
else if (value instanceof String)
{
pooledActors = new String[] {(String)value};
}
else
{
throw new WorkflowException("Pooled actors value '" + value + "' is invalid");
}
instance.setPooledActors(pooledActors);
continue;
}
}
@@ -1044,14 +1081,10 @@ public class JBPMEngine extends BPMEngine
// no specific mapping to jBPM task has been established, so place into
// the generic task variable bag
String name = null;
if (key.getNamespaceURI().equals(NamespaceService.DEFAULT_URI))
String name = key.toPrefixString(this.namespaceService);
if (value instanceof NodeRef)
{
name = key.getLocalName();
}
else
{
name = key.toPrefixString(this.namespaceService);
value = new org.alfresco.repo.jscript.Node((NodeRef)value, serviceRegistry, null);
}
instance.setVariableLocally(name, value);
}

View File

@@ -30,7 +30,10 @@ import org.alfresco.repo.workflow.TaskComponent;
import org.alfresco.repo.workflow.WorkflowComponent;
import org.alfresco.repo.workflow.WorkflowDefinitionComponent;
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.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowException;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
@@ -54,6 +57,7 @@ public class JBPMEngineTest extends BaseSpringTest
WorkflowComponent workflowComponent;
TaskComponent taskComponent;
WorkflowDefinition testWorkflowDef;
NodeRef testNodeRef;
//@Override
@@ -72,6 +76,10 @@ public class JBPMEngineTest extends BaseSpringTest
assertEquals("Test", testWorkflowDef.name);
assertEquals("1", testWorkflowDef.version);
assertTrue(workflowDefinitionComponent.isDefinitionDeployed(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML));
// get valid node ref
NodeService nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
testNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "spacesStore"));
}
@@ -336,6 +344,25 @@ public class JBPMEngineTest extends BaseSpringTest
}
public void testNodeRef()
{
WorkflowDefinition workflowDef = getTestDefinition();
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "reviewer"), "admin");
parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), testNodeRef);
WorkflowPath path = workflowComponent.startWorkflow(workflowDef.id, parameters);
assertNotNull(path);
assertNotNull(path);
List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.id);
assertNotNull(tasks1);
assertEquals(1, tasks1.size());
assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).state);
WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).id, null);
assertNotNull(updatedTask);
assertEquals(WorkflowTaskState.COMPLETED, updatedTask.state);
}
/**
* Locate the Test Workflow Definition
*

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.workflow.jbpm;
import org.alfresco.repo.jscript.Node;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.jbpm.context.exe.Converter;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springmodules.workflow.jbpm31.JbpmFactoryLocator;
/**
* jBPM Converter for transforming Alfresco Node to string and back
*
* @author davidc
*/
public class NodeConverter implements Converter
{
private static final long serialVersionUID = 1L;
private static BeanFactoryLocator jbpmFactoryLocator = new JbpmFactoryLocator();
/* (non-Javadoc)
* @see org.jbpm.context.exe.Converter#supports(java.lang.Object)
*/
public boolean supports(Object value)
{
if (value == null)
{
return true;
}
return (value.getClass() == Node.class);
}
/* (non-Javadoc)
* @see org.jbpm.context.exe.Converter#convert(java.lang.Object)
*/
public Object convert(Object o)
{
Object converted = null;
if (o != null)
{
converted = ((Node)o).getNodeRef().toString();
}
return converted;
}
/* (non-Javadoc)
* @see org.jbpm.context.exe.Converter#revert(java.lang.Object)
*/
public Object revert(Object o)
{
Object reverted = null;
if (o != null)
{
BeanFactoryReference factory = jbpmFactoryLocator.useBeanFactory(null);
ServiceRegistry serviceRegistry = (ServiceRegistry)factory.getFactory().getBean(ServiceRegistry.SERVICE_REGISTRY);
reverted = new Node(new NodeRef((String)o), serviceRegistry, null);
}
return reverted;
}
}

View File

@@ -0,0 +1,28 @@
<jbpm-configuration>
<jbpm-context>
<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
<service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
<service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
<service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
<service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
</jbpm-context>
<!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
<string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />
<string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
<string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
<string name='resource.converter' value='org/alfresco/repo/workflow/jbpm/jbpm.converter.properties' />
<string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
<string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
<string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
<string name="resource.varmapping" value="org/alfresco/repo/workflow/jbpm/jbpm.varmapping.xml" />
<long name="jbpm.msg.wait.timout" value="5000" singleton="true" />
<int name="jbpm.byte.block.size" value="1024" singleton="true" />
<string name="mail.smtp.host" value="localhost" />
<bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl" singleton="true" />
<bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
<bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
</jbpm-configuration>

View File

@@ -0,0 +1,18 @@
# this file contains the mappings between converter types
# and the char that is used in the database. this mapping
# is used by the ConverterEnumType to store the VariableInstance
# converter field. The Converters class provides singleton access
# to these converter classes.
B org.jbpm.context.exe.converter.BooleanToStringConverter
Y org.jbpm.context.exe.converter.BytesToByteArrayConverter
E org.jbpm.context.exe.converter.ByteToLongConverter
C org.jbpm.context.exe.converter.CharacterToStringConverter
A org.jbpm.context.exe.converter.DateToLongConverter
D org.jbpm.context.exe.converter.DoubleToStringConverter
F org.jbpm.context.exe.converter.FloatToStringConverter
G org.jbpm.context.exe.converter.FloatToDoubleConverter
I org.jbpm.context.exe.converter.IntegerToLongConverter
R org.jbpm.context.exe.converter.SerializableToByteArrayConverter
H org.jbpm.context.exe.converter.ShortToLongConverter
N org.alfresco.repo.workflow.jbpm.NodeConverter

View File

@@ -0,0 +1,179 @@
<!--
# This file specifies how jbpm will store variables into the database.
#
# If jbpm needs to determine how to store a variable into the database,
# the jbpm-types below or scanned in sequence as they are specified here.
# For each jbpm-type, jbpm will see if the give variable object matches
# with the matcher bean. If there is a match, the converter (optional)
# and the variable instance will be used to store and retrieve
# the variable value for the rest of its lifetime till the variable is
# deleted.
-->
<jbpm-types>
<list name="jbpm.types" singleton="true">
<!-- java.lang.String -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.String" /></field>
</bean>
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
</jbpm-type>
<!-- java.lang.Boolean -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Boolean" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.BooleanToStringConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
</jbpm-type>
<!-- java.lang.Character -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Character" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.CharacterToStringConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
</jbpm-type>
<!-- java.lang.Long -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Long" /></field>
</bean>
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
</jbpm-type>
<!-- java.lang.Byte -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Byte" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.ByteToLongConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
</jbpm-type>
<!-- java.lang.Short -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Short" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.ShortToLongConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
</jbpm-type>
<!-- java.lang.Integer -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Integer" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.IntegerToLongConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.LongInstance" />
</jbpm-type>
<!-- java.lang.Double -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Double" /></field>
</bean>
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
</jbpm-type>
<!-- java.lang.Float -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.lang.Float" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.FloatToDoubleConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.DoubleInstance" />
</jbpm-type>
<!-- java.util.Date -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="java.util.Date" /></field>
</bean>
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.DateInstance" />
</jbpm-type>
<!-- org.alfresco.repo.jscript.Node -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="org.alfresco.repo.jscript.Node" /></field>
</bean>
</matcher>
<converter class="org.alfresco.repo.workflow.jbpm.NodeConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.StringInstance" />
</jbpm-type>
<!-- byte[] -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.ClassNameMatcher">
<field name="className"><string value="[B" /></field>
</bean>
</matcher>
<converter class="org.jbpm.context.exe.converter.BytesToByteArrayConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
</jbpm-type>
<!-- java.io.Serializable -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.SerializableMatcher" />
</matcher>
<converter class="org.jbpm.context.exe.converter.SerializableToByteArrayConverter" />
<variable-instance class="org.jbpm.context.exe.variableinstance.ByteArrayInstance" />
</jbpm-type>
<!-- hibernatable long id types -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.HibernateLongIdMatcher" />
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.HibernateLongInstance" />
</jbpm-type>
<!-- hibernatable string id types -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.HibernateStringIdMatcher" />
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.HibernateStringInstance" />
</jbpm-type>
<!-- hibernatable ejb3 types -->
<jbpm-type>
<matcher>
<bean class="org.jbpm.context.exe.matcher.Ejb3Matcher" />
</matcher>
<variable-instance class="org.jbpm.context.exe.variableinstance.Ejb3Instance" />
</jbpm-type>
</list>
</jbpm-types>

View File

@@ -6,6 +6,7 @@
<task name="Submit" swimlane="Initiator">
<controller>
<variable name="reviewer" access="write,required" />
<variable name="testNode" access="write,required" />
</controller>
</task>
<transition name="" to="Review"></transition>
@@ -15,29 +16,18 @@
<assignment actor-id="#{reviewer}"></assignment>
</swimlane>
<task-node name="Review">
<event type="node-enter">
<script>
System.out.println("the reviewer is " + reviewer);
System.out.println("node " + testNode.name + " contains " + testNode.children.length + " children");
</script>
</event>
<task name="Review" duedate="1 business day" blocking="true" swimlane="Reviewer">
<controller>
<variable name="comment" access="read,write,required"></variable>
</controller>
</task>
<transition name="reject" to="Rejected"></transition>
<transition name="approve" to="Approved"></transition>
</task-node>
<task-node name="Rejected">
<task name="Rejected" swimlane="Initiator">
<controller>
<variable name="comment" access="read"></variable>
</controller>
</task>
<transition name="" to="end"></transition>
</task-node>
<task-node name="Approved">
<task name="Approved" swimlane="Initiator">
<controller>
<variable name="comment" access="read"></variable>
</controller>
</task>
<transition name="" to="end"></transition>
<transition name="" to="publish"></transition>
</task-node>
<end-state name="end"></end-state>
</process-definition>