Search code examples
javajbossjbpmbusiness-process-managementdrools-guvnor

JBPM Service Task assignments input from config


I have JBPM process where I have add Service Task Rest. In the assignments inputs I want to set url through config file and not directly in the source field.

enter image description here

I am researching 3 days but still I cant find it.

Is there any option to set the url value like this:

http://{ip-address}/{port}/update

As you can see in the example above ip-address and port should be read from a config or property file.

The next part is just to check is everything okay.

Can I achieve the result like this:

    Config config = new Config();
    

    /** Output Variables in a HashMap ***/
    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("Result", msg); // ("name of variable", value)
    resultMap.put("url", "http://" + config.getProperty("ip") + config.getProperty("port") + "/update");
    manager.completeWorkItem(workItem.getId(), resultMap);

NEW EDIT

Maybe I wrote it a little bit confusing but like this the whole url need to be in the config and what I want is only ip and port to be read from config and to to write in the source like this manually: http:// (wrote by me manually) + ip : port (read from config) / update (wrote by me manually). So as I wrote above, I want only ip and port values from config. That is why I wrote them as {ipVar}:{portVar} above.

New edit: Thank you for the detailed answers. Maybe I am writing it confusing so I will explain this picture: enter image description here

you see my point was to only get ip and port from config and anything else what user want to write because there can be another endpoints...

for example: http://{ip}:{port}/create/user/bashir or https://{ip}:8080/asd/update

I want to get ip and port as variables from config and to use it if I need in some assignment, for this case URL.


Solution

  • You have two solutions:

    • First one: To create your own Rest Task, it is what we call WorkItem which consist of developing your own task in which you consume your REST API the way you want. take a look here to have an idea on how do we create WorkItem.
    • Second one: You need to create a WorkItem (a custom task) that you call it just before the Service Task Rest which will only import your data from a config file and assign the imported values into global variables. And then, in the Service Task Rest, you have to put in the Source field the name of variable for each input

    I hope my answer was clear and helpful. This is how I always do.

    Edit: you have to change your code as follow

    Config config = new Config();
    
    
    /** Output Variables in a HashMap ***/
    Map<String, Object> resultMap = new HashMap<String, Object>();
    resultMap.put("Result", msg); // ("name of variable", value)
    resultMap.put("url", "http://" + config.getProperty("ip") +":"+ config.getProperty("port"));
    manager.completeWorkItem(workItem.getId(), resultMap);
    

    in WorkDefinitions:

    [
        "name" : "WorkItemTest",
        "parameters" : [ //inputs
            "stringVar " : new StringDataType(),
        ],
        "results" : [ //outputs
            "url" : new ObjectDataType(),
        ],
        "displayName" : "WorkItemTest",
        "icon" : "defaultservicenodeicon.png"
    ]
    

    then, you go to variable definition and define a variable called url and finalURL of type String as follow (it's in french language)

    enter image description here

    Later, you draw your task and put output as follow:

    enter image description here

    now your url from config file is assigned to a the variable url, now you need to concatenate the url with the endpoint (ip:port/update). To so you need to add a script task in which you will add this line of code:

    kcontext.setVariable("finalURL",url+"/update"); //this will assign the url + "/update" to the variable finalURL
    

    So last step now, in the screenshot that you shared, for the url, you choose from the combobox the variable named finalURL, as follow

    enter image description here