1 Reply Latest reply on Sep 24, 2005 4:34 PM by Ronald van Kuijk

    Help me Understand linking a process to an instance of an ob

    Aaron Novice

      I'm trying to learn more about jBPM, as I can use it in several of my projects. However, in going over the documentation, I'm left feeling that there are some gaps in my understanding.

      In the documentation, you show how you can load a "waiting" instance of the workflow, using the method:

      jbpmSession.findLatestProcessDefinition("ProcessDefinitionName");
      

      Since you can obviously have hundreds of this specific Process Definition tied to other objects, how can you get the specific Process for the specific object instance? I saw how you can load a specific ProcessInstance using:
      List processInstances = graphSession.findProcessInstances(processDefinition.getId());
      ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
      

      Obviously, this loads the first instance in the List. Not only that, but I have to build a List of all ProcessInstances? But how do we know which instance is tied to which object? Is there a way (and I'm sure there is, I just haven't seen it yet) to grab the id of the processInstance as soon as one is created for an object? How?

      I can create a new ProcessDefinition for object1, but then, how do I retrieve the id of that ProcessDefinition for later re-use and/or action to it? Kinda like (suedo):
      object1.setBpmId(processInstance.getId());
      

      Then, several weeks later, I'm ready to kick off another transition to this object, I can just load the current ProcessInstance tied to that object (suedo):
      ProcessInstance processInstance = jbpmSession.loadInstance(object1.getBpmID());
      


      I guess I'm just wondering how I can get a processInstance ID, as the instance is freshly created without having to build a List of ALL the processInstances, AND, how can load that processInstance ID when I'm ready for it?

      I'm sure it's in the documentation, so if it is, I apologize now. You can just send me the link. If not, can I get some clarification on using this in the "real world"?

      Thank you!

        • 1. Re: Help me Understand linking a process to an instance of a
          Ronald van Kuijk Master

           

          "Neelixx" wrote:
          I'm trying to learn more about jBPM, as I can use it in several of my projects. However, in going over the documentation, I'm left feeling that there are some gaps in my understanding.

          In the documentation, you show how you can load a "waiting" instance of the workflow, using the method:
          jbpmSession.findLatestProcessDefinition("ProcessDefinitionName");
          



          Wrong, this finds the latest definition of a process, not a process instance

          "Neelixx" wrote:


          Since you can obviously have hundreds of this specific Process Definition tied to other objects, how can you get the specific Process for the specific object instance?



          I hope not... hundreds of process definitions tied to objects.... maybe instances, but what do you mean by 'tied'

          "Neelixx" wrote:

          I saw how you can load a specific ProcessInstance using:
          List processInstances = graphSession.findProcessInstances(processDefinition.getId());
          ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
          

          Obviously, this loads the first instance in the List. Not only that, but I have to build a List of all ProcessInstances? But how do we know which instance is tied to which object?

          Again, what do you mean by 'tied' and what kind of objects? If you mean you have some own data that is being used in process instances ( and I hope not in multiple ones) than you need some kind of mapping. Either outside jBPM (which I advise) or inside (store the primary key of your object in a process variable
          "Neelixx" wrote:

          Is there a way (and I'm sure there is, I just haven't seen it yet) to grab the id of the processInstance as soon as one is created for an object? How?

          See previous remark
          "Neelixx" wrote:

          I can create a new ProcessDefinition for object1, but then, how do I retrieve the id of that ProcessDefinition for later re-use and/or action to it? Kinda like (suedo):

          What about storing it somewhere? Would be the most logical thing to me
          "Neelixx" wrote:

          object1.setBpmId(processInstance.getId());
          


          Yep... that's what I do to
          "Neelixx" wrote:

          Then, several weeks later, I'm ready to kick off another transition to this object, I can just load the current ProcessInstance tied to that object (suedo):
          ProcessInstance processInstance = jbpmSession.loadInstance(object1.getBpmID());
          


          I guess I'm just wondering how I can get a processInstance ID, as the instance is freshly created without having to build a List of ALL the processInstances, AND, how can load that processInstance ID when I'm ready for it?

          Look at the api.... it's all there
          "Neelixx" wrote:



          I'm sure it's in the documentation, so if it is, I apologize now. You can just send me the link. If not, can I get some clarification on using this in the "real world"?

          There is nothing wrong with your understanding... I even bet that the time it took you to write this, you could have found it in the api to. You even used the right class allready http://docs.jboss.com/jbpm/v3/javadoc/org/jbpm/db/GraphSession.html#loadProcessInstance(long)
          "Neelixx" wrote:


          Thank you!


          Any time, but besides using the documentation also use the javadoc. Or better, a code completion IDE which shows you the javadoc (like eclipse)
          Saves you a lot of time