[jboss-user] [jBPM] - Running a script task and then a rule in a process

Ramesh Verala do-not-reply at jboss.com
Thu Sep 20 15:07:50 EDT 2012


Ramesh Verala [https://community.jboss.org/people/veerala_in] created the discussion

"Running a script task and then a rule in a process"

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

--------------------------------------------------------------
Hi
Newbie to BPM/BRMS. I am trying to run a rule after a script task in jBPM 5.3. I am trying to do everything through the jbpm web console, except for the flow group designing, since there is no provision, to my knowledge to design the  rule flow in jBPM console. I tried calling fireAllRules() through ksession in the script. I also tried to call fireAllRules() through listener as suggested in another thread here. Never the less I am unable to do it. I must be doing some fundamental mistake here, can anyone suggest me.
Here are the sources:

*Model and Rule:*
--------------------------------
| 1. | | | package salesOrder |
| 2. | | | declare Employee |
| 3. | | |     name: String |
| 4. | | |     id: Integer |
| 5. | | |     email: String |
| 6. | | |     mobile: Integer |
| 7. | | | end |
| 8. | | | 
 |
| 9. | | | declare Customer |
| 10. | | |     name: String |
| 11. | | |     email: String |
| 12. | | |     mobile: Integer |
| 13. | | |     isRegistered: Boolean |
| 14. | | |     address: String |
| 15. | | | end |
| 16. | | | 
 |
| 17. | | | declare Product |
| 18. | | |     name: String |
| 19. | | |     price: Integer |
| 20. | | | end |
| 21. | | | 
 |
| 22. | | | declare Company |
| 23. | | |     name: String |
| 24. | | |     products: Product |
| 25. | | |     warehouse: String |
| 26. | | | end |
| 27. | | | 
 |
| 28. | | | declare Order |
| 29. | | |     customer: Customer |
| 30. | | |     product: Product |
| 31. | | |     totalPrice: Integer |
| 32. | | |     isDiscountAllowed: Boolean |
| 33. | | |     discountPercent: Integer |
| 34. | | |     discountAmount: Integer |
| 35. | | |     invoicePrice: Integer |
| 36. | | |     isMoneyPaid: Boolean |
| 37. | | | end |
| 38. | | | 
 |
| 39. | | | declare Shipment |
| 40. | | |     Order: Order |
| 41. | | |     dateShipped: java.util.Date |
| 42. | | |     toBeShipped: Boolean |
| 43. | | |     shipped: Boolean |
| 44. | | | end |
| 45. | | | 
 |
| 46. | | | declare CustomerServiceRep extends Employee |
| 47. | | |     order: Order |
| 48. | | | end |
| 49. | | | 
 |
| 50. | | | declare Accountant extends Employee |
| 51. | | |     order: Order |
| 52. | | | end |
| 53. | | | 
 |
| 54. | | | declare WareHouseRep extends Employee |
| 55. | | |     shipment: Shipment |
| 56. | | | end |
| 57. | | | 
 |
| 58. | | | 
 |
| 59. | | | 
 |
| 60. | | | rule "CreditApproved" |
| 61. | | |     dialect "java" |
| 62. | | |     ruleflow-group "SalesOrderRuleFlowId" |
| 63. | | |     when |
| 64. | | |         Customer( isRegistered == true ) |
| 65. | | |     then |
| 66. | | |         System.out.print("Credit Approved Rule Applied"); |
| 67. | | | end |

*Rules Flow Source:*
---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?> 
<process xmlns=" http://drools.org/drools-5.0/process http://drools.org/drools-5.0/process"
         xmlns:xs=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
         xs:schemaLocation=" http://drools.org/drools-5.0/process http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
         type="RuleFlow" name="SalesOrderRuleFlowName" id="SalesOrderRuleFlowId" package-name="salesOrder" >

  <header>
  </header>

  <nodes>
    <start id="1" name="Start" x="16" y="26" width="48" height="48" />
    <ruleSet id="3" name="CreditApproved" x="96" y="17" width="116" height="67" ruleFlowGroup="SalesOrderRuleFlowId" />
    <end id="6" name="End" x="392" y="26" width="48" height="48" />
  </nodes>

  <connections>
    <connection from="1" to="3" />
    <connection from="3" to="6" />
  </connections>

</process>

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

*Process Source:*

| 1. | | | <?xml version="1.0" encoding="UTF-8"?>  |
| 2. | | | <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/bpmn20" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" 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:drools="http://www.jboss.org/drools" id="_ptfzEANVEeK2lJvWBPLVRg" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" targetNamespace="http://www.omg.org/bpmn20">  |
| 3. | | |   <bpmn2:process id="salesOrder.SalesOrderProcess" drools:packageName="salesOrder" name="SalesOrderProcess" isExecutable="true">  |
| 4. | | |     <bpmn2:startEvent id="_104129D7-29A0-49E8-A790-226F714A41CD" drools:bgcolor="#9acd32" name="">  |
| 5. | | |       <bpmn2:outgoing>_824C0C53-4A42-4D52-9114-B033A8CAFC81</bpmn2:outgoing>  |
| 6. | | |     </bpmn2:startEvent>  |
| 7. | | |  <bpmn2:scriptTask id="_60A5093D-5DE3-4077-8F5F-AF569A60B626" drools:bgcolor="#fafad2" drools:taskName="PlaceOrder" name="PlaceOrder" scriptFormat="http://www.java.com/java">  |
| 8. | | |       <bpmn2:incoming>_824C0C53-4A42-4D52-9114-B033A8CAFC81</bpmn2:incoming>  |
| 9. | | |       <bpmn2:outgoing>_8A2D3B8A-B1F9-4993-B112-84458270EFAF</bpmn2:outgoing>  |
| 10. | | |       <bpmn2:ioSpecification id="_ptfzEQNVEeK2lJvWBPLVRg">  |
| 11. | | |         <bpmn2:dataInput id="_60A5093D-5DE3-4077-8F5F-AF569A60B626_TaskNameInput" name="TaskName"/>  |
| 12. | | |         <bpmn2:inputSet id="_ptgaIANVEeK2lJvWBPLVRg"/>  |
| 13. | | |         <bpmn2:outputSet id="_ptgaIQNVEeK2lJvWBPLVRg"/>  |
| 14. | | |       </bpmn2:ioSpecification>  |
| 15. | | |       <bpmn2:dataInputAssociation id="_ptgaIgNVEeK2lJvWBPLVRg">  |
| 16. | | |         <bpmn2:targetRef>_60A5093D-5DE3-4077-8F5F-AF569A60B626_TaskNameInput</bpmn2:targetRef>  |
| 17. | | |         <bpmn2:assignment id="_ptgaIwNVEeK2lJvWBPLVRg">  |
| 18. | | |           <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="_ptgaJANVEeK2lJvWBPLVRg">PlaceOrder</bpmn2:from>  |
| 19. | | |  <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="_ptgaJQNVEeK2lJvWBPLVRg">_60A5093D-5DE3-4077-8F5F-AF569A60B626_TaskNameInput</bpmn2:to>  |
| 20. | | |         </bpmn2:assignment>  |
| 21. | | |       </bpmn2:dataInputAssociation>  |
| 22. | | |  <bpmn2:script><![CDATA[System.out.println("Hello Ramesh"); 
Customer c = new Customer(); 
c.setName("Ramesh Verala"); c.setIsRegistered(true); 
Product p = new Product();p.setName("apparel");
Order o = new Order();
o.setProduct(p);
o.setCustomer(c);
o.setIsMoneyPaid(false);
org.drools.event.AgendaEventListener lis = new org.drools.event.AgendaEventListener(){ 
public void activationCancelled(org.drools.event.ActivationCancelledEvent arg0, org.drools.WorkingMemory arg1) { } 
 public void activationCreated(org.drools.event.ActivationCreatedEvent arg0, org.drools.WorkingMemory arg1) { }
 public void afterActivationFired( org.drools.event.AfterActivationFiredEvent arg0, org.drools.WorkingMemory arg1) { } 
public void afterRuleFlowGroupActivated( org.drools.event.RuleFlowGroupActivatedEvent arg0, org.drools.WorkingMemory arg1) 
 { System.out.println("firing all rules"); arg1.fireAllRules(); }
 public void afterRuleFlowGroupDeactivated( org.drools.event.RuleFlowGroupDeactivatedEvent arg0, org.drools.WorkingMemory arg1) { } 
public void agendaGroupPopped(org.drools.event.AgendaGroupPoppedEvent arg0, org.drools.WorkingMemory arg1) { }
 public void agendaGroupPushed(org.drools.event.AgendaGroupPushedEvent arg0, org.drools.WorkingMemory arg1) { } 
public void beforeActivationFired( org.drools.event.BeforeActivationFiredEvent arg0, org.drools.WorkingMemory arg1) { } 
public void beforeRuleFlowGroupActivated( org.drools.event.RuleFlowGroupActivatedEvent arg0, org.drools.WorkingMemory arg1) { } 
 public void beforeRuleFlowGroupDeactivated( org.drools.event.RuleFlowGroupDeactivatedEvent arg0, org.drools.WorkingMemory arg1) { }  }; 
 System.out.println("casting.."); 
org.drools.runtime.StatefulKnowledgeSession ksession = (org.drools.runtime.StatefulKnowledgeSession) kcontext.getKnowledgeRuntime(); 
try{ 
org.drools.impl.StatefulKnowledgeSessionImpl s = (org.drools.impl.StatefulKnowledgeSessionImpl)ksession; s.session.addEventListener(lis)  ; 
System.out.println("listener is added"); } catch(Exception ex) { System.out.println("================================================================================================================"); 
System.out.println(ex.getMessage()); }
ksession.insert(c);ksession.insert(o);]]></bpmn2:script>  |
| 23. | | |     </bpmn2:scriptTask>  |
| 24. | | |  <bpmn2:businessRuleTask id="_0172EE3A-F4D5-4FBE-B796-F703A4877671" drools:bgcolor="#fafad2" drools:taskName="CreditApproved" drools:ruleFlowGroup="salesOrder.SalesOrderRuleFlowId" name="CreditApproved">  |
| 25. | | |       <bpmn2:incoming>_8A2D3B8A-B1F9-4993-B112-84458270EFAF</bpmn2:incoming>  |
| 26. | | |       <bpmn2:outgoing>_70594D97-F29D-4D84-B0DC-86312DFCB533</bpmn2:outgoing>  |
| 27. | | |       <bpmn2:ioSpecification id="_ptgaJgNVEeK2lJvWBPLVRg">  |
| 28. | | |         <bpmn2:dataInput id="_0172EE3A-F4D5-4FBE-B796-F703A4877671_TaskNameInput" name="TaskName"/>  |
| 29. | | |         <bpmn2:inputSet id="_ptgaJwNVEeK2lJvWBPLVRg"/>  |
| 30. | | |         <bpmn2:outputSet id="_ptgaKANVEeK2lJvWBPLVRg"/>  |
| 31. | | |       </bpmn2:ioSpecification>  |
| 32. | | |       <bpmn2:dataInputAssociation id="_ptgaKQNVEeK2lJvWBPLVRg">  |
| 33. | | |         <bpmn2:targetRef>_0172EE3A-F4D5-4FBE-B796-F703A4877671_TaskNameInput</bpmn2:targetRef>  |
| 34. | | |         <bpmn2:assignment id="_ptgaKgNVEeK2lJvWBPLVRg">  |
| 35. | | |           <bpmn2:from xsi:type="bpmn2:tFormalExpression" id="_ptgaKwNVEeK2lJvWBPLVRg">CreditApproved</bpmn2:from>  |
| 36. | | |  <bpmn2:to xsi:type="bpmn2:tFormalExpression" id="_ptgaLANVEeK2lJvWBPLVRg">_0172EE3A-F4D5-4FBE-B796-F703A4877671_TaskNameInput</bpmn2:to>  |
| 37. | | |         </bpmn2:assignment>  |
| 38. | | |       </bpmn2:dataInputAssociation>  |
| 39. | | |     </bpmn2:businessRuleTask>  |
| 40. | | |     <bpmn2:endEvent id="_AD849530-E5B2-4953-AA9B-2B5F7FB8C3D6" drools:bgcolor="#ff6347" name="">  |
| 41. | | |       <bpmn2:incoming>_70594D97-F29D-4D84-B0DC-86312DFCB533</bpmn2:incoming>  |
| 42. | | |     </bpmn2:endEvent>  |
| 43. | | |  <bpmn2:sequenceFlow id="_824C0C53-4A42-4D52-9114-B033A8CAFC81" sourceRef="_104129D7-29A0-49E8-A790-226F714A41CD" targetRef="_60A5093D-5DE3-4077-8F5F-AF569A60B626"/>  |
| 44. | | |  <bpmn2:sequenceFlow id="_8A2D3B8A-B1F9-4993-B112-84458270EFAF" sourceRef="_60A5093D-5DE3-4077-8F5F-AF569A60B626" targetRef="_0172EE3A-F4D5-4FBE-B796-F703A4877671"/>  |
| 45. | | |  <bpmn2:sequenceFlow id="_70594D97-F29D-4D84-B0DC-86312DFCB533" sourceRef="_0172EE3A-F4D5-4FBE-B796-F703A4877671" targetRef="_AD849530-E5B2-4953-AA9B-2B5F7FB8C3D6"/>  |
| 46. | | |   </bpmn2:process>  |
| 47. | | |   <bpmndi:BPMNDiagram id="_ptgaLQNVEeK2lJvWBPLVRg">  |
| 48. | | |     <bpmndi:BPMNPlane id="_ptgaLgNVEeK2lJvWBPLVRg" bpmnElement="salesOrder.SalesOrderProcess">  |
| 49. | | |       <bpmndi:BPMNShape id="_ptgaLwNVEeK2lJvWBPLVRg" bpmnElement="_104129D7-29A0-49E8-A790-226F714A41CD">  |
| 50. | | |         <dc:Bounds height="30.0" width="30.0" x="75.0" y="115.0"/>  |
| 51. | | |       </bpmndi:BPMNShape>  |
| 52. | | |       <bpmndi:BPMNShape id="_ptgaMANVEeK2lJvWBPLVRg" bpmnElement="_60A5093D-5DE3-4077-8F5F-AF569A60B626">  |
| 53. | | |         <dc:Bounds height="80.0" width="100.0" x="165.0" y="75.0"/>  |
| 54. | | |       </bpmndi:BPMNShape>  |
| 55. | | |       <bpmndi:BPMNShape id="_ptgaMQNVEeK2lJvWBPLVRg" bpmnElement="_0172EE3A-F4D5-4FBE-B796-F703A4877671">  |
| 56. | | |         <dc:Bounds height="80.0" width="100.0" x="345.0" y="90.0"/>  |
| 57. | | |       </bpmndi:BPMNShape>  |
| 58. | | |       <bpmndi:BPMNShape id="_ptgaMgNVEeK2lJvWBPLVRg" bpmnElement="_AD849530-E5B2-4953-AA9B-2B5F7FB8C3D6">  |
| 59. | | |         <dc:Bounds height="28.0" width="28.0" x="789.0" y="95.0"/>  |
| 60. | | |       </bpmndi:BPMNShape>  |
| 61. | | |       <bpmndi:BPMNEdge id="_ptgaMwNVEeK2lJvWBPLVRg" bpmnElement="_824C0C53-4A42-4D52-9114-B033A8CAFC81">  |
| 62. | | |         <di:waypoint xsi:type="dc:Point" x="90.0" y="130.0"/>  |
| 63. | | |         <di:waypoint xsi:type="dc:Point" x="135.0" y="130.0"/>  |
| 64. | | |         <di:waypoint xsi:type="dc:Point" x="135.0" y="115.0"/>  |
| 65. | | |         <di:waypoint xsi:type="dc:Point" x="215.0" y="115.0"/>  |
| 66. | | |       </bpmndi:BPMNEdge>  |
| 67. | | |       <bpmndi:BPMNEdge id="_ptgaNANVEeK2lJvWBPLVRg" bpmnElement="_8A2D3B8A-B1F9-4993-B112-84458270EFAF">  |
| 68. | | |         <di:waypoint xsi:type="dc:Point" x="215.0" y="115.0"/>  |
| 69. | | |         <di:waypoint xsi:type="dc:Point" x="305.0" y="115.0"/>  |
| 70. | | |         <di:waypoint xsi:type="dc:Point" x="305.0" y="130.0"/>  |
| 71. | | |         <di:waypoint xsi:type="dc:Point" x="395.0" y="130.0"/>  |
| 72. | | |       </bpmndi:BPMNEdge>  |
| 73. | | |       <bpmndi:BPMNEdge id="_ptgaNQNVEeK2lJvWBPLVRg" bpmnElement="_70594D97-F29D-4D84-B0DC-86312DFCB533">  |
| 74. | | |         <di:waypoint xsi:type="dc:Point" x="395.0" y="130.0"/>  |
| 75. | | |         <di:waypoint xsi:type="dc:Point" x="618.0" y="130.0"/>  |
| 76. | | |         <di:waypoint xsi:type="dc:Point" x="618.0" y="111.0"/>  |
| 77. | | |         <di:waypoint xsi:type="dc:Point" x="803.0" y="109.0"/>  |
| 78. | | |       </bpmndi:BPMNEdge>  |
| 79. | | |     </bpmndi:BPMNPlane>  |
| 80. | | |   </bpmndi:BPMNDiagram>  |
| 81. | | | </bpmn2:definitions>  |


Thanks
--------------------------------------------------------------

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120920/9cc58f59/attachment-0001.html 


More information about the jboss-user mailing list