Jbpm virtual delivery student lab 1 9

Page 1

JBOSS JBPM DEVELOPMENT

Lab Guide

LabGuide


T

JBoss JBPM For Developers


Table of Contents Lab: 0 Installation and Lab Testing Lab: 1 Starting First Projects. Lab: 2 Working With KIE Workbench. Lab: 3 Handling Data Objects and Process Using KIE. Lab: 4 Using Human Task Using KIE. Lab: 5 Creating Rule using KIE. Lab: 6 Working with jpdl using Eclipse. Lab: 7 Understanding flow and using variable and rules. Lab: 8 Using excel to specify rule and make it part of BPM. Lab: 9 Using persistence in jBPM.

Copyright Xcelframeworks


LAB:0: Installing jbpm

Step: 1 Install Java Step: 2 Download extract apache-ant. Step: 3 Set JAVA_HOME,ANT_HOME and Path Step:4 Download jBPM Go to http://jboss.org/jbpm | Download | Download jBPM 6.2.0.Final | jbpm-6.2.0.Final-installer-full.zip.

Step: 5 Unzip and extract the installer content and you will find an install.html file that contains the helper documentation for installing a demo jBPM runtime with inbuilt projects. Copyright Xcelframeworks


Step:6 Go to the Directory extracted and run ant install.demo

Step: 7 The install command would install the web tooling and the Eclipse tooling, required for modeling and operating jBPM. Step:8 Run the demo ant start.demo

Step: 9 Test Installation since this installation the application server (JBoss) with the web tooling (the Kie workbench and dashboard) deployed in it and the eclipse tooling with all the plugins installed.

Step:10 Access the Kie workbench demo environment by using the URL and log in by using the demo admin user called admin and the password admin at following URL. http://localhost:8080/jbpm-console.

Copyright Xcelframeworks


Enter user name and password and you get the Dashboard Specified Below.

Copyright Xcelframeworks


1 LAB

Lab: 1 Working with First Project

Lab Objective: This Lab helps Participants to create there first project and understand basic steps to create and run simple project. Step: 1 Launch Eclipse already part of your lab Environment.

Step: 2 Create a project by clicking file->new and selecting jbpm project type. 1


Step: 3 Enter Project name as “HelloWorld”.

Step: 4 you get three option of creating project. Select first option. 2


Step: 5 Click next to configure jBPM Runtime ensure you select jBPM6 or above as option.

3


Step: 6 Navigate through directory structure.

4


Step: 7 Select sample.bpmn. Right click and select Open With Bpmn2 Diagram Editor.

Step: 8 once open you will find a process flow with one process Hello preceded by start and closed by terminator. As specified below.

5


Step: 9 Go to properties tab and you will find a java statement in script task. (Don’t change it).

Step: 10 Select Language as java.

6


Step: 11 Save the project and you will find errors in project. In problems view select the error and double click on it to launch Editor.

Step: 12 Specify Package in Package name as of now we will specify com.sample as specified in step 13.

Step: 13 Enter package name and save it. 7


Step: 14 once you save it you will find errors eliminated. (Verify)

8


Step: 15 Create a java class to create a Knowledgebase object and start a session with the process defined.

Step: 16 write the statements as specified in below image.

9


Step: 17 Also see the Test class as specified below.

Step: 18 Run the project by selecting Run As->Java Application

10


Step: 19 verify the output. You will find System.out.println called which was defined in the Hello Process.

11


Lab: 2 Working With KIE Workbench 12


Step: 1 Login to KIE Work Bench using kriv as user and krisv as password to Launch the Workbench as specified below.

13


We have various options that helps us to author deploy and test jbpm Process flows. Have a view on the entire menu Items on the Dashboard specified below.

Step: 2 create an Organization unit. Create a new Repository and assign that repository to the organization unit as specified below in the steps. Go to Administrative perspective and select Manage Org units as specified below. Click on add.

14


Clicking on add provides below dialog .Specify name and Default group Id.

Once Organization unit is created you will find it in the list. Selecting the newly created Unit will show no Associated and Available Repositories.

15


Now move to repository section as specified below and create a new Repository.

Specify a name and select the organization unit you created in previous steps.

16


Once you select the Organization unit you will find Organization unit associated with the repository.

17


