jBPM Work Items and Timers Mgr. Marián Macik, Senior Quality Engineer April 2021 ❏ Work Item Handlers ❏ What is a Work Item (WI)? ❏ Work Item Handler (WIH) installation ❏ Example #1 - Email WIH configuration ❏ Example #2 - REST WIH configuration ❏ Timer nodes ❏ Start, Catch intermediate ❏ Boundary intermediate ❏ Example #3 - Timer nodes TOPICS COVERED ❏ Work Item is an implementation of a domain-specific service (REST call to an external service, email, integration with Google, Dropbox…). ❏ In other words it is “a piece of work that needs to be done” as a part of a business process. ❏ Work Items are executed using Work Item Handlers which are pluggable into the jBPM (Java classes implementing a Work Item Handler interface). ❏ Anybody can implement its own WIH in case it doesn’t yet exist. ❏ WIH “tells” the jBPM engine how to handle the process node with a particular work item, i.e. how to send an email, call a REST service, upload a file to Dropbox… ❏ Plenty of Work Items available in jBPM Work Items repository (already preinstalled in jBPM). WORK ITEM ❏ First, you have to enable work item for whole Business Central. ❏ Click on the wheel in the upper right corner. ❏ Select Service Tasks Administration. ❏ Enable the service task you want. ❏ Some work items are enabled and available by default: ❏ BusinessRuleTask ❏ DecisionTask ❏ Email ❏ JMSSendTask ❏ Rest ❏ ServiceTask ❏ WebService WORK ITEMS INSTALLATION ❏ Now you can install it to your project. ❏ In project Settings/Service Tasks, click on Install button. ❏ Fill in needed parameters, they vary with each work item. WORK ITEMS INSTALLATION ❏ You should see your work item handler declared in Settings/Deployments/Work Item Handlers. ❏ If it is not there, press the Reset button to refresh the user interface ❏ Don’t press the Save button before you can see Work Item Handler as on the picture WORK ITEMS INSTALLATION Example #1: EMAIL WORK ITEM CONFIGURATION ❏ Configuration for GMail: ❏ new org.jbpm.process.workitem.email.EmailWorkItemHandler("smtp.gmail.com", "587", "testMail@gmail.com", "testPassword", "true") ❏ Don’t forget the last parameter “true”. This will instruct Business Central to use secure TLS connection, which is needed for GMail. ❏ In GMail account, don’t forget to enable access for less secure apps. ❏ Configuration for MailSlurper: ❏ Change wwwPort to 8180 in config.json (or any other available port on your system) so it doesn’t clash with Business Central 8080 port ❏ Create credentials ❏ new org.jbpm.process.workitem.email.EmailWorkItemHandler("localhost", "2500", "user", "password") Example #2: REST WORK ITEM CONFIGURATION ❏ Configuration: ❏ new org.jbpm.process.workitem.rest.RESTWorkItemHandler("user", "password", classLoader) ❏ User and password can be empty, i.e. “”, if no authentication is needed ❏ classLoader is a special variable needed for jBPM to see our domain object, i.e. Person ❏ If you need other options, please have a look at the source code and choose the appropriate constructor for your needs Example #2: REST WORK ITEM CONFIGURATION ❏ You need your domain object, i.e. Person, to be remotable - able to be marshalled/unmarshalled to/from JSON/XML TIMERS ❏ Timer nodes are useful for situations when our domain relies on specific time events, durations or deadlines ❏ We need to create a new process instance on a specific date or in specific intervals (Start) ❏ A product is painted and paint needs to dry before moving onto another stage in a factory (Catch intermediate) ❏ A task has to be completed in 24 hours, otherwise we need to escalate to a manager (Boundary intermediate) ❏ ISO8601 format for specifying time events Start Catch intermediate Boundary intermediate linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat THANK YOU