我创建了一个虚拟工作流程,我使用以下测试用例进行了测试:
@Test
public void testNonPifCondition(){
//prepare input parameters for the process:
String document_id = "3002001";
String task_name = "Index";
String insured_name = "Tushar";
String acct_action_needed = "false";
Map<String, Object> inputVariables = new HashMap<String, Object>();
inputVariables.put("document_id", document_id);
inputVariables.put("task_name", task_name);
inputVariables.put("insured_name", insured_name);
inputVariables.put("acct_action_needed", acct_action_needed);
//Start the process using its ID and pass the input variables
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("NS_UW_WorkFlow", inputVariables);
System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
//Assert.assertEquals("Coordinate Staff", processInstance.getNodeInstances().iterator().next().getNodeName());
/*Assert.assertEquals(date, mockWorkItemHandler.getInputParameter("bedrequest_date"));
Assert.assertEquals(entity, mockWorkItemHandler.getInputParameter("bedrequest_entity"));
Assert.assertEquals(patientAge, mockWorkItemHandler.getInputParameter("bedrequest_patientage"));
Assert.assertEquals(patientGender, mockWorkItemHandler.getInputParameter("bedrequest_patientgender"));
Assert.assertEquals(patientStatus, mockWorkItemHandler.getInputParameter("bedrequest_patientstatus"));
*/
//let's complete the task emulating the results of this task.
Map<String,Object> taskResults = new HashMap<String, Object>();
taskResults.put("out_insured_name", "Chandra");
mockWorkItemHandler.completeWorkItem(taskResults);
System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );
// Assert.assertEquals("3C", mockWorkItemHandler.getInputParameter("insured_name"));
//let's complete the task with a mocked resource
taskResults = new HashMap<String, Object>();
taskResults.put("nsig_insured_name", "Soham");
mockWorkItemHandler.completeWorkItem(taskResults);
System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );
//Assert.assertEquals("Check In Patient", processInstance.getNodeInstances().iterator().next().getNodeName());
// Assert.assertEquals("true", mockWorkItemHandler.getInputParameter("checkinresults_notified"));
//let's complete the task passing the mocked results
taskResults = new HashMap<String, Object>();
taskResults.put("nsuw_insured_name", "Venkata");
mockWorkItemHandler.completeWorkItem(taskResults);
System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"acct_action_needed\") : " + processInstance.getNodeInstances().iterator().next().getVariable("acct_action_needed") );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"acct_action_boolean\") : " + processInstance.getNodeInstances().iterator().next().getVariable("acct_action_boolean") );
//The process should be completed now. Let's check the 2 output
//parameters of the last task: they should be mapped to process variables.
/*Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
Assert.assertEquals("true", processInstance.getVariable("checkinresults_checkedin"));
Assert.assertEquals(checkinDate, processInstance.getVariable("checkinresults_time"));*/
taskResults = new HashMap<String, Object>();
taskResults.put("nsau_insured_name", "Raju");
mockWorkItemHandler.completeWorkItem(taskResults);
}
但是当我尝试使这个工作流组驱动即基于 groupID 的任务将分布在用户之间时,它只是炸弹。
以下是我使用的方法:
1)首先我使用以下代码加载任务服务:
@Before
public void setUp() throws Exception {
// Compiles and persists all the .bpmn resources
ds1 = new PoolingDataSource();
ds1.setUniqueName("jdbc/testDS1");
ds1.setClassName("org.h2.jdbcx.JdbcDataSource");
ds1.setMaxPoolSize(3);
ds1.setAllowLocalTransactions(true);
ds1.getDriverProperties().put("user", "sa");
ds1.getDriverProperties().put("password", "sasa");
ds1.getDriverProperties().put("URL", "jdbc:h2:mem:mydb");
ds1.init();
emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
System.setProperty("java.naming.factory.initial",
"bitronix.tm.jndi.BitronixInitialContextFactory");
emfTask = Persistence.createEntityManagerFactory("org.jbpm.task");
taskService = new TaskService(emfTask,
SystemEventListenerFactory.getSystemEventListener());
taskSession = taskService.createSession();
MockUserInfo userInfo = new MockUserInfo();
taskService.setUserinfo(userInfo);
this.fillUsersAndGroups(taskSession);
// server = new MinaTaskServer(taskService);
taskServer = new HornetQTaskServer(taskService, 5446);
Thread thread = new Thread(taskServer);
thread.start();
System.out.println("Waiting for the HornetQTask Server to come up");
while (!taskServer.isRunning()) {
System.out.print(".");
Thread.sleep(50);
}
TaskClient taskClient = new TaskClient(new HornetQTaskClientConnector("client 1",
new HornetQTaskClientHandler(SystemEventListenerFactory
.getSystemEventListener())));
this.client = new TaskClientWrapper(taskClient);
this.client.connect("127.0.0.1", 5446);
}
2)然后运行以下测试用例:
@Test
public void taskAssignedToGroup() throws InterruptedException {
UserTransaction ut = null;
try{
KnowledgeBase kbase = this.createKnowledgeBase();
ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null,
env);
new JPAWorkingMemoryDbLogger(session);
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
CommandBasedHornetQWSHumanTaskHandler wsHumanTaskHandler = new CommandBasedHornetQWSHumanTaskHandler(
session);
wsHumanTaskHandler.setClient(client.getTaskClient());
session.getWorkItemManager().registerWorkItemHandler("Human Task",
wsHumanTaskHandler);
String document_id = "3002001";
String task_name = "Index";
String insured_name = "Tushar";
String acct_action_needed = "false";
Map<String, Object> inputVariables = new HashMap<String, Object>();
inputVariables.put("document_id", document_id);
inputVariables.put("task_name", task_name);
inputVariables.put("insured_name", insured_name);
inputVariables.put("acct_action_needed", acct_action_needed);
ProcessInstance process = session.createProcessInstance("NS_UW_WorkFlow",
inputVariables);
session.insert(process);
long processInstanceId = process.getId();
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcessInstance(processInstanceId);
System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
Thread.sleep(2000);
// For Tushar
List<TaskSummary> tasks = client.getTasksAssignedAsPotentialOwner(
"tushar", "en-UK", this.getTestUserGroupsAssignments().get("tushar"));
Assert.assertEquals(0, tasks.size());
// Pass the user and the group it belongs
client.claim(tasks.get(0).getId(), "tushar", this.getTestUserGroupsAssignments().get("tushar"));
// The task owned method will give the tasks for a user which have been already claimed by him.
tasks = client.getTasksOwned("tushar", "en-UK");
Assert.assertEquals(1, tasks.size());
client.start(tasks.get(0).getId(), "tushar");
Map<String,Object> taskResults = new HashMap<String, Object>();
taskResults.put("insured_name", "Chandra");
client.complete(tasks.get(0).getId(), "tushar", taskResults);
tasks = client.getTasksOwned("tushar", "en-UK");
Assert.assertEquals(1, tasks.size());
ut.commit();
}catch(Exception e){
try {
ut.rollback();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("error : " + e.getLocalizedMessage());
}
}
一切正常,直到代码到达以下行: long processInstanceId = process.getId();
当我尝试通过触发以下命令来启动进程时: WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcessInstance(processInstanceId);
该代码给了我以下错误:
>..java.lang.RuntimeException: Could not commit transaction
> at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction>>>>(TaskServiceSession.java:1130)
> at org.jbpm.task.service.TaskServiceSession.addTask(TaskServiceSession.java:189)
> at org.jbpm.task.service.TaskServerHandler.messageReceived(TaskServerHandler.java:151)
> at org.jbpm.task.service.hornetq.HornetQTaskServerHandler.messageReceived>(HornetQTaskServerHandler.java:43)
> at org.jbpm.task.service.hornetq.BaseHornetQTaskServer.run(BaseHornetQTaskServer.java:104)
> at java.lang.Thread.run(Thread.java:662)
>Caused by: java.lang.RuntimeException: Unable to rollback transaction
> at org.jbpm.task.service.persistence.TaskLocalTransactionManager.rollback>(TaskLocalTransactionManager.java:77)
> at org.jbpm.task.service.persistence.TaskPersistenceManager.endTransaction>(TaskPersistenceManager.java:110)
> at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction(TaskServiceSession.java:1118)
> ... 5 more
>Caused by: java.lang.IllegalStateException: Transaction not active
> at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:82)
> at org.jbpm.task.service.persistence.TaskLocalTransactionManager.rollback>(TaskLocalTransactionManager.java:70)
> ... 7 more
>
之后,当我尝试通过触发以下命令来查找分配给用户“tushar”的任务时:
List<TaskSummary> tasks = client.getTasksAssignedAsPotentialOwner(
"tushar", "en-UK", this.getTestUserGroupsAssignments().get("tushar"));
我列出了 0 个任务。
任务服务是通过以下功能以用户名和组来诱导的:
private void fillUsersAndGroups(TaskServiceSession taskSession) {
User tushar = new User("tushar");
User venkata = new User("venkata");
User raju = new User("raju");
User ramya = new User("ramya");
taskSession.addUser(tushar);
taskSession.addUser(venkata);
taskSession.addUser(raju);
taskSession.addUser(ramya);
users.put("tushar", tushar);
users.put("venkata", venkata);
users.put("raju", raju);
users.put("ramya", ramya);
Group index = new Group("INDEX");
Group auSme = new Group("TASK 1");
Group uwSme = new Group("TASK 2");
Group accSme = new Group("TASK 3");
taskSession.addGroup(index);
taskSession.addGroup(auSme);
taskSession.addGroup(uwSme);
taskSession.addGroup(accSme);
groups.put("INDEX", index);
groups.put("TASK 1", auSme);
groups.put("TASK 2", uwSme);
groups.put("TASK 3", accSme);
}
然后我通过以下功能将我的自我(TUSHAR)分配到“INDEX”组中:
protected Map<String, List<String>> getTestUserGroupsAssignments() {
Map<String, List<String>> assign = new HashMap<String, List<String>>();
List<String> tusharGroups = new ArrayList<String>();
List<String> venkataGroups = new ArrayList<String>();
List<String> rajuGroups = new ArrayList<String>();
List<String> ramyaGroups = new ArrayList<String>();
tusharGroups.add("INDEX");
venkataGroups.add("TASK 1");
rajuGroups.add("TASK 2");
ramyaGroups.add("TASK 3");
assign.put("tushar", tusharGroups);
assign.put("venkata", venkataGroups);
assign.put("raju", rajuGroups);
assign.put("ramya", ramyaGroups);
return assign;
}
我仍然没有分配任何任务。
就工作流程而言,启动后,我有一个索引任务,其组 ID 设置为“索引”。
如果需要更多信息,请告诉我。
我只想获取一个任务并完成它,以便它移动到工作流中的下一个节点。
伙计们严重需要帮助:(
这是我的persistance.xml(如果有帮助的话):
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/持久性/orm_1_0.xsd " xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence">
<!-- <persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit> -->
<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <jta-data-source>jdbc/testDS1</jta-data-source> -->
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
<mapping-file>META-INF/ExtraIndexes.hbm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:mem:mydb" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>
<persistence-unit name="org.jbpm.task">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<!-- <mapping-file>META-INF/TaskEventsorm.xml</mapping-file> -->
<class>org.jbpm.task.Attachment</class>
<class>org.jbpm.task.Content</class>
<class>org.jbpm.task.BooleanExpression</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Delegation</class>
<class>org.jbpm.task.Escalation</class>
<class>org.jbpm.task.Group</class>
<class>org.jbpm.task.I18NText</class>
<class>org.jbpm.task.Notification</class>
<class>org.jbpm.task.EmailNotification</class>
<class>org.jbpm.task.EmailNotificationHeader</class>
<class>org.jbpm.task.PeopleAssignments</class>
<class>org.jbpm.task.Reassignment</class>
<class>org.jbpm.task.Status</class>
<class>org.jbpm.task.Task</class>
<class>org.jbpm.task.TaskData</class>
<class>org.jbpm.task.SubTasksStrategy</class>
<class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
<class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
<class>org.jbpm.task.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:mem:humanTasks" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="sasa" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>