Discussion:
[jboss-user] [jBPM] - getProcess in ProcessInstanceImpl throws a NullPointerException
Sandra Renaud
2013-04-03 08:34:43 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Hello,

I have a NullPointerException when I set process variables and I don't know if it is normal.

The exception comes from this code of jbpm :

   //In ProcessInstanceImpl
   public Process getProcess() {
        if (this.process == null) {
            this.process = kruntime.getKnowledgeBase().getProcess(processId);
        }
        return this.process;
    }


and this is the StackTrace :

SEVERE [javax.faces.event] (http--127.0.0.1-8080-2) java.lang.NullPointerException
          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68)
          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:133)
          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238)
          at com.st.ams.task.management.TaskManager.setProcessVariable(TaskManager.java:234)
          at com.st.ams.task.management.TaskManager$Proxy$_$$_WeldClientProxy.setProcessVariable(TaskManager$Proxy$_$$_WeldClientProxy.java)
          at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstanceFgPlanStep2(NewFinishedGoodProcessManagement.java:149)
          at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstancePlan(NewFinishedGoodProcessManagement.java:89)
          at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstance(NewFinishedGoodProcessManagement.java:71)
          at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement$Proxy$_$$_WeldClientProxy.manageInstance(NewFinishedGoodProcessManagement$Proxy$_$$_WeldClientProxy.java)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
          at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
          at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
          at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
          at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
          at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
          at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
          at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
          at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
          at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:569)
          at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:564)
          at org.jboss.weld.event.EventImpl.fire(EventImpl.java:68)
          at com.st.ams.form.bean.EmailBean.send(EmailBean.java:148)
          at com.st.ams.form.bean.EmailBean$Proxy$_$$_WeldClientProxy.send(EmailBean$Proxy$_$$_WeldClientProxy.java)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:601)
          at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
          at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
          at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
          at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
          at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
          at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
          at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
          at javax.faces.component.UICommand.broadcast(UICommand.java:300)
          at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
          at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
          at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
          at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
          at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
          at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
          at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
          at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
          at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:397)
          at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
          at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
          at java.lang.Thread.run(Thread.java:722)


WARN  [org.jboss.solder.exception.control.log] (http--127.0.0.1-8080-2) No handlers found for exception javax.faces.event.AbortProcessingException: java.lang.NullPointerException



I use persistent session and
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);

return a non null instance.

Regards,
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
wp ren
2013-04-04 02:51:48 UTC
Permalink
wp ren [https://community.jboss.org/people/bird86] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
kruntime.getKnowledgeBase().getProcess(processId);

it is used to get Process definition by the attribute 'id' of the element 'process' in *.bpmn file, not processId(ksession.startProcess('').getId()).
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-04 12:58:55 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Sorry but I don't understand your answer.

I recurrently throws this error when I work with WorkflowProcessInstance.

This is the code that failed :

WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
*wpi.setVariable(key, object);*

or

  WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                    if((wpi == null) || (wpi.getVariable(key) == null)){
       //This case never appears because of persistent sessions
                                   System.out.println("workflow process instance is null :-(");
                    }else{
                                   System.out.println("workflow process instance is NOT null :-)");
                                   retObj = wpi.getVariable(key);

                                   //node info
                                   System.out.println("list of node instance : ");
                                   for(NodeInstance iNode : wpi.getNodeInstances()){
*Node node = iNode.getNode();*
        }
  }
--------------------------------------------------------------

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

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

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Anyone to help please?

I don't succed to debug this.

This is the code of knowledgeSession producer :

log.debug("produce the KnowledgeSession ...");

                    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

List<Resource> resources = getProcessDefinitionList();
                    for (Resource resource : resources) {
                              kbuilder.add(resource, ResourceType.BPMN2);
                    }

                    if ( kbuilder.hasErrors() ) {
                         log.error( kbuilder.getErrors().toString() );
                     }
                    KnowledgeBase kbase = kbuilder.newKnowledgeBase();

                    Environment env = KnowledgeBaseFactory.newEnvironment();
                    env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

                    if(kbase != null){
                              System.out.println("knowledge base NOT null");
                              for(org.drools.definition.process.Process p :kbase.getProcesses()){
                                        System.out.println(" - process "+p.getName()+" ["+p.getId()+"]");
                              }


                    }

                    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
                    System.out.println(" !!!! DEBUG SESSION PERSISTENCE : new session with id : "+ksession.getId()+" !!!!");

And the associated log :

knowledge base NOT null
- process newcpbeforem29commontrunk [com.st.ams.flows.newcpbeforem29commontrunk]
- process newcpbeforem29 [com.st.ams.flows.newcpbeforem29]
- process newfinishedgood [com.st.ams.flows.newfinishedgood]
- process DataCorrections [com.st.ams.flows.datacorrections]
- process newproductline [com.st.ams.flows.newproductline]
Hibernate:
    insert
    into
        SessionInfo
        (lastModificationDate, rulesByteArray, startDate, OPTLOCK)
    values
        (?, ?, ?, ?)
!!!! DEBUG SESSION PERSISTENCE : new session with id : 32 !!!!

After that I try to retrieve all tasks and display task information. This use the method below :

public Object getProcessVariable(Long processInstanceId, Long taskId, String key){
                    Object retObj = null;
                    WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                    if((wpi == null) || (wpi.getVariable(key) == null)){
                              System.out.println("workflow process instance is null :-(");
                    }else{
                              System.out.println("workflow process instance is NOT null :-)");
                              retObj = wpi.getVariable(key);

                              //node info
                              System.out.println("is knowledge runtime null? "+(kSession.getSessionClock() == null));

                              System.out.println("list of node instance : ");
                              for(NodeInstance iNode : wpi.getNodeInstances()){
                                        Node node = iNode.getNode();
                              }
                    }
                    return retObj;
          }

and the associated log :

workflow process instance is NOT null :-)
is knowledge runtime null? false
list of node instance :

