[jbpm5.1]Can get the current nodeId,correctly??
leo87601 Nov 28, 2011 10:59 AMDear all,
We want to get the current node name after completed a task.But it is not working correctly some time.
we found the error happen here.
long nodeId = wfInstance.getNodeInstances().iterator().next().getNodeId();
BTW, Before we setted the persistence, this issue does not happen.
The data seem had problem too, we found that the PROCESSINSTANCEINFO's lastmodificationdate(12:44:36) is the same as the pending node's log time, but the workflow had been run into Qualified at 12:44:43.
We can not see the processinstancebytearray, so not sure the processintanceinfo had been updated correctly or not?
select * from nodeinstancelog where processinstanceid =134 order by id desc;
ID | TYPE | NODEINSTANCEID | NODEID | PROCESSINSTANCEID | PROCESSID | LOG_DATE | NODENAME |
---|---|---|---|---|---|---|---|
683 | 0 | 5 | 9 | 134 | LeadProcess | 2011-11-28 12:44:43.048 | Qualified |
682 | 1 | 4 | 8 | 134 | LeadProcess | 2011-11-28 12:44:43.048 | Gateway |
681 | 0 | 4 | 8 | 134 | LeadProcess | 2011-11-28 12:44:43.048 | Gateway |
680 | 1 | 3 | 5 | 134 | LeadProcess | 2011-11-28 12:44:43.033 | Pending |
679 | 0 | 3 | 5 | 134 | LeadProcess | 2011-11-28 12:44:36.36 | Pending |
SELECT * FROM PROCESSINSTANCEINFO where iNSTANCEID =134;
INSTANCEID | LASTMODIFICATIONDATE | LASTREADDATE | PROCESSID | PROCESSINSTANCEBYTEARRAY | STARTDATE | STATE | OPTLOCK |
---|---|---|---|---|---|---|---|
134 | 2011-11-28 12:44:36.376 | 2011-11-28 12:57:39.437 | LeadProcess | aced00057765000852756c65466c6f770000000000000086000b4c65616450726f6365737300000001000000000000000400000000001200000000000000030000000000000005001b00000000000000fd00000000000100000000000000020006616374696f6e0000000074000750656e64696e67770c0006757365724964000000007400056b72697376 |
Environment : Jboss 5.1, h2 database, windows 2003. we are using the default setting of jbpm-5.1.0.Final-installer-full.zip
Here is our code of complete task.
public ProcessInstanceBO completeUserTask(long instanceId, String toState){
ProcessInstance instance = ksession.getProcessInstance(instanceId); // init process by instanceid
WorkflowProcessInstance wfInstance = ((WorkflowProcessInstance)instance);
// get currently Node instances
Iterator<NodeInstance> iterator = wfInstance.getNodeInstances().iterator();
NodeInstance nodeInstance = iterator.next();
// compelte workitem.
final long workItemId = workItemNodeInstance.getWorkItemId();
final Map<String, Object> results = new HashMap<String, Object>();
results.put(this.ACTION, toState);
ksession.getWorkItemManager().completeWorkItem(workItemId, results);
ksession.getWorkItemManager().abortWorkItem(workItemId);
// retrieve the process instance again.
instance = ksession.getProcessInstance(instanceId);
WorkflowProcessInstance wfInstance = (WorkflowProcessInstance) instance;
//retrieve the current node again. we expect that , here is the next step's nodeid, but it doesn't work correctly every time. some time it still in the last stage.
long nodeId = wfInstance.getNodeInstances().iterator().next().getNodeId();
logger.debug("Process current node id: " + nodeId );
WorkflowProcess wfProcess = (WorkflowProcess) readKnowledgeBase().getProcess(wfInstance.getProcessId());
//We cannot get the correct Node name because.
Node node = wfProcess.getNode(nodeId);
....
}
We are confusing on this issue, please help. Thanks a lots.