Now lets create a business process. Switch to Project Authoring by clicking on authoring->Project Authoring .

Click on Demo and you find your name under search box .Select your Org unit which is Alchemyls as specified below.

18


Select the elements under alchemyls in our case it is alchemyls with empty items.

19


Select New Item and view various artifacts that can be created which include project, Business Process, Data Object and others.

Select New Project and Enter AlchemySample in project Name.

20


Now once again if you go and see the Org Unit and Repository you will find this project added to it as specified in the below Screen.

21


Create a new Business Process. Go to New Item and select Business Process as specified below.

22


In the Wizard Specify name to the Business Process and select the package here we are selecting alchemyls.alchemysample.

Your Dialog must look like below specified completed dialog.

Once you click on ok you will find Process Modeler Launching .Once it is launched click on the arrow specified below to see the Drag Drop toolset loaded with various tools that helps us to create Business Process flow diagram.

23


Click on the arrow specified to view Object Library specified below

Below is the tools made available as a result of clicking on the >> specified above.

24


Select start event and click on click on arrow, which gets highlighted, and double click to get the editor as specified below.

25


Type sample in the editor. Once you see name select the task and tool icon as specified below to get options of various task. Select user Task from the list to make it a User task.

Once Selected you will find a human appearing as specified below. Finally click on the circle to get End Task added.

26


As a result of above actions you will find a process with start,user task and End as specified below.

Save the Model clicking on save on right hand side first button.

Once it is saved click on the right hand side arrow to get the properties pane to edit some baasic properties to start with.

27


Once you get properties under core properties Enter Actors .We will Enter Krisv.

After making changes save them. Click on open Project Editor to Build and deploy Project.

28


Below is the Project editor page that helps you to Build and deploy.

29


Select Build and click on Build and deploy sub Menu to build the project.

To confirm Deployment go Process Management menu and select Process Definitions.You will find your sample process defined.

See the Below Diagram with the process.

30


Click on start under Action option .

Click on submit without adding anything in Form and correlation Key.

31


Once you click on submit you will find certain details check out your instance state is Active.

Go to options and select Process Model as specified Below.

32


Clicking on process model you will find the Process Model

Click Ok. Once Done Select Task from main Menu as specified below.

33


Task details are specified Just visualize the options for now. Click on start as specified below.

Once we start we find release and open options under actions tag. 34


Click on complete

Clicking on complete you will find Tasks empty.

35


Under process management Active Tab you will find nothing. But under completed you will find your task execution is over.

36


Now lets Un deploy the project. Select Deploy and Process Deployments under it.

Click on undeploy .

37


Project Un Deployed. 38


Lab: 3 Handling Data Objects and Process Using KIE.

39


Step: 1 Create a Project with following Business Process. Specify name of Business Process as Loan Approval.

Step 2:For this we need to create Data Object now and associate it with the Business Process. To do that click on below menu Item as specified.

40


Give a name to the Data Object as LoanCustomer as specified below.

Step:3 Add Data items to your Data Object as specified below. Add three items to it which includes name,creditScore and eligible.

41


Continue and add rest by clicking on create and continue as specified below.

After adding all three your data object must look like

Step:4 Save the Data Object Defined and you will find the item added in project Explorer as specified below. 42


Step:5 Next is to associate Data Object with Business Process. To do that click on any portion in Business Process and go to properties. Select variable Definition and add Variable.

43


Post Adding Specify the name and select the Type as show below.

Click Ok and save. Step:6 In this Step we will define Data I/O for our Tasks .Select the Task and click on Data I/O as specified below.

Complete the Data I/O as specified below. 44


Step: 7 Repeat the Process for Other Task don’t forget to save. Finally we have all the Data I/O defined as specified below.

45


After completing all we need to save. Step: 8 Click on the source to see the java pojo generated as specified below.

Task Completed.

46


Lab: 4 Using Human Task Using KIE.

47


Step: 1 In previous Lab we associated and defined Data I/O for our task. Verify all is done.

Step: 2 Specify expression for XOR Gateway as specified below select the connector and go to properties view, select expressions and write the script as specified below.

48


In properties view select variable and definitions and launch editor to write the script.

Save the properties as specified below.

49


Step: 3 Create forms to allow users to enter the data form. Click on the icon specified below and click on Generate all Forms.