but then I have the same error as for my first post in the ProcessInstanceImpl class

Caused by: java.lang.NullPointerException
          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getWorkflowProcess(WorkflowProcessInstanceImpl.java:181) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getNodeContainer(WorkflowProcessInstanceImpl.java:69) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.getNode(NodeInstanceImpl.java:103) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
          at com.st.ams.task.management.TaskManager.getProcessVariable(TaskManager.java:234) [classes:]

It may be the kruntime that is null but how it is null?
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-04 19:42:53 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
h4. What's probably happening is that the code you're calling is happening outside of a transaction.

You've posted the code above, so you can see that the NPE is probably happening because the ProcessInstanceImpl.kruntime field is null.

The kruntime field in the ProcessInstanceImpl is set to null as soon as the transaction is closed. This has to do with making sure that jBPM doesn't cache old copies of processinstances.

So, in this case, when you call
wpi.getNodeInstances()
the transaction has already ended (it ended within the ksession.getProcessInstance() method).

May I ask why you want a list of NodeInstances? There may be other ways to get the information that you're looking for. Also, at the moment that you're looking for the node instances, there shouldn't be any or otherwise you're betting on a race condition.


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

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-05 09:06:34 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Thank you for your answer Marco. You are totally right ; I made a step by step debugging and I could see a call to jpm.dispose() so this may be linked to the closed transaction.

But even if I debug several time I don't really understand what happens and why. What can I do to avoid the transaction to close?

Bellow there are some screenshot of the debug :

