01-22-2014 04:07 AM
<?xml version="1.0" encoding="UTF-8"?>
<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://www.activiti.org/test">
<process id="saleOpportunity" name="Sale Opportunity" isExecutable="true">
<documentation>This is an example of sale opportunity process creating or selecting a customer to be in business with.</documentation>
<subProcess id="customerCreationSubprocess" name="Customer Creation Subprocess">
<startEvent id="customerCreationSubprocessStart" name="Customer Creation Subprocess Start"></startEvent>
<endEvent id="customerCreationSubprocessEnd" name="Customer Creation Subprocess End"></endEvent>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<userTask id="selectCustomerMethod" name="Select Customer Method" activiti:assignee="${sellerName}">
<documentation>Hello,
In order to select a customer you have to tell us if its account is already created or we should create an account for him/her.</documentation>
<extensionElements>
<activiti:formProperty id="isCustomerCreated" name="Create a customer o select one?" type="enum" variable="isCustomerCreated" required="true">
<activiti:value id="true" name="Select a customer"></activiti:value>
<activiti:value id="false" name="Create a customer"></activiti:value>
</activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow3" sourceRef="selectCustomerMethod" targetRef="exclusivegateway1"></sequenceFlow>
<userTask id="customerCreation" name="Customer Creation" activiti:assignee="${sellerName}">
<documentation>Please, fill all the information about this customer in order to be created.</documentation>
<extensionElements>
<activiti:formProperty id="clientName" name="Client Name" type="string" variable="clientName" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<userTask id="customerCreated" name="Customer Created" activiti:assignee="${sellerName}">
<documentation>Client ${clientName} has been successfully created.</documentation>
</userTask>
<sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="customerCreation">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${isCustomerCreated == 'true'}]]></conditionExpression>
</sequenceFlow>
<userTask id="customerSelection" name="Customer Selection" activiti:assignee="${sellerName}">
<documentation>Type the name of the client you want to be in business with.</documentation>
<extensionElements>
<activiti:formProperty id="clientName" name="Client Name" type="string" variable="clientName" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow9" sourceRef="customerCreationSubprocessStart" targetRef="selectCustomerMethod"></sequenceFlow>
<sequenceFlow id="flow10" sourceRef="customerCreation" targetRef="customerCreated"></sequenceFlow>
<sequenceFlow id="flow11" sourceRef="exclusivegateway1" targetRef="customerSelection">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${isCustomerCreated == 'false'}]]></conditionExpression>
</sequenceFlow>
<exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow14" sourceRef="customerCreated" targetRef="exclusivegateway2"></sequenceFlow>
<sequenceFlow id="flow15" sourceRef="customerSelection" targetRef="exclusivegateway2"></sequenceFlow>
<sequenceFlow id="flow16" sourceRef="exclusivegateway2" targetRef="customerCreationSubprocessEnd"></sequenceFlow>
</subProcess>
<startEvent id="mainStartEvent" name="Main Start" activiti:initiator="${initiator}">
<documentation>Hello,
Please, choose the seller.</documentation>
<extensionElements>
<activiti:formProperty id="sellerName" name="Seller Name" type="user" variable="sellerName" required="true"></activiti:formProperty>
</extensionElements>
</startEvent>
<endEvent id="mainEndEvent" name="Main End Event">
<documentation>Thanks!</documentation>
</endEvent>
<sequenceFlow id="flow12" sourceRef="mainStartEvent" targetRef="customerCreationSubprocess"></sequenceFlow>
<sequenceFlow id="flow13" sourceRef="customerCreationSubprocess" targetRef="chooseMethod"></sequenceFlow>
<userTask id="chooseMethod" name="Choose Method">
<documentation>Choose a method here.</documentation>
</userTask>
<sequenceFlow id="flow17" sourceRef="chooseMethod" targetRef="mainEndEvent"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_saleOpportunity">
<bpmndi:BPMNPlane bpmnElement="saleOpportunity" id="BPMNPlane_saleOpportunity">
<bpmndi:BPMNShape bpmnElement="customerCreationSubprocess" id="BPMNShape_customerCreationSubprocess">
<omgdc:Bounds height="271.0" width="811.0" x="210.0" y="202.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="customerCreationSubprocessStart" id="BPMNShape_customerCreationSubprocessStart">
<omgdc:Bounds height="35.0" width="35.0" x="240.0" y="323.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="customerCreationSubprocessEnd" id="BPMNShape_customerCreationSubprocessEnd">
<omgdc:Bounds height="35.0" width="35.0" x="940.0" y="323.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="540.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="selectCustomerMethod" id="BPMNShape_selectCustomerMethod">
<omgdc:Bounds height="59.0" width="105.0" x="350.0" y="311.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="customerCreation" id="BPMNShape_customerCreation">
<omgdc:Bounds height="55.0" width="105.0" x="590.0" y="252.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="customerCreated" id="BPMNShape_customerCreated">
<omgdc:Bounds height="55.0" width="105.0" x="736.0" y="252.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="customerSelection" id="BPMNShape_customerSelection">
<omgdc:Bounds height="55.0" width="105.0" x="690.0" y="362.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
<omgdc:Bounds height="40.0" width="40.0" x="860.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="mainStartEvent" id="BPMNShape_mainStartEvent">
<omgdc:Bounds height="35.0" width="35.0" x="100.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="mainEndEvent" id="BPMNShape_mainEndEvent">
<omgdc:Bounds height="35.0" width="35.0" x="1230.0" y="320.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="chooseMethod" id="BPMNShape_chooseMethod">
<omgdc:Bounds height="55.0" width="105.0" x="1080.0" y="310.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="455.0" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="340.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="560.0" y="320.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="279.0"></omgdi:waypoint>
<omgdi:waypoint x="590.0" y="279.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="275.0" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="350.0" y="340.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="695.0" y="279.0"></omgdi:waypoint>
<omgdi:waypoint x="736.0" y="279.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="560.0" y="360.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="389.0"></omgdi:waypoint>
<omgdi:waypoint x="690.0" y="389.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
<omgdi:waypoint x="841.0" y="279.0"></omgdi:waypoint>
<omgdi:waypoint x="880.0" y="279.0"></omgdi:waypoint>
<omgdi:waypoint x="880.0" y="320.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
<omgdi:waypoint x="795.0" y="389.0"></omgdi:waypoint>
<omgdi:waypoint x="880.0" y="389.0"></omgdi:waypoint>
<omgdi:waypoint x="880.0" y="360.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
<omgdi:waypoint x="900.0" y="340.0"></omgdi:waypoint>
<omgdi:waypoint x="940.0" y="340.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
<omgdi:waypoint x="135.0" y="337.0"></omgdi:waypoint>
<omgdi:waypoint x="210.0" y="337.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="1021.0" y="337.0"></omgdi:waypoint>
<omgdi:waypoint x="1080.0" y="337.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow17" id="BPMNEdge_flow17">
<omgdi:waypoint x="1185.0" y="337.0"></omgdi:waypoint>
<omgdi:waypoint x="1230.0" y="337.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
jpa-application-context.xml
: (note that I include the user form type from activiti-explorer)<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="org.workflow" />
<bean id="activitiDataSource"
class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocation">
<value>classpath:client/jpa-persistence.xml</value>
</property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="databaseType" value="h2" />
<property name="dataSource" ref="activitiDataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
<property name="jpaHandleTransaction" value="true" />
<property name="jpaCloseEntityManager" value="true" />
<property name="customFormTypes">
<list>
<bean class="org.activiti.explorer.form.UserFormType"/>
</list>
</property>
<property name="jobExecutorActivate" value="true" />
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />
<bean id="formService" factory-bean="processEngine"
factory-method="getFormService" />
<bean id="clientService" class="org.workflow.client.ClientService" />
</beans>
package org.workflow.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import org.common.AbstractTest;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.FormService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.form.FormProperty;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:client/jpa-application-context.xml"})
@TransactionConfiguration(transactionManager="transactionManager")
public class ClientTest extends AbstractTest {
@PersistenceContext
private EntityManager entityManager;
@Autowired
private RuntimeService rs;
@Autowired
private TaskService ts;
@Autowired
private FormService fs;
@Autowired
private RepositoryService reps;
@Test
public void createClient() throws Exception {
String processKey = "saleOpportunity";
String userAssignee = "kermit";
String sellerVar = "sellerName";
String isCustomerCreatedVar = "isCustomerCreated";
String isCustomerCreatedValue = "false";
String clientVar = "clientName";
String clientName = "John";
String filename = "/home/MY_USER/workspace/workflow/src/main/resources/diagrams/" + processKey + ".bpmn";
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put(sellerVar, userAssignee);
reps.createDeployment().addInputStream(processKey + ".bpmn20.xml", new FileInputStream(filename)).deploy();
// main start event
rs.startProcessInstanceByKey(processKey, variableMap);
Task task = ts.createTaskQuery().singleResult();
assertNotNull(task);
assertNotNull(task.getAssignee());
assertEquals(task.getAssignee(), userAssignee);
ts.complete(task.getId());
ts.setVariable(task.getId(), sellerVar, userAssignee);
// next -> subprocess start event -> customer method
task = ts.createTaskQuery().singleResult();
Map<String, String> formProperties = new HashMap<String,String>();
formProperties.put(isCustomerCreatedVar, isCustomerCreatedValue);
fs.submitTaskFormData(task.getId(), formProperties);
task = ts.createTaskQuery().singleResult();
Map<String, Object> variables = rs.getVariables(task.getExecutionId());
// assertEquals(variables.get(isCustomerCreatedVar), isCustomerCreatedValue);
// assertFalse(Boolean.valueOf((String) variables.get(isCustomerCreatedVar)));
boolean isCustomerCreated = (boolean) Boolean.valueOf((String) variables.get(isCustomerCreatedVar));
// gateway
if (isCustomerCreated)
{
// nope
}
else
{
// yep -> Customer Creation
formProperties.clear();
formProperties.put(clientVar, clientName);
fs.submitTaskFormData(task.getId(), formProperties);
variables.clear();
variables = rs.getVariables(task.getExecutionId());
assertEquals(variables.get(clientVar), clientName);
// customer created
task = ts.createTaskQuery().singleResult();
ts.complete(task.getId());
}
// choose method
task = ts.createTaskQuery().singleResult();
ts.complete(task.getId());
}
}
ts.setVariable(task.getId(), sellerVar, userAssignee);
), so it doesn't find them afterwards in other tasks of the same process, but they don't have any problem using explorer and they were stored back then with my other configuration. Also, it's not detecting my user form type classes, but I have activiti-explorer-5.14.jar
in my classpath (I can find both formtype and renderer in the package explorer of Eclipse).01-22-2014 04:58 AM
01-22-2014 11:21 AM
01-23-2014 03:17 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.