Pular para o conteúdo principal

A Parser work item handler for jbpm 6

One usual task we do in a process is to have to parse XML/JSON to objects and vice versa. I always look at sample work item handlers from jbpm and I want to create my own work item handlers because it is fun. Today I will quickly show the first public useful work item handler I have created: The parser.

What is and how to use it?


It is a simple parser task that you can use in your BPM Suite/ jbpm 6 process to parse from XML/JSON to some Java object and vice versa. You can, for example, read XML from a file and convert to your model object. It can be used with the REST Task for previous jbpm version, since recently support to transform was added to the REST Task



It accepts the following parameters:


Input: The input data. If you provide a string, the parser will try to parse the string to an object of type Type and format Format (see below), if not, it will try to parse the object to a String of format Format. It is a required parameter;
Format: It is a required parameter that can have the values JSON or XML;
Result: The result is an output parameter that will be a string if you provide an Input object that is not of String type; and an object of type Type if you provide  an Input object of type String.

Providing these parameters correctly is enough to use the parser task. Please bear in mind that it uses JAXB to parse the object, so it must have the @XmlRootElement annotation.

Installation


The steps to install it are similar to the steps we used to install the hello world work item handler. But since we are on BPM Suite 6.1, it will be slight different, see:

* Clone the source code from my github and run mvn clean install to have it in your maven repository (actually in the maven repository used by BPM Suite); Or download the JAR containing this work item handler and upload it as an artifact to your installation;

* Add the GAV information of the WIH(Group: org.jbpm.process.workitem; Artifact ID: parser-task; version: 1.0) as a dependency of your project:




* Now edit the new deployment descriptor to include a declaration of this WIH class. Notice I am sending the Classloader as a parameter. It is needed to load classes defintion to be parsed:




* Finally edit the wid file to include the declaration of the WIH. Now you can open the process and drag it to use in your process.

If you want to see more details about this WIH, please see  the project in github and also the tests for it.

Conclusion


It is easy to extend the jbpm 6 library to include your own custom tasks. The parser task was approved for the Service Repository in BPM Suite! See jbpm github!

Comentários

  1. gran post.
    Where I can download the jar of this work item handler?

    ResponderExcluir
    Respostas
    1. Hello, I just updated the post with a link to the JAR, I added it to github: https://github.com/jesuino/parser-task/tree/master/dist

      It is also part of jbpm service repository now! https://github.com/droolsjbpm/jbpm/commit/37539813c8bea643fd405b83ce2b9757a4499f6d

      Excluir
  2. Great post :) very helpful and made me lots of clarity about workitem handlers.
    One doubt that I have is when we use 'manager.completeWorkItem(workItem.getId(), resultvar);'
    this will return the value of 'resultvar' to 'Results' parameter which we have defined in .wid file

    "results" : [
    "Result" : new ObjectDataType(),
    ],

    Correct me if I am wrong.
    Now I would like to use this value if process, how can I do that?

    ResponderExcluir

Postar um comentário

Postagens mais visitadas deste blog

Dancing lights with Arduino - The idea

I have been having fun with Arduino these days! In this article I am going to show how did I use an electret mic with Arduino to create a Dancing Lights circuit. Dancing Lights   I used to be an eletronician before starting the IT college. I had my own electronics maintenance office to fix television, radios, etc. In my free time I used to create electronic projects to sell and I made a few "reais" selling a version of Dancing lights, but it was too limited: it simply animated lamps using a relay in the output of a 4017 CMOS IC. The circuit was a decimal counter  controlled by a 555. 4017 decimal counter. Source in the image When I met Arduino a few years ago, I was skeptical because I said: I can do this with IC, why should I use a microcontroller. I thought that Arduino was for kids. But now my pride is gone and I am having a lot of fun with Arduino :-) The implementation of Dancing Lights with Arduino uses an electret mic to capture the sound and light leds...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.

Genetic algorithms with Java

One of the most fascinating topics in computer science world is Artificial Intelligence . A subset of Artificial intelligence are the algorithms that were created inspired in the nature. In this group, we have Genetic Algorithms  (GA). Genetic Algorithms  To find out more about this topic I recommend the following MIT lecture and the Nature of Code book and videos created by Daniel Shiffman. Genetic Algorithms using Java After I remembered the basics about it, I wanted to practice, so I tried my own implementation, but I would have to write a lot of code to do what certainly others already did. So I started looking for Genetic Algorithm libraries and found Jenetics , which is a modern library that uses Java 8 concepts and APIs, and there's also JGAP . I decided to use Jenetics because the User Guide was so clear and it has no other dependency, but Java 8. The only thing I missed for Jenetics are more small examples like the ones I will show i...