Step: 4 Verify all the forms are generated as specified below.

Step: 5 Launch the form editor and edit the forms by editing the forms. Final forms must be similar as specified in below images.

50


51


52


Step: 7 Build and deploy by going to project editor as shown below.

Ensure you get build successful. 53


Step: 8 verify Deployment.

Step: 9 Go to process Definition as specified.

Step: 10 You can see the process in the list along with action .

54


click on start to run the process as a result of which it starts user task.

Click on release and then Claim to claim the task.

Once you click on claimwe get the ialong where you can enter details and click on complete.

55


once you click on complete you will find it moves to ReviewScore claim and complete all the tasks as specified in below depictions.

56


After ReviewScore task is claimed we move to Result .

57


Once all tasks are executed we find task list empty as specified below.

58


Go to Process Instance and check out completed tab you will find the below entry.

Task Completed. 59


Lab: 5 Creating Rule using KIE . 60


In this Lab we would see how to define a guided Rule using KIE. Create a guided rule using New Item->Guided Rule.

After specifying name click on ok. 61


You will find below dialog to help you in creating a Rule.

Click on plus beside when and you get below dialog.

62


Select LoanCustomer and click on ok.

Once you click you get below added to when 63


Click on There is a loanCustomer and you get below Dialog to specify constraint. Select Add a restriction and select loanCustomer.

Click on loanCustomer below and modify the constraint.

64


Select creditScore from the dropdown.

65


Select greater than and click on pencil beside it.

Click on literal Value.

66


Enter 50.0 in the textfield .

67


click on plus sign beside THEN

Select Modify loanCustomer. 68


Click on pencil below

Select add Field and select eligible from Dropdown.

69


Set eligible value to true.And click on show options….

70


Select java as dialect.

Add following options to your rule.

71


Ensure no-loop and lock-on-active are selected and ruleflow-group is named as loanApproval.

72


Have look at source

Save the rule

73


Task Completed In next lab we would see how to use business rule in Business Process. 74


Lab: 6 Working with jpdl using Eclipse. 75


Step: 1 Confirm Installation by following steps as specified below. Click File Menu->New->Other .

Step:2 Creating a new Project Select Process Project. Click Next

76


Specify a project name and click Next.

Select jbpm runtime and click next to complete configuration of project.

77


Have a look over project structure generate.

Open it in navigator and see the folder structure.you will find a jpdl folder .

78


Select jpdl and create a new process.

Once done you will find some files generated we will see that in other following sections.

79


Click finish. Step: 3 Creating a swimlane and assigning actor to it. Step: 3.1 to process-project name/ (src/main/jpdl)/process name in the project explorer window pane and double click to open it in the editor.

80


2. Click Properties tab.

3. Click on the tab Swimlanes.

4. Right Click on the vertical white space area.

81


5. Choose New Swimlane.

6.Give a suitable name to the Swimlane.

7. Click on the Assignment tab.

82


8. Choose an Assignment type as “Actor� from the drop down.

9.Give a valid/existing actor or user name in Actor textbox. Here we give it as manger.

You have created a swimlane and assigned an actor (Manager). 83


Step:4 Creating a Swimlane using pooled actor Pooled actor stands for a group of users. When a swimlane is assigned to a group of users - each user belonging to that group will be a part of the same swimlane. 1.Create a new Swimlane. Click on the Assignment tab.

2. Choose an Assignment type as “Pooled Actors” from the drop down.

3.Give a valid/existing actor or user name in Pooled Actors textbox. Here we give it as manager. Optionally the actor name can be given as shipper,user and admin. jBPM by default offers 4 users ‘manager’,’admin’, ’shipper’,’user’ with the role ‘manager/admin/u ser’, ‘admin/user’,’user’ ,’user’ accordingly. 84


Step: 5 Swimlane using expression. It is an assignment expression for the jBPM identity component. Management of users, groups and permissions is commonly known as identity management. The actors will be resolved from the expression. The following depicts that how a swimlane can be associated with a user using expression. 1. Create a new Swimlane. (follow previous step) 2. Click on the Assignment tab.

3. Choose an Assignment type as “Expression� from the drop down.

85


4. Give a valid/existing actor or user name in the textbox using expression. Here we give it as Manager. Optionally the actor name can be given as Shipper, User and Admin (which is default user provided).

