12 Replies Latest reply on Nov 20, 2011 11:45 PM by Ashish T

    JBPM5 Implementation

    Donald Walters Newbie

      Hello,

       

      I am still trying to migrate from v4 to v5 but I am kinda stuck on a couple of points.

      In version 4 I could create a custom node which would use my java class. Is there an equivalent in the BPM2 notation?

      Also, I have a state node with a timer that has a <on event="start"> and a <on event="timeout">. What is the v5 equivalent?

       

      Thanks

        • 2. Re: JBPM5 Implementation
          Mauricio Salatino Master

          Hi Donald sorry for the delay in the answer.

          In jBPM5 you have the concept of WorkItem that allows you to add your custom nodes with domain specific functionality.

          Indise BPMN2 the concept of Service Task is used to model your processes and then in runtime you can bind a named Service Task (a Service task with a specific type) to a work item.
          For creating a new work item with your specific functionality you need to create a new WorkItemHandler. For doing this you need to implement the WorkItemHandler interface. Please check the official documentation, in the Domain Specific Activities where the concept of work item handler is explained.

          Cheers

          • 3. Re: JBPM5 Implementation
            Maciej Swiderski Master

            Donald Walters wrote:

            In version 4 I could create a custom node which would use my java class. Is there an equivalent in the BPM2 notation?

            In addition to what Mauricio posted you could use Service Task with "other" implementation that in fact will execute your defined operation, which could be java method. Note that you need to define interface and operation in the bpmn2 definition.

            Please have a look at one of the examples shipped with jBPM5.1

            service task bpmn2 definition

            test case for that process definition (look at method testServiceTask)

             

             

            Donald Walters wrote:

             

            Also, I have a state node with a timer that has a <on event="start"> and a <on event="timeout">. What is the v5 equivalent?

             

            In my opinion you should employ intermediate timer event, so it can be attached to a particular activity (boundary) or as part of the process flow which in fact will act as wait state until timer expires. Second one looks bit more suitable for your case.

            Not sure how to deal with on start from v4, what was the purpose of the on start event on that state node?

             

            HTH

            Maciej

            • 4. Re: JBPM5 Implementation
              Donald Walters Newbie

              Thanks guys but I think I am missing something here.

               

              I have the following JBPM4 definition. The result from each process goes to the other process also the original variables that are passed.

              <?xml version="1.0" encoding="UTF-8"?>

              <process name="test" xmlns="http://jbpm.org/4.4/jpdl">

                 <start>

                    <transition name="case2" to="prompt1"/>

                 </start>

               

                 <custom name="prompt1" class="com.core.executors.GenericProcess">

                    <transition name="case22" to="delete6"/>

                    <property name="properties">

                       <map class="java.util.HashMap">

                          <entry>

                             <key>

                                <string value="message"/>

                             </key>

                             <value>

                                <string value="Processing message 1"/>

                             </value>

                          </entry>

                          <entry>

                             <key>

                                <string value="process.type"/>

                             </key>

                             <value>

                                <string value="prompt"/>

                             </value>

                          </entry>

                       </map>

                    </property>

                 </custom>

               

              <custom name="delete6" class="com.core.executors.GenericProcess">

                    <transition name="case22" to="end6"/>

                    <property name="properties">

                       <map class="java.util.HashMap">

                          <entry>

                             <key>

                                <string value="filter"/>

                             </key>

                             <value>

                                <string value="*.doc"/>

                             </value>

                          </entry>

                          <entry>

                             <key>

                                <string value="process.type"/>

                             </key>

                             <value>

                                <string value="filter"/>

                             </value>

                          </entry>

                       </map>

                    </property>

                 </custom>

               

                 <end name="end6"/>

              </process>

               

              Below is the GenericProcess class

               

              public class GenericProcess implements ActivityBehaviour {

                  private HashMap<String, String> properties = new HashMap<String, String>();

               

               

                  public void execute(ActivityExecution ae) throws Exception {

                      String type = properties.get("process.type");

                      Object result = ae.getVariable("response");

                      if (type.equals("prompt")) {

                          result = new PromptProcess().execute(result, properties);

                      }

                      if (type.equals("filter")) {

                          result = new FilterProcess.execute(result, properties);

                      }

               

                          ae.setVariable("response", result);

                  }

               

               

                  public HashMap<String, String> getProperties() {

                      return properties;

                  }

               

               

                  public void setProperties(HashMap<String, String> properties) {

                      this.properties = properties;

                  }

              }

               

              How do I replicate something like this in JBPM5?

              • 5. Re: JBPM5 Implementation
                Maciej Swiderski Master

                Donald, please find attached very simple version of your process in BPMN2. It does not cover all aspects of your process, for instance parameters are simple strings but I think that could be achieved rather easy.

                 

                HTH

                Maciej

                1 of 1 people found this helpful
                • 6. Re: JBPM5 Implementation
                  Donald Walters Newbie

                  Thanks for the response.

                   

                  But, how do I access the response in the subsequent service? Also, for every service task I would have to define a separate interface?

                  • 7. Re: JBPM5 Implementation
                    Maciej Swiderski Master

                    To access response in subsequent service task make use of parameter mapping of that service task. You use parameter mapping to inject input to the service task and you use result mapping to get the output back from service task.

                     

                    You do not need to create separate interfaces for every service task, you can reuse it. Define once and make use of it as many times as you want. The same way you can create many methods/operations in the defined interface and make use of them in your service tasks.

                    1 of 1 people found this helpful
                    • 8. Re: JBPM5 Implementation
                      Donald Walters Newbie

                      Thanks Guys. I was able to make something work based on the answers above. It may not be as clean as it aught to be it is similar to what I have in the JBPM4.

                       

                      Basically i created a dummy interface... This is just so that the BPMN2 xml won't scream

                       

                      <itemDefinition id="_2_InMessageType" structureRef="java.lang.String"/>

                          <message id="_2_InMessage" itemRef="_2_InMessageType"/>

                          <interface id="_2_ServiceInterface" name="com.core.DummyService">

                              <operation id="_2_ServiceOperation" name="handle">

                                  <inMessageRef>_2_InMessage</inMessageRef>

                              </operation>

                          </interface>

                       

                      ...

                       

                      <serviceTask id="prompt6" name="prompt6" operationRef="_2_ServiceOperation" implementation="Other">

                                  <ioSpecification>

                                      <dataInput id="prompt6_type" name="type"/>

                                      <dataInput id="prompt6_processItem" name="processItem"/>

                                      <dataInput id="prompt6_message" name="message"/>

                                      <dataOutput id="prompt6_result" name="processItem"/>

                                      <inputSet>

                                          <dataInputRefs>prompt6_type</dataInputRefs>

                                          <dataInputRefs>prompt6_processItem</dataInputRefs>

                                          <dataInputRefs>prompt6_message</dataInputRefs>

                                      </inputSet>

                                      <outputSet>

                                          <dataOutputRefs>prompt6_result</dataOutputRefs>

                                      </outputSet>

                                  </ioSpecification>

                                  <dataInputAssociation>

                                      <targetRef>prompt6_message</targetRef>

                                      <assignment>

                                          <from xsi:type="tFormalExpression">Hello World!!</from>

                                          <to xsi:type="tFormalExpression">prompt6_message</to>

                                      </assignment>

                                  </dataInputAssociation>

                                  <dataInputAssociation>

                                      <targetRef>prompt6_type</targetRef>

                                      <assignment>

                                          <from xsi:type="tFormalExpression">com.core.test.Prompt</from>

                                          <to xsi:type="tFormalExpression">prompt6_type</to>

                                      </assignment>

                                  </dataInputAssociation>

                                  <dataInputAssociation>

                                      <sourceRef>processItem</sourceRef>

                                      <targetRef>prompt6_processItem</targetRef>

                                  </dataInputAssociation>

                                  <dataOutputAssociation>

                                      <sourceRef>prompt6_result</sourceRef>

                                      <targetRef>processItem</targetRef>

                                  </dataOutputAssociation>

                              </serviceTask>

                       

                       

                       

                      Then I created a handler and register it for the Service Task. This will take the process type parameter and create the necessary class.

                       

                      @Override

                          public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

                              String className = (String) workItem.getParameter("processType");

                              try {

                                  Class clazz = Class.forName(className);

                       

                       

                                  Constructor constructor = clazz.getConstructor(Map.class);

                       

                       

                                  ProcessItem processItem = (ProcessItem)workItem.getParameter("processItem");

                                  Map params = workItem.getParameters();

                                  params.remove("Interface");

                                  params.remove("Operation");

                                  params.remove("ParameterType");

                                  params.remove("processItem");

                       

                       

                                  GenericProcess process =(GenericProcess) constructor.newInstance(params);

                                 

                                  Object result = process.execute(processItem);

                                  Map<String, Object> results = new HashMap<String, Object>();

                                  results.put("processItem", result);

                              System.out.println("=================================\n");

                                  manager.completeWorkItem(workItem.getId(), results);

                              } catch (ClassNotFoundException e) {

                                  e.printStackTrace();

                              } catch (InstantiationException e) {

                                  e.printStackTrace();

                              } catch (IllegalAccessException e) {

                                  e.printStackTrace();

                              } catch (NoSuchMethodException e) {

                                  e.printStackTrace();

                              } catch (InvocationTargetException e) {

                                  e.printStackTrace();

                              }

                          }

                       

                      Also, I used the timer event to do the state with <on event="timer>

                       

                      <intermediateCatchEvent id="wait4" name="wait4">

                                  <timerEventDefinition>

                                      <timeDuration>180000</timeDuration>

                                  </timerEventDefinition>

                              </intermediateCatchEvent>

                       

                      But I have 1 issue with that. The timer application does not exist after the time is expired. I think it is still there waiting. (not sure on this)

                       

                      Also, how do I get the activity (node id) in order to cancel the timer?

                      • 9. Re: JBPM5 Implementation
                        Maciej Swiderski Master

                        Donald, great to hear you moving forward that is the most important to stay with a product...

                         

                        Regarding your implementation, I don't think you need to have it so complex. You could use Map directly as parameter map instead of having simple (String) types. So, you will have a method that accepts Map as argument and then you do not need to have a new service task handler. Unless you have another reason to have it.

                         

                        Regarding timers, I am not sure what you mean with:

                         

                        Donald Walters wrote:

                        The timer application does not exist after the time is expired. I think it is still there waiting. (not sure on this)

                         

                        If it is a matter of that process finishes but timer is still active maybe it is because of missing terminateEventDefinition tag within endEvent?!

                         

                         

                             <endEvent id="_5" name="EndProcess" >
                                <terminateEventDefinition/>
                            </endEvent>
                        
                        

                        if not, could you elaborate bit more what is happening?

                         

                        Cheers

                        • 10. Re: JBPM5 Implementation
                          Donald Walters Newbie

                          Hi Maciej,

                           

                          that was my problem. i did not know how to use the Map as an argument declaratively in the service task. An example would be great

                           

                          wrt to the timer. I do have that endEvent but what happens is the following. The event timeout is reach and the subsequent process is executed and the endEvent is reach (I assume) but the program is not exited.

                           

                          If I remove the the timer event then it ends normally.

                          • 11. Re: JBPM5 Implementation
                            Maciej Swiderski Master

                            Donald,

                             

                            please find attached and example that illustrates both map usage and timer. Timer does work properly, there are no hangs what so ever.

                             

                            Maybe you could post your process definition with a test case so I could try to take a look at it too.

                             

                            Cheers

                            • 12. Re: JBPM5 Implementation
                              Ashish T Newbie

                              Hi All,

                               

                              I am also facing the same situation.

                               

                              The sample given by Maciej is prefect and works in the Junit env.

                               

                              But as soon as invoke it from Main it hangs. I am sure that i am missing somthing basic but wasted too much of time.

                               

                              I wiould appriciate responces from community memebers.

                               

                              Regards,

                              Ashish