Please find following code <?xml version="1.0" encoding="UTF-8"?>
|
| <process-definition
| xmlns="http://jbpm.org/3/jpdl"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://jbpm.org/3/jpdl
http://jbpm.org/xsd/jpdl-3.0.xsd "
| name="simple">
| <start-state name="start">
| <transition name="toCheckDSCR" to="Check DSCR">
| <action name="Read DSC Ratio"
class="com.sample.action.FirstActionHandler"></action>
| </transition>
| </start-state>
| <end-state name="end">
| </end-state>
| <decision name="Check DSCR">
| <transition name="toReadLoansData" to="Read Loans Data">
| <condition>
| executionContext.getVariable("DSCRatio").intValue() > 0
| </condition>
| </transition>
| <transition name="toRejectLoan" to="Reject Loan">
| <condition>
| executionContext.getVariable("DSCRatio").intValue() == 0
| </condition>
| </transition>
| </decision>
| <task-node name="Reject Loan">
| <transition name="toEndFromRejectLoan" to="end">
| <action name="action1"
class="com.sample.action.LoanRejectHandler"></action>
| </transition>
| </task-node>
| <state name="Read Loans Data">
|
| <transition name="toProcessLoanDecision" to="Process Loan Decision">
| <action name="action1"
class="com.sample.action.DatabaseActionHandler"></action>
| </transition>
| </state>
| <decision name="Process Loan Decision">
| <transition name="toProcessLoan" to="Process Loan">
| <condition>
|
executionContext.getVariable("LoanProcessingDecision").toString().equals("Yes")
| </condition>
| </transition>
| <transition name="toEndFromProcessLoanDecision" to="end">
| <condition>
|
executionContext.getVariable("LoanProcessingDecision").toString().equals("No")
| </condition>
| </transition>
| </decision>
| <task-node name="Process Loan">
| <transition name="toEndFromProcessLoan" to="end">
| <action name="action1"
class="com.sample.action.ProcessLoanHandler"></action>
| </transition>
| </task-node>
|
| </process-definition>
Code for Test class
| package com.sample;
|
| import java.io.FileReader;
| import java.util.ArrayList;
|
|
|
| import junit.framework.TestCase;
|
| import org.jbpm.db.JbpmSession;
| import org.jbpm.db.JbpmSessionFactory;
| import org.jbpm.graph.def.ProcessDefinition;
| import org.jbpm.graph.exe.ProcessInstance;
| import org.jbpm.graph.exe.Token;
| import org.jbpm.jpdl.xml.JpdlXmlReader;
|
| public class SimpleProcessTest extends TestCase {
|
| static JbpmSessionFactory jbpmSessionFactory =
JbpmSessionFactory.buildJbpmSessionFactory();
|
| public void testSimpleProcess() throws Exception {
|
| //saveProcessDefinition();
| //saveProcessInstance();
| readProcessInstance();
|
| }
|
| public void saveProcessInstance() {
|
| // obtain a session
| JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
| try {
| ProcessDefinition loanProcess =
jbpmSession.getGraphSession().findLatestProcessDefinition("simple");
| // start a user managed transaction
| jbpmSession.beginTransaction();
|
| ProcessInstance loanInstance = new ProcessInstance(loanProcess);
| loanInstance.signal();
|
| // store the result in the database
| jbpmSession.getGraphSession().saveProcessInstance(loanInstance);
|
| // commit the user transaction
| jbpmSession.getConnection().commit();
|
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| finally {
| // close the session.
| jbpmSession.close();
| }
| }
|
| public void readProcessInstance()
| {
| JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
| ProcessDefinition procDef =
jbpmSession.getGraphSession().findLatestProcessDefinition("simple");
|
| ArrayList arlProcInsts = (ArrayList)
jbpmSession.getGraphSession().findProcessInstances(procDef.getId());
|
|
| int count = arlProcInsts.size();
| ProcessInstance procInst = null;
| System.out.println(">>>>>> "+count + " >>>>>>> " + procDef);
| for (int i = 0; i < count; i++)
| {
| procInst = (ProcessInstance) arlProcInsts.get(i);
| System.out.println("Process Instance ID = " +
procInst.getId());
| System.out.println("Has Ended Value = " +
procInst.hasEnded());
| }
|
| Token rootToken = procInst.getRootToken();
|
| Token token = rootToken.findToken("Check DSCR/Read Loans Data");
| System.out.println("token = " + token);
|
| rootToken.signal("toReadLoansData");
| procInst.signal();
|
| jbpmSession.close();
| }
|
| public void saveProcessDefinition(){
|
|
| JbpmSession jbpmSession =
jbpmSessionFactory.openJbpmSession();
| try{
| ProcessDefinition definition = new JpdlXmlReader(new
FileReader("D:/TestProcess/src/process/simple.par/processdefinition.xml")).readProcessDefinition();
|
| /* assertNotNull("Definition should not be null",
definition);
|
| // Create an instance of the process
definition.*/
| //ProcessInstance instance = new
ProcessInstance(definition);
|
//*********************************************************************
| //instance.signal();
|
|
jbpmSession.getGraphSession().saveProcessDefinition(definition);
| jbpmSession.getConnection().commit();
|
| }
| catch(Exception e)
| {
| e.printStackTrace();
| }
| finally {
| // close the session.
| jbpmSession.close();
| }
|
| }
|
| }
|
|
1. In 'saveProcessDefinition' method, I am reading the process definition XML
from file system and store it to jBPM database.
2. In 'saveProcessInstance' method, the process definition is read from the
database and instance is created. This instance is saved to database.
3. In 'readProcessInstance' the instance is read from database and executed
further.
I am getting the error in step 3. But not sure that steps 1 and 2 above are
correct and are not the root cause of error in step 3.
Please confirm that the code is correct. Saving the process definition in
database must be the common task, are there any best practices defined to do
such common tasks.
Thanks and Regards,
Nilesh
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3912011#3912011
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3912011
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user