Step: 5 Swimlane using Handler. jBPM provides org.jBPM.taskmgmt.def.AssignmentHandler interface using which an user can be assigned to a Swimlane. The mentioned interface consists of a method with the following signature that is responsible to assign a user to a swimlane. This approach is more relevant when an user is to associated with a Swimlane at runtime. 1. Create a new Swimlane.

2. Create a class named AssignUser

86


2. Click on the Assignment tab.

3. Choose an Assignment type as “Handler� from the drop down.

87


4. Click on the search button to find the designated class.

5. Type the few letters of the designated class in the textbox. This will show the all possible class that one can associate with the swimlane.

6. Click OK to finish.

88


Working with process Definition Entities These entities define a manual or automated task that corresponds to a step within a process design. Adding a new entity allows one to create a new step and assign it to a Swimlane (optionally) within a process.

Step: 1 Creating a start node. A start node is used to start a process. Without using a start node subsequent activities inside a process can’t be performed. It is the entry point to a jBPM process. 1. Click on the Start node from the left window toolbar pane of the editor.

2. Drop it on the design editor.

89


3.Click on the properties tab below the design editor.

4.Click on the task tab.

5. Check the Configure Task checkbox.

90


Enter the name of the task that will be associated with the Start-Node. Here it is given as StartTask as shown below.

7. Click on the Details tab. And Click on the Generate Form button.

This wizard is responsible to create a task variable in the ContextInstance of the Process.

.

91


8.Click on the add button to add a variable to the left.

Give the name of the variable. Here it is ‘name’. Press Enter. Enter the label. By default access permission of each variable entered in the entry is Read and Write. Additionally if ‘Required’ checkbox is selected then this variable becomes mandatory with the related task. 9. Click on Add in Define the form buttons section. Enter the name of the transition on which the execution flow will take place. Enter the label of the button.

92


10. Click on the Assignment tab.

93


11. If runtime assignment is required as a business need then use ‘Assignment Handler’ option with the task created in previous steps.

12. Create a java class AssignUser.

94


13. Click on the Search button to find the assignment handler class.

14. Choose the assignment handler class from the wizard. Click OK when done.

95


15. If at design time the user is to be associated with the task choose ‘Actor’ from the dropdown.

16 Enter the name of the Actor (user).

96


17. If a set of actors is to work upon the task then choose ‘Pooled Actors’ from the dropdown under assignment tab.

18. Give a set of valid user name in a comma-separated expression in Pooled Actors textbox.

97


19.Alternatively one can also use choose ‘Expression’ to associate a single user(actor) from the dropdown.

98


21. If a Swimlane is previously configured then one can choose ‘Swimlane’ from the dropdown and allocate the task under this Swimlane.

22. Enter the name of the swimlane into the textbox. Name is case-sensitive.

23.To attach some exception handling policy click on the ‘Exceptions’ tab under properties 99


tab.

24. Right Click on the blank vertical box. Click new Exception Handler.

25. Give the name of an exception class. Here it is java.lang.Exception class. The exception handler name is populated with the exception class name specified in the text box.

100


26. Under the newly created exception handler right click on it and click on New Action.

27. On creating a new action a separate wizard will open which will ask for a name of the action.

101


28. Go to details tab to associate a class with this action. Separately an expression also can be attached with this action.

29. Choose the appropriate action details. Either a handler or an expression. A handler is nothing but an action class. Here we associate using an action class.

30. Create a Java class ExceptionAction

102


31. Click on the search button to get the action handler class.

32. Choose the action handler class from the wizard. Click OK when done.

103


33. If the task is to be based on certain event occurrences then click on the Events tab.

34. Right Click on the right blank area and click New Event.

104


35.Choose appropriate Event Type from the dropdown that might occur during the execution of a start node. Here task-create event type has been chosen.

36. An event with name of an event-type will be generated.

105


37. Right click on the generated event. Select New Action.

38. An action will be generated in the right pane as the figure shows.

39.Configure the action.

106


Step: 2 Creating a End Node and transition. 1. Click on the End node from the left window toolbar pane of the editor.

2.Drop it on the design editor.

3. Click on the properties tab below the design editor.

107


4.Rename your end node if required.

