How do I add and call a custom Java class inside a jBPM Process?

Joel Peltonen

I have a local jBPM 7.33 with a simple process. At one point in the process, I need to generate a PDF file.

I want to do it by creating a very basic Java class that is run in a Task. The class would get variables from the process scope, generate the PDF and save the generated blob (or filesystem path) as a process variable.

How do I add a custom class and then call that class?

Bashir

that's what we call it WorkItemHandler , your java class will be a customized jbpm task

  1. First of all install jbpm in eclipse

  2. Create a jBPM project in eclipse (tick Build the project using Maven)

  3. create a java class that implements WorkItemHandler. it will be in this format.

    package com.example;
    import org.kie.api.runtime.process.WorkItem;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.drools.core.process.instance.WorkItemHandler;
    import org.kie.api.runtime.process.WorkItemManager;
    
    public class WorkItemTest implements WorkItemHandler {
    
        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            workItem.getParameters().toString();
    
            /**Input Variables***/
            String stringVar = (String) workItem.getParameter("stringVar");
    
    
            /***
             * 
             * 
             * YOUR CODE
             * 
             */
    
            String msg = "done";
    
            /**Output Variables in a HashMap***/
            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("Result", msg); //("name of variable", value)
            manager.completeWorkItem(workItem.getId(), resultMap);
        }
    
        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            System.out.println("Aborted ! ");
    
        }
    
    }
    
  4. Build a jar file of this project.

  5. From the workbench, go to Artifact, upload the jar
    click on this icon, then artifacts enter image description here

  6. from the settings of your project, go to dependencies, and add from repository the uploaded artifact enter image description here

  7. from the settings of your project, go to Deployments / Work Item Handler and add a new work Item Handler : type its name and how to instantiate it (new com.example.WorkItemTest()) enter image description here

  8. Finally, go to the Asset "WorkDefinitions" , define your work item (so you can see it in the workflow designer tool) as follow

  [
    "name" : "WorkItemTest",
    "parameters" : [ //inputs
        "stringVar " : new StringDataType(),
    ],
    "results" : [ //outputs
        "Result" : new ObjectDataType(),
    ],
    "displayName" : "WorkItemTest",
    "icon" : "defaultservicenodeicon.png"
  ]
  1. you can now find this task in "service tasks" of your workflow designer tool (refresh before)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I add and call a custom Java class inside a jBPM Process?

From Dev

How do I add a class to a custom namespace?

From Dev

How do I call a graphical class in Java?

From Dev

How do I add a custom Button inside a cell in handsontable?

From Dev

How do I call a java class that opens a CLI with the Process-Builder and reads/writes the Input-/Outputstream of this? Wrapper? Adapter?

From Dev

How do I properly call a method inside a method inside the same class?

From Dev

How do I access an array list inside of a class constructor in java?

From Dev

How do I call a method from a class that was not instantiated in Java?

From Dev

Java - How do i call a class from a different project?

From Dev

How do I call a function written in a kotlin class , in java?

From Dev

How do I call a method from another class in Java?

From Dev

How do I call a method from a class that was not instantiated in Java?

From Dev

How do I call actionPerformed method from another class in java

From Dev

How can I call a function inside a class?

From Dev

How do I turn a C++ class into managed class and call the pure virtual function inside?

From Dev

How do I call a function inside a function

From Dev

How do I implement abstract class inside abstract class in the implementation class in Java?

From Dev

How do I implement abstract class inside abstract class in the implementation class in Java?

From Dev

How do I call a method inside another class from my main?

From Dev

How do I call the selected class or name inside the loop with JavaScript or jQuery?

From Dev

How do I add a notification for process completions

From Dev

ZF2: how do I get ServiceManager instance from inside the custom class

From Dev

How do I call a custom function in a parent class when panResponder starts moving?

From Dev

How do I add a UICollectionView inside a UICollectionViewCell?

From Dev

How do you get data out of JBPM/Drools process instance?

From Dev

How do I include this variable inside this class?

From Dev

How do I conditionally add a class to a block item inside a repeat loop with Chameleon

From Dev

FormPanel class: how do I add a textbox name (not inside it, but at left side) and order the buttons?

From Dev

FormPanel class: how do I add a textbox name (not inside it, but at left side) and order the buttons?

Related Related

  1. 1

    How do I add and call a custom Java class inside a jBPM Process?

  2. 2

    How do I add a class to a custom namespace?

  3. 3

    How do I call a graphical class in Java?

  4. 4

    How do I add a custom Button inside a cell in handsontable?

  5. 5

    How do I call a java class that opens a CLI with the Process-Builder and reads/writes the Input-/Outputstream of this? Wrapper? Adapter?

  6. 6

    How do I properly call a method inside a method inside the same class?

  7. 7

    How do I access an array list inside of a class constructor in java?

  8. 8

    How do I call a method from a class that was not instantiated in Java?

  9. 9

    Java - How do i call a class from a different project?

  10. 10

    How do I call a function written in a kotlin class , in java?

  11. 11

    How do I call a method from another class in Java?

  12. 12

    How do I call a method from a class that was not instantiated in Java?

  13. 13

    How do I call actionPerformed method from another class in java

  14. 14

    How can I call a function inside a class?

  15. 15

    How do I turn a C++ class into managed class and call the pure virtual function inside?

  16. 16

    How do I call a function inside a function

  17. 17

    How do I implement abstract class inside abstract class in the implementation class in Java?

  18. 18

    How do I implement abstract class inside abstract class in the implementation class in Java?

  19. 19

    How do I call a method inside another class from my main?

  20. 20

    How do I call the selected class or name inside the loop with JavaScript or jQuery?

  21. 21

    How do I add a notification for process completions

  22. 22

    ZF2: how do I get ServiceManager instance from inside the custom class

  23. 23

    How do I call a custom function in a parent class when panResponder starts moving?

  24. 24

    How do I add a UICollectionView inside a UICollectionViewCell?

  25. 25

    How do you get data out of JBPM/Drools process instance?

  26. 26

    How do I include this variable inside this class?

  27. 27

    How do I conditionally add a class to a block item inside a repeat loop with Chameleon

  28. 28

    FormPanel class: how do I add a textbox name (not inside it, but at left side) and order the buttons?

  29. 29

    FormPanel class: how do I add a textbox name (not inside it, but at left side) and order the buttons?

HotTag

Archive