6 Replies Latest reply on Jun 15, 2006 8:46 AM by Ahmed Adly

    jBPM ProcessDefinition instance state and POJO class state

    Ahmed Adly Newbie

      In some cases we'll need to link the token state with our POJO state
      for example: suppose that we have a car rental application and its workflow is:

       1.add a new car to our warehouse
       2.rent a car from warehouse.
       3. do some maintenance to car.
       [-- FORK --]
       / \
       / \
       if car is OK then car else car goes to
       returned to warehouse. mechanic to repair

      This is abstract example. so what I mean that i will create a POJO class that reflect a car in my database and this POJO has an attribute that defines what is the state of my car (created, inWarhouse, rented, goToMaintenance, carOK, or carInRepair)

      I know that the instance of each ProcessDefinition can be persisted in DB with its current state, but in this case we do not need this, we need that when creating a new instance of the process definition, I tell the instance to jump to a state or node equivalent to the state of my Car POJO selected from database. By another mean I need to mapping the ProcessDefinition instance state with one of my POJO attributes and define the instance state or node by calling somthing like this

      The question is : is this possible? if yes by any way, how we can implement this?

      Ahmed Adly,
      Java Developer

        • 1. Re: [URGENT] jBPM ProcessDefinition instance state and POJO
          Ahmed Adly Newbie

          So, long time waiting for reply,
          I hope that is not a bad thing. any reply from any one in this forum moderators will be gracefully appreciated

          • 2. Re: jBPM ProcessDefinition instance state and POJO class sta
            Koen Aers Master


            The reason why you have to wait this long is probably because no one (probably including me) has a clue of what you really mean... But I am gonna try anyway.
            If you want to use (a reference to) your car as a process variable in the process instance: yes you can. Or if you want to externalize the state info of your car into individual process variables of the process instance: yes you can.
            It is all up to you.


            • 3. Re: jBPM ProcessDefinition instance state and POJO class sta
              Ahmed Adly Newbie

              Dear Koen,
              I am very happy for your reply.
              And I am sorry for you did not understand me. but I'll try to make it clear.
              I want to create instance of this Process Definition. Then make the token to start at node #3 (which is do some maintenance to car) instead of start state without calling signal() method many time to go to node #3.

              That mean
              1. I want to create a Car process when admin login to add new car to the system.

              2. Then after a time system manager login to rent this car.
              3. after a period the manager login again to check that the car is return but need some maintenance.

              I have seen your example that available with jBPM source, in this example there is something like this, but my case differs from that example, in my project I need to persiste Car POJO data with it's current state, the POJO data contains many attributes that are not supported using your instance variable that persisted in database in jbpm_variableinstance table such as Java Vector, Set, ArrayList, ...etc. Any way, variables and attributes of Car POJO will be persisted in Car Table, so we want not to persiste the token of process instance, and when manager login again retrieves the Car data and creates instance of Car Process Difinition and set the created token current node to node #3 (which is the state of the retrieved car) without make many signals to make token reachs this node.

              By another mean, I want to make a synchronization between my POJO state and the created token state, because our project has offline booking module that can not persisted till my application connect to internet.

              This is Urgent for us, it will make big difference in our project developing.

              Thanks alot,

              • 4. Re: jBPM ProcessDefinition instance state and POJO class sta
                Koen Aers Master


                I still don't understand very well what you mean, but here we go again:

                - To move the token around in your processdefinition you have to signal the token. If you have nodes where the process execution does not have to wait, use generic nodes instead of task nodes or states.
                - To store the state of business objects like your car, you can use your normal way of doing things and use the id field of your car as a process variable in your process.


                • 5. Re: jBPM ProcessDefinition instance state and POJO class sta
                  Ahmed Adly Newbie

                  Dear Koen,
                  Sorry for late about reply but I am busy in my work to login and reply, any way I have found the answer what I am looking for but I can not explain it now; when I finish my tasks and get some time I will expose what I have experienced, I promise. I am appreciating your reply

                  • 6. Re: jBPM ProcessDefinition instance state and POJO class sta
                    Ahmed Adly Newbie

                    here I am, back again
                    I hope that reply help any one who need this.

                    this is a pice of code that get car POJO from database, assuming that the car state now in state #2 which is "2.rent a car from warehouse."

                    //read definition XML file
                    ProcessDefinition carProcessDefinition=ProcessDefinition.parseXmlResource(processDefFileName);
                    //create new process instance from this definition
                    ProcessInstance carProcessInstance=carProcessDefinition.createProcessInstance();
                    //get my car object from database
                    Car car=carService.getCarById(carId);
                    //get a state object in this process instance using the POJO object state
                    //carState attribute in the car POJO is string that represent the node name
                    //in the process definition.
                    Node currentNode=(Node)carProcessDefinition.getNode(car.getCarState());
                    //now this will set the active (current) node of the process definition to equivalent
                    //state of my CarPOJO class
                    //now we will signal to the next state which is doSomeMaintenance

                    Thanks a lot,
                    Ahmed Adly