Discussion:
[jboss-user] [jBPM] - ProcessContext Throwing NPE
roxy1987
2013-03-07 16:04:33 UTC
Permalink
roxy1987 [https://community.jboss.org/people/roxy1987] created the discussion

"ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/801365#801365

--------------------------------------------------------------
Hi community,

I have run into an issue trying to set a variable.
What I want is to set a variable while completing a task. The following is what I do :


//Just before task complete I call the following code.

StatefulKnowledgeSession kSession = BpmRepositoryConfig.createSession();
  ProcessContext kContext = new ProcessContext(kSession);
  ProcessInstance processInstance = kSession.getProcessInstance(taskData.getProcessInstanceId());
  logger.info("ProcInst : "+processInstance.getId());
  kContext.setProcessInstance(processInstance);
  for (Entry<String, Object> entry : map.entrySet())
  {
      logger.info(entry.getKey() + "/" + entry.getValue());
      if(!(kContext == null))
       kContext.setVariable(entry.getKey(), entry.getValue());
      else
       logger.severe("KContext is Null");
  }
 


KContext is not null. But it throws the following NPE :


[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R java.lang.NullPointerException
[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R  at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68)
[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R  at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:133)
[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R  at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238)
[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R  at org.drools.spi.ProcessContext.setVariable(ProcessContext.java:68)
[3/7/13 10:47:46:951 COT] 00000110 SystemErr     R  at pe.com.bcp.model.BpmAPI.createTaskVariables(Unknown Source)


Need help please. And other ideas to create task variables are welcome. Thanks.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/801365#801365]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
roxy1987
2013-03-11 16:04:39 UTC
Permalink
roxy1987 [https://community.jboss.org/people/roxy1987] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/801952#801952

--------------------------------------------------------------
Guys,
Any Help on this please?

Regards.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/801952#801952]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2013-03-13 02:42:59 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/802236#802236

--------------------------------------------------------------
Hi Roxy,

Do you want to set "process variable" or "task output variable"?
Your code seems to try to set "process variable"

How about setting the variable via the Task Output Variable and then map those task output to the process variable that you want to set.  That works with JBPM5.4..


Regards,
Thomas Setiabudi
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802236#802236]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
roxy1987
2013-03-13 15:27:07 UTC
Permalink
roxy1987 [https://community.jboss.org/people/roxy1987] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/802390#802390

--------------------------------------------------------------
Hi Thomas,

I wanna set a variable after the process has been started. For instance, consider a process with 2 tasks.
User fills in a text field(say 'newUser') while completing 1st task and the value of the text field is used as the actor id for the next task('#newUser').
And I dont wanna use any script node in between.
I have tried using a Map and putting it in the content of the task and mapping with out parameter but no luck. So probably I did nt use it correctly. So may be you could give me a running example code.

Thanks.



--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802390#802390]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2013-03-14 03:44:10 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/802534#802534

--------------------------------------------------------------
Hi, (changed your name is it? was Roxy1987 right?)

So please find the attached process definition (test1.testAssignUser.v1.bpmn2)
The process has two process variables, they are:
1. pvFirstActor
2. pvSecondActor

The process is like what you said, it has 2 human task:
1. HumanTask1 with actor Id taken from the value of "pvFirstActor"
2. HumanTask2 with actor Id taken from the value of "pvSecondActor"


when we first start process we set the value of variable "pvFirstActor" that will be used as the first Human Task actor Id

then the first human task has output variable that called "secondActorName" that is mapped to "pvSecondActor"

so after we complete HumanTask1 then the value of "pvSecondActor" will be set based on the output of the HumanTask1

Attached a working test case too, look at the testAssignVariableAsActorId() test function inside PersistentProcessTest class in jbpm5-PersistentProcess.7z (it is based on sample from Mauricio Salatino / Salaboy)


Regards,
Thomas Setiabudi
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802534#802534]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Shobhit Tyagi
2013-03-14 14:59:11 UTC
Permalink
Shobhit Tyagi [https://community.jboss.org/people/roxy1987] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/802698#802698

--------------------------------------------------------------
Yeah my user id was getting displayed so I changed that.

Well thank you so much Thomas.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802698#802698]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Shobhit Tyagi
2013-03-14 16:49:48 UTC
Permalink
Shobhit Tyagi [https://community.jboss.org/people/roxy1987] created the discussion

"Re: ProcessContext Throwing NPE"

To view the discussion, visit: https://community.jboss.org/message/802738#802738

--------------------------------------------------------------
Thomas,

I tried the code. but it didnt work. Its the same thing. Following is my process def :


  <?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.jboss.org/drools"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
xmlns:g="http://www.jboss.org/drools/flow/gpd"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns="http://www.jboss.org/drools">

<itemDefinition id="_taskUserItem" structureRef="String" />

<itemDefinition id="_2-taskUserItem" structureRef="String" />

<itemDefinition id="_3-taskUserItem" structureRef="String" />

<process processType="Private" isExecutable="true" id="com.sample.dynamicTaskVariable" name="Dynamic Task Variable Process" tns:packageName="defaultPackage" >

<!-- process variables -->
<property id="taskUser" itemSubjectRef="_taskUserItem"/>

<!-- nodes -->
<startEvent id="_1" name="StartProcess" />
<userTask id="_2" name="Create Variable" >
<ioSpecification>
<dataInput id="_2_TaskNameInput" name="TaskName" />
<dataInput id="_2_CommentInput" name="Comment" />
<dataOutput id="_2_taskVariableOutput" name="taskVariable" />
<inputSet>
<dataInputRefs>_2_TaskNameInput</dataInputRefs>
<dataInputRefs>_2_CommentInput</dataInputRefs>
</inputSet>
<outputSet>
<dataOutputRefs>_2_taskVariableOutput</dataOutputRefs>
</outputSet>
</ioSpecification>
<dataInputAssociation>
<targetRef>_2_TaskNameInput</targetRef>
<assignment>
<from xsi:type="tFormalExpression">Create Variable</from>
<to xsi:type="tFormalExpression">_2_TaskNameInput</to>
</assignment>
</dataInputAssociation>
<dataInputAssociation>
<targetRef>_2_CommentInput</targetRef>
<assignment>
<from xsi:type="tFormalExpression">createVariable.xhtml</from>
<to xsi:type="tFormalExpression">_2_CommentInput</to>
</assignment>
</dataInputAssociation>
<dataOutputAssociation>
<sourceRef>_2_taskVariableOutput</sourceRef>
<targetRef>taskUser</targetRef>
</dataOutputAssociation>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>krisv</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<userTask id="_3" name="Verify Variable" >
<ioSpecification>
<dataInput id="_3_TaskNameInput" name="TaskName" />
<dataInput id="_3_CommentInput" name="Comment" />
<inputSet>
<dataInputRefs>_3_TaskNameInput</dataInputRefs>
<dataInputRefs>_3_CommentInput</dataInputRefs>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
<dataInputAssociation>
<targetRef>_3_TaskNameInput</targetRef>
<assignment>
<from xsi:type="tFormalExpression">Verify Variable</from>
<to xsi:type="tFormalExpression">_3_TaskNameInput</to>
</assignment>
</dataInputAssociation>
<dataInputAssociation>
<targetRef>_3_CommentInput</targetRef>
<assignment>
<from xsi:type="tFormalExpression">verifyVariable.xhtml</from>
<to xsi:type="tFormalExpression">_3_CommentInput</to>
</assignment>
</dataInputAssociation>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>#{taskUser}</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<endEvent id="_4" name="End" >
<terminateEventDefinition />
</endEvent>

<!-- connections -->
<sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
<sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />
<sequenceFlow id="_3-_4" sourceRef="_3" targetRef="_4" />

</process>

<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="com.sample.dynamicTaskVariable" >
<bpmndi:BPMNShape bpmnElement="_1" >
<dc:Bounds x="132" y="216" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_2" >
<dc:Bounds x="228" y="204" width="169" height="73" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" >
<dc:Bounds x="444" y="204" width="169" height="73" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_4" >
<dc:Bounds x="672" y="216" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_1-_2" >
<di:waypoint x="156" y="240" />
<di:waypoint x="312" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_2-_3" >
<di:waypoint x="312" y="240" />
<di:waypoint x="528" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_3-_4" >
<di:waypoint x="528" y="240" />
<di:waypoint x="696" y="240" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

</definitions>



Then I complete the task as following :


public static void completeTask(long taskId, String userId, Map<String, Object> map) throws Exception
{
  String name = "client 1"+UUID.randomUUID();
  TaskClient client = new TaskClient(new HornetQTaskClientConnector(name, new HornetQTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
  BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();
  ContentData contentData = null;
  client.connect(ipAddress, port);
  try
  {
   contentData = ContentMarshallerHelper.marshal(map, null);
   client.complete(taskId, userId, contentData, responseHandler);
   responseHandler.waitTillDone(5000);
   BpmAPI.completeWorkItem(taskId);
  }
  catch(Exception e)
  {
   BpmExceptionHandler.handleException(e);
  }
  finally
  {
   if(client != null)
   {
    client.disconnect();
   }
  }
}
 


In the map above I put a variable for next task.
Only difference in the code is that I complete the task and then I complete the work item.

Regards.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802738#802738]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...