5.The Changes will be reflected in the design editor.

108


1. Click on the transition from the left window toolbar pane of the editor.

109


Select the source node. Drag up to the destination node.

3. Click on the properties tab below the design editor.

4. Default transition doesn’t have any name. A name can be provided in the General tab under ‘Name’ textbox section.

110


5. The Changes will be reflected in the design editor.

111


7. Select the transition from the Process Design Area.

8.Select the property tab below the Process design editor.

9. Select the Actions tab to add action

112


10. Right click on the right blank area and click on New Action.

Give the name of the action as follows.

113


Click on details tab as depicted.

Choose the appropriate Action either as handler or Expression. Here the chosen one is a Handler.

Choose the appropriate action handler class that one has to create before this step. To choose the handler (Java class) click on the Search button.

Choose the appropriate action handler class from the matching items. Click OK when finished.

114


16. Click on the advanced tab.

The wizard is responsible for event propagation and asynchronous behavior. Default is true|yes.

115


Step: 3 Creating a Task Node: A task node represents one or more tasks that are to be performed by human. So when execution arrives in a task node, task instances will be created in the task lists of the workflow participants. After that, the node will go to a wait state meaning that some manual work is required for completion of the task. So when the users perform their task, the task completion will trigger the resuming of the execution.

2. Drop it on the process design Editor. Workflow after creating a task node.

116


3. Click on the properties tab.

4. Enter the name of the task in the ‘Name’ textbox.

117


5. Changes will be reflected in the process design editor as follows.

There are two ways to specify the decision criteria in a jbpm process. One is by adding condition elements on the transitions. Conditions are script expressions that returns a ‘Boolean’. At runtime the decision node will loop over its leaving transitions and evaluate each condition. The first transition for which the conditions resolve to 'true' will be taken. Alternatively, an implementation of the DecisionHandler can be specified. Then the decision is generated by a Java class and the selected leaving transition is returned by the decide-method of the DecisionHandler implementation.

118


Drop on the process design editor. Design your process in the process design editor.

119


Click on the properties tab below.

4. Change the name to ‘Approve/Disapprove’

120


changes will be reflected in the process design editor.

5. Click on the Handler tab.

Select choose type Delegation from the dropdown.

121


Select choose type Delegation from the dropdown.

Create a custom Decision Handling class for the decision handler.

122


Choose your newly created class to set the delegation. Click the search button and set the decision handler class.

OK to finish.

123


Lab: 7 Understanding flow and using variable

124


Create a Project as done in previous cases and build a simple Hello Script task(ensure kmodule.xml).

125


Write a class to be used in further case.

Specify following code to test the basic Hello flow . 126


Create a rule file using

Create below rules as specified in the file

127


128


In the script section write code to get variable created using ksession(while invoking the test).

129


130


131


Select Script task and enter below written script in the section.

132


133


Select the gateway and specify following use pencil to add/edit entries.

Select loopback flow and specify below name.

134


Select loopback flow and specify below script.

Select otherwise flow and specify below properties in sequence.

135


Select otherwise flow and specify name.

Select Hello Post node and specify this in Script (java). 136


Select End (terminate node and specify the properties)

Configure kmodule.xml with following entries:

137


Write code to invoke session with rules in process as specified below.

Execute the file ProcessRuleTest and confirm the output. 138


139


Lab: 8 Using excel to specify rule and make it part of BPM.

140


141


This is extension of Lab:07 but we would create this as a maven project to explore dependencies. Step:01 In the previous project open pom.xml and add following

Step:02 once build you will find following jar file added to the project.

Step:03 Create an excel and add it to your project instead of .drl file.

Step:04 See the below excel.

142


You can also import it from google drive. Rest everything will be common. Step:05 Run the file named ProcessRuleTest.java and see the output.

143


144


Lab: 9 Using persistence in jBPM.

145


Step:01 create a flow as specified below.

It should be place in following directory structure.

Create a usergroup.properties file and make following entries.

146


Configure logging in logging-test.xml and specify below content to it.

Create jndi.properties file and enter below entries.

Configure persistence.xml file with following entries.

147


148


You can download it from google drive (solutions). Under the following directory create java files .

Configure runtime as specified in below java file.

149


Write the test file with main as specified below.

150


151


Run the program and verify the output.

152


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.