Loading Image... Loading Image...
then getProcess() is called 7 times :
Loading Image... Loading Image...
And when it goes to the next step
Loading Image... Loading Image...
all become null! :((
https://community.jboss.org/servlet/JiveServlet/showImage/20565/debug_wpi3.png https://community.jboss.org/servlet/JiveServlet/downloadImage/20565/debug_wpi3.png
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-05 09:33:44 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
There are one or two things you can do to keep the tx from closing -- but you don't want to go down that road. I've been there, and it just gets complexer and ends up in code that's harder to maintain.

(If you are really, really, really sure that you still want to do it after reading this, let me know and I can explain it.)

The main reason you don't want to fool around with tx's when working with jBPM is that jBPM is designed to have full control over transactions -- or in other words, when some of the drools/jbpm developers initially designed the persistence mechanism, they designed it only thinking about the use case where drools/jbpm had control over the tx's: later, some changes were made to make it possible for the users to do that, but the design of the core persistence mechanism (the SingleSessionCommandService) doesn't really play nice with that. With Drools/jBPM 6, we've expanded some of the possibilities, and hopefully we'll add even more in the coming year, but, in my very humble opinion, I don't think we're at a point yet where we can encourage users to take tx control away from the engine.

In short, once you take control of the tx with jBPM, you're getting into "hacking" territory and you'll be more and more on your own, so to speak.

So, having said that, I'm getting back to my original question: why do you want the node instance information? One of the anti-patterns that's emerged with BPM is "reaching into the engine": you're always better of treating the engine as a black box because it makes it easier to migrate to new versions of the engine (or other engines) in the long run. It's the same principle as webservices -- or even just information encapsulation.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-05 09:44:10 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Having written what I've written above (about +not fooling around with tx's and the engine+), if you are really, really, really, really, really, really sure that you want to go down that road, you can do the following:

Start and  end the JTA transaction yourself.

It's that simple: the core persistence mechanism in Drools/jBPM checks to see if there's an active transaction first before starting one -- and it also keeps track of whether or not it started a transaction. That way, it will  not commit the transaction if it has also not started the transaction.

However, as Elmer Fudd used to say, +be vewy, vewy+ careful when you're doing this. Open the tx, do your thing with the engine and close the tx immediately: +remember that the process instance state is saved *only* when the transaction commits*.*+ If you do 2 or more actions that modify the process instance, you'll +probably+ be okay. If you modify the processs instance state +and+ "reach into the engine" to do weird things, good luck!

Some of the other core committers to the jBPM project would disagree with me about this: they might say "Ahh, Marco's being a wimp -- there are no problems with tx's. Go ahead and have a transaction party!". They will be right 99% of the time -- but if you get into complicated (high load/performance) situations with jBPM and user-controlled tx's, I'd wouldn't bet on it.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-05 09:48:30 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
OK I understand your explainations about jbpm black box.

About the nodeInstance it is to look for node metada as I am interesting about Shobhit Tyaqi question : https://community.jboss.org/message/806501#806501 https://community.jboss.org/message/806501#806501

But this is effectively not critical for my project. However, I encounter the same problem for a pillar method of my project that consists in setting process variable at each step of all my processes :

public void setProcessVariable(Long processInstanceId, String key, Object object){
                    WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                    if((wpi == null) || (wpi.getVariable(key) == null)){
                              System.out.println("workflow process instance is null :-(");
                    }else{
                              System.out.println("workflow process instance is NOT null :-)");
                              wpi.setVariable(key, object);
                    }
          }

So this is why I need your help.

Many thank for all your answers.
Sandra
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-05 10:07:45 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Interesting.. well, if you can keep a secret ;D, the metadata that Shobhit was asking about is +actually available+. The jBPM parser parses and stores that information and it's available at (process instance) runtime. Actually, I'm pretty sure it's even available directly from the knowledge base. Of course, the minute we start trying hat metadata, the BPM engine is no longer a black box... I'll make a quick code example and post it on this thread in the next couple days.


But back to your process variable question: unfortunately, the only way to set process variables in a process is at the very beginning, with the following method:

{code}ksession.startProcess(String processId, Map<String, Object> parameters){code}

The String key in the parameters Map should match the name of the.. (searching brain for bpmn2 knowledge... ) property element in the process element. The property's itemSubjectDef should reference a itemDefintiion element defined with the correct data type ("java.lang.String", for example) above/outside the process element in your BPMN2.

At the moment, definining or adding a process variable (that you want to access outside of the engine) is only possible at process instance creation -- with the method described above. At least, as far as I know..  I'll check with some of the other dev's to make sure.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-05 10:08:58 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Argh -- Sandra, how do you make the java code look pretty (with colors, etc.. )? It didn't work for me. :/
--------------------------------------------------------------

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

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

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Lol, I'm looking forward to see your example about accessing metadatas!

To make the java code looks like java code, you must use the advanced editor :
click on add response
then click on advanced editor at right up corner outside the editing panel and accept to exit the page (normally your text is not remove).
finally select the code click on >> button and highlighting.

Easy compare to implement Jbpm! :)

If I can abuse a little more of your patience, I will explain you why I have to set process variable :
I use them to set the userId and groupId at each step for the next step. So I already use the parameter map when I start process :

Map<String, Object> variables = new HashMap<String, Object>();
                    variables.put("flowId", entity.getFlowId());
                    variables.put("flowType", entity.getFlowType().getFlowAcronym());
                    variables.put("codifType", codifType);
                    variables.put("groupAssign", codifType+"_P_ENG");
                    variables.put("userAssign", userAssign);
                    variables.put("line", line);
 
                    taskManager.startProcess("com.st.ams.flows.newfinishedgood", variables);

/**
           * Start a new processInstance of an existing Process
           * and set the variables of this instance
           * @param processId, map of variables
           * @return ProcessInstance created
           */
          public ProcessInstance startProcess(String processId, Map<String, Object> parameters){
                    ProcessInstance p = kSession.startProcess(processId,parameters);
                    return p;
          }


But one of my main targets using jbpm is to manage dynamic assignement, and I was starting doing this with the methode setVariables :

private void manageInstanceFgPlanStep2() {
                    log.debug("Normally this method is called after sending email : " + "it validate the step 2");
                    String userAssign = newFinishedGoodBean.getFlowEntity().getpEngPartEntity().getRecipientPoBeName();
                    log.debug(" ->userAssign = "+userAssign);
                    taskManager.setProcessVariable(taskManager.getManageTask().getProcessInstanceId(), "userAssign", userAssign);
                    taskManager.setProcessVariable(taskManager.getManageTask().getProcessInstanceId(), "groupAssign",
                                                                      "AMS_CRW_"+newFinishedGoodBean.getFlowEntity().getOrganisationalEntity().getCodifType()+"_PO_BE");
                    taskManager.completeTask(taskManager.getManageTask(),null);
          }


This method to set variables worked very good until last week, I have test several flows from start to end... The major change I made is to persist session in database in order to retrive user task even if the application server crashes. So just one line :

StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

replace by
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);


Are you a Jbpm developer? That must be awesome to take part to this project.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-05 15:05:37 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
I am lucky enough to spend most of my time working on jBPM -- and it is indeed awesome!

One approach to your problem is to switch from "pass-by-value" to "pass-by-reference" for your variable assignment. In other words, instead of passing the primitive values (String, int, etc.), you can pass an object containing these values as a parameter. If you want to retrieve the values later, you simply make sure that your code keeps a reference to the object so that you can retrieve and modify the (possibly changed) values.

This means the following:
1. Making sure that the object used is in the classpath -- you need to put in the classpath of the application server or your war.
2. Correctly referencing and extracting the information from your object -- whether that's in your WorkItemHandler implementation or a scriptTask.

Because of persistence, the object also needs to be serialized. Hmm.. I'll make a example of this today/tomorrow and post a link for you here.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-08 10:53:57 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Hello Marco,

I'm not sur to understand how to put an object in the classpath of the war.

I think I will try to modify my processes and add output parameters. And then map output parameters with variables parameters inside the process and if it works I will post it.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Marco Rietveld
2013-04-10 09:03:51 UTC
Permalink
Marco Rietveld [https://community.jboss.org/people/marco.rietveld] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Hi Sandra,

With regards to an object in the classpath of your war, I mean the following:

1. Include the class in the war.
2. Add a jar with the class to the library of your server.1. For JBoss AS 7 (standalone), that would be in the standalone/lib directory.
2. For JBoss AS 5/EAP 5 (default profile), that would be in the server/default/lib directory.


Also, I'm (slowly) making an example for you here: https://github.com/mrietveld/jbpm-more-examples https://github.com/mrietveld/jbpm-more-examples.

If you have an example of a BPMN2 file that you could pass to me (with which you would like to use dynamic assignment/process variables), that would be great!
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-11 08:07:44 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Hello Marco,

I use Jboss 7.

These are two bpmn2 files : first is a complete flow with dynamic assignation, and the second is a flow with a single human node but also with dynamic userId.

I look at your POM example for the branch 5.4, you don't use context injection? I use it, but if I can give you other files to help you make your example, no problem.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-11 13:28:21 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Finally, I set the assignation and other dynamic variable with outputparameters.

First I encounter a runtime exception but it was due to mySQL who creates all foreihn keys with restric cascading and prevent jbpm from updating task parameters.
I just change the cascading type directly in the database and now it's works fine.

Loading Image... Loading Image...

In the step validation (java code):

Map<String, Object> results = new HashMap<>();
                    results.put("userAssign", userAssign);
                    results.put("groupAssign", groupAssign);
                    results.put("formValid", formValid);
 
                    taskManager.completeTask(taskManager.getManageTask(),results);


Thank you very much again Marco!
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
wp ren
2013-04-12 03:06:45 UTC
Permalink
wp ren [https://community.jboss.org/people/bird86] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
h3. http://docs.jboss.org/jbpm/v5.4/userguide/ch.core-basics.html#d0e2102 http://docs.jboss.org/jbpm/v5.4/userguide/ch.core-basics.html#d0e2102
you see the chapter of 6.8.1.Data
Loading Image... Loading Image...

it may be the reason of throws a NullPointerException. it is important, you use or dont use persistence.
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Sandra Renaud
2013-04-12 07:07:40 UTC
Permalink
Sandra Renaud [https://community.jboss.org/people/joploya] created the discussion

"Re: getProcess in ProcessInstanceImpl throws a NullPointerException"

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

--------------------------------------------------------------
Hello,

Thank you for the link. Indeed, when I don't use persistence I just used the workflowProcessInstance and it works great. And the NullPointerException apear after changing to persistent session.

But, I already try the command base approach and in my case it doesn't change anything. 

My conclusion that seams to work for now is :
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
wpi.getVariable(key);

to access variables even if I use persistent session.

and define output parameters mapped to process variables directly inside the process and pass a map of results to the complete task method to dynamically change process variables.
--------------------------------------------------------------

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

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