Java Service Task in Designer / Modeler

#1

I would like to create a Service Task which is implemented in Java. This service task should then be available in the modeler / designer (web application) for the customer so that he can drag and drop this service task without much configuration.

Example:
I develop a Java program as a Java Delegate: like this here: https://gist.github.com/tijsrademakers/bd73fbd5ac6fd5350055e29bd9bf012e#file-flowable-6-introtask-java

After that I compile and deploy the jar file the WEB-INF/lib

What do I have to do the be able to use this service task in the designer “out-of-the-box”?
I want to know how to deploy/import/include my extension JAR to flowable-modeler so that I am able to see the custom service task in the flowable-modeler palette.

Custom defined (service) tasks in web based modeler
How to add the custom task(service task implementation) in web modeler pallet
#2

Hi John,

the similar question is:

Regards
Martin

#3

Hi Martin,

I appreciate your answer. It is a bit hard to follow. Is there any official guide for this?
A little code example of a basic custom service task would help me greatly.

Thanks in advance.

Regards
John

#4

Hi John,

The whole example is in the pull request https://github.com/flowable/flowable-engine/pull/382

But let’s do it step by step.

  1. Add new node to stencilset_bpmn.json ServiceTask node is a good example. After this step new node is added to modeler paletes.
  2. Implement json -> bpmn and bpmn -> json converter and add it to the converters. The best example is org.flowable.editor.language.json.converter.ServiceTaskJsonConverter. (this step is needed only in the case when you want to change something in ServiceTask node in the stencil set.
  3. In your case this step is not needed, because you just need to use “default” service task behavior but you can also implement your own behavior to behave differently from service task (see e.g. org.flowable.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior)

Regards
Martin

1 Like
#5

Dear Martin,

I’m new to Flowable so I might be wrong, but I think I’m trying to do something similar without success.

What I need to achieve is to make custom tasks available in the web based modeler so that users can create workflows starting from them.
Moreover I need these custom tasks to have a java delegate class associated by default.

I can easily achieve that with the eclipse editor but I don’t understand how to do that for the web based one.

What I did so far was: checking out the flowable engine from github (not even sure if this is needed), find the json file which should contain the tasks in the palette but I don’t even know which steps to follow in order to deploy them into the modeler.

Could you please guide me through that process?

Thanks a lot,

Jacopo

#6

Hi Jacopo,

did you try to add new service task to palette?
after that you can add default value to java delegate class attribute.
Next task is to make non needed attributes hidden.

Regards
Martin

#7

Hi Martin,

what I manage to do so far is:

  • checkout flowable-engine from github

  • find the stencilset_bpmn.json file in flowable-engine\modules\flowable-ui-modeler\flowable-ui-modeler-logic\src\main\resources

  • Add the following lines for a custom task:

    {
    “type” : “node”,
    “id” : “CustomTask”,
    “title” : “Custom task”,
    “description” : “A service task with custom logic”,
    “view” : (COPIED FROM SERVICE TASK)
    “icon” : “activity/list/type.service.png”,
    “groups” : [ “Activities” ],
    “propertyPackages” : [ “overrideidpackage”, “namepackage”, “documentationpackage”, “asynchronousdefinitionpackage”, “exclusivedefinitionpackage”, “servicetasktriggerablepackage”, “executionlistenerspackage”, “multiinstance_typepackage”, “multiinstance_cardinalitypackage”, “multiinstance_collectionpackage”, “multiinstance_variablepackage”, “multiinstance_conditionpackage”, “isforcompensationpackage”, “servicetaskclasspackage”, “servicetaskexpressionpackage”, “servicetaskdelegateexpressionpackage”, “servicetaskfieldspackage”, “servicetaskresultvariablepackage”, “skipexpressionpackage” ],
    “hiddenPropertyPackages” : [ ],
    “roles” : [ “Activity”, “sequence_start”, “sequence_end”, “ActivitiesMorph”, “all” ]
    }

Thanks,
Jacopo

#8

Hi Martin,

I have a small update:
I managed to build flowable-engine with ant on windows. I saw this generated the flwoable-modeler war.
Also, navigating into the modules to flowable-ui-modeler I see the various submodules (among which there is flowable-ui-modeler-logic which contains the stencil set json file.

I edited it and rebuild with maven, so when I deploy the new war I can see the new tasks as you can see from the picture.

CustomTasks

What are the next steps now?
Which customization should I make in order to make this custom tasks ready to be put in a workflow?
How can I associate the java delegate to it?

Kind Regards,
Jacopo

#9

Hi,
add default value to e.g. java delegate class attribute.

Martin

#10

Hi,

where should I specify the delegate class?

Thanks,
Jacopo

#11

Hi,

{
    "name" : "claim_task_scripttextpackage",
    "properties" : [ {
      "id" : "scripttext_claim_task",
      "type" : "Text",
      "title" : "Script",
      "value" : "import static org.flowable.app.service.runtime.TestHelper.*;\n println 'Replace $USERID and $TASK_DEFINITION_KEY with proper value';\n processInstanceIds = getSubProcessInstanceIds(processInstanceId, execution);\n taskId = getVirtualProcessEngine(execution).getTaskService().createTaskQuery().processInstanceIdIn(processInstanceIds).taskDefinitionKey(\"$TASK_DEFINITION_KEY\").singleResult().getId();\n getVirtualProcessEngine(execution).getTaskService().claim(taskId, '$USER_ID');",
      "description" : "Script text of the script task.",
      "popular" : true
    } ]
  }

shows how to create new package with default value. This package can be used in your custom task. In fact you have to create new package based on e.g servicetaskdelegateexpressionpackage.

Regards
Martin

#12

Hi Martin,

I made some progress following your advice. Now I can drag the custom service tasks from the palette and have the proper delegate class associated with them.

editorOk
editorOk2

When I try to validate the workflow I get some warnings concerning the tasks and some criticals concerning the link between them. As consequence when I try to export it I get an empty workflow. The only task ok is the receive task (which I did not customize).

validKo

This is an example of what I added in the stencilset for the custom tasks:

{
    "type" : "node",
    "id" : "CustomTask",
    "title" : "Custom Task",
    "description" : "A custom task",
    "view" : "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg\n   xmlns=\"http://www.w3.org/2000/svg\"\n   xmlns:svg=\"http://www.w3.org/2000/svg\"\n   xmlns:oryx=\"http://www.b3mn.org/oryx\"\n   xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n\n   width=\"102\"\n   height=\"82\"\n   version=\"1.0\">\n  <defs></defs>\n  <oryx:magnets>\n  \t<oryx:magnet oryx:cx=\"1\" oryx:cy=\"20\" oryx:anchors=\"left\" />\n  \t<oryx:magnet oryx:cx=\"1\" oryx:cy=\"40\" oryx:anchors=\"left\" />\n  \t<oryx:magnet oryx:cx=\"1\" oryx:cy=\"60\" oryx:anchors=\"left\" />\n  \t\n  \t<oryx:magnet oryx:cx=\"25\" oryx:cy=\"79\" oryx:anchors=\"bottom\" />\n  \t<oryx:magnet oryx:cx=\"50\" oryx:cy=\"79\" oryx:anchors=\"bottom\" />\n  \t<oryx:magnet oryx:cx=\"75\" oryx:cy=\"79\" oryx:anchors=\"bottom\" />\n  \t\n  \t<oryx:magnet oryx:cx=\"99\" oryx:cy=\"20\" oryx:anchors=\"right\" />\n  \t<oryx:magnet oryx:cx=\"99\" oryx:cy=\"40\" oryx:anchors=\"right\" />\n  \t<oryx:magnet oryx:cx=\"99\" oryx:cy=\"60\" oryx:anchors=\"right\" />\n  \t\n  \t<oryx:magnet oryx:cx=\"25\" oryx:cy=\"1\" oryx:anchors=\"top\" />\n  \t<oryx:magnet oryx:cx=\"50\" oryx:cy=\"1\" oryx:anchors=\"top\" />\n  \t<oryx:magnet oryx:cx=\"75\" oryx:cy=\"1\" oryx:anchors=\"top\" />\n  \t\n  \t<oryx:magnet oryx:cx=\"50\" oryx:cy=\"40\" oryx:default=\"yes\" />\n  </oryx:magnets>\n  <g pointer-events=\"fill\" oryx:minimumSize=\"50 40\">\n\t<rect id=\"text_frame\" oryx:anchors=\"bottom top right left\" x=\"1\" y=\"1\" width=\"94\" height=\"79\" rx=\"10\" ry=\"10\" stroke=\"none\" stroke-width=\"0\" fill=\"none\" />\n\t<rect id=\"bg_frame\" oryx:resize=\"vertical horizontal\" x=\"0\" y=\"0\" width=\"100\" height=\"80\" rx=\"10\" ry=\"10\" stroke=\"#bbbbbb\" stroke-width=\"1\" fill=\"#f9f9f9\" />\n\t\t<text \n\t\t\tfont-size=\"12\" \n\t\t\tid=\"text_name\" \n\t\t\tx=\"50\" \n\t\t\ty=\"40\" \n\t\t\toryx:align=\"middle center\"\n\t\t\toryx:fittoelem=\"text_frame\"\n\t\t\tstroke=\"#373e48\">\n\t\t</text>\n\t\n\t<g id=\"serviceTask\" transform=\"translate(3,3)\">\n\t<path oryx:anchors=\"top left\"\n\t\tstyle=\"fill:#72a7d0;stroke:none\"\n     d=\"M 8,1 7.5,2.875 c 0,0 -0.02438,0.250763 -0.40625,0.4375 C 7.05724,3.330353 7.04387,3.358818 7,3.375 6.6676654,3.4929791 6.3336971,3.6092802 6.03125,3.78125 6.02349,3.78566 6.007733,3.77681 6,3.78125 5.8811373,3.761018 5.8125,3.71875 5.8125,3.71875 l -1.6875,-1 -1.40625,1.4375 0.96875,1.65625 c 0,0 0.065705,0.068637 0.09375,0.1875 0.002,0.00849 -0.00169,0.022138 0,0.03125 C 3.6092802,6.3336971 3.4929791,6.6676654 3.375,7 3.3629836,7.0338489 3.3239228,7.0596246 3.3125,7.09375 3.125763,7.4756184 2.875,7.5 2.875,7.5 L 1,8 l 0,2 1.875,0.5 c 0,0 0.250763,0.02438 0.4375,0.40625 0.017853,0.03651 0.046318,0.04988 0.0625,0.09375 0.1129372,0.318132 0.2124732,0.646641 0.375,0.9375 -0.00302,0.215512 -0.09375,0.34375 -0.09375,0.34375 L 2.6875,13.9375 4.09375,15.34375 5.78125,14.375 c 0,0 0.1229911,-0.09744 0.34375,-0.09375 0.2720511,0.147787 0.5795915,0.23888 0.875,0.34375 0.033849,0.01202 0.059625,0.05108 0.09375,0.0625 C 7.4756199,14.874237 7.5,15.125 7.5,15.125 L 8,17 l 2,0 0.5,-1.875 c 0,0 0.02438,-0.250763 0.40625,-0.4375 0.03651,-0.01785 0.04988,-0.04632 0.09375,-0.0625 0.332335,-0.117979 0.666303,-0.23428 0.96875,-0.40625 0.177303,0.0173 0.28125,0.09375 0.28125,0.09375 l 1.65625,0.96875 1.40625,-1.40625 -0.96875,-1.65625 c 0,0 -0.07645,-0.103947 -0.09375,-0.28125 0.162527,-0.290859 0.262063,-0.619368 0.375,-0.9375 0.01618,-0.04387 0.04465,-0.05724 0.0625,-0.09375 C 14.874237,10.52438 15.125,10.5 15.125,10.5 L 17,10 17,8 15.125,7.5 c 0,0 -0.250763,-0.024382 -0.4375,-0.40625 C 14.669647,7.0572406 14.641181,7.0438697 14.625,7 14.55912,6.8144282 14.520616,6.6141566 14.4375,6.4375 c -0.224363,-0.4866 0,-0.71875 0,-0.71875 L 15.40625,4.0625 14,2.625 l -1.65625,1 c 0,0 -0.253337,0.1695664 -0.71875,-0.03125 l -0.03125,0 C 11.405359,3.5035185 11.198648,3.4455201 11,3.375 10.95613,3.3588185 10.942759,3.3303534 10.90625,3.3125 10.524382,3.125763 10.5,2.875 10.5,2.875 L 10,1 8,1 z m 1,5 c 1.656854,0 3,1.3431458 3,3 0,1.656854 -1.343146,3 -3,3 C 7.3431458,12 6,10.656854 6,9 6,7.3431458 7.3431458,6 9,6 z\" />\n\t</g>\n  \n\t<g id=\"parallel\">\n\t\t<path oryx:anchors=\"bottom\" fill=\"none\" stroke=\"#bbbbbb\" d=\"M46 70 v8 M50 70 v8 M54 70 v8\" stroke-width=\"2\" />\n\t</g>\n\t\n\t<g id=\"sequential\">\n\t\t<path oryx:anchors=\"bottom\" fill=\"none\" stroke=\"#bbbbbb\" stroke-width=\"2\" d=\"M46,76h10M46,72h10 M46,68h10\"/>\n\t</g>\n\t\n\t<g id=\"compensation\">\n\t\t<path oryx:anchors=\"bottom\" fill=\"none\" stroke=\"#bbbbbb\" d=\"M 62 74 L 66 70 L 66 78 L 62 74 L 62 70 L 58 74 L 62 78 L 62 74\" stroke-width=\"1\" />\n\t</g>\n  </g>\n</svg>",
    "icon" : "activity/list/custom/custom.png",
    "groups" : [ "BPMN.STENCILS.GROUPS.ACTIVITIES" ],
    "propertyPackages" : [ "CustomTaskNamePackage", "CustomTaskClassPackage", "CustomTaskOverrideIdPackage", "CustomTaskDocumentationPackage", "CustomTaskFieldsPackage", "custom_multiinstance_typepackage", "custom_isforcompensationpackage"],
    "hiddenPropertyPackages" : [ ],
    "roles" : [ "Activity", "sequence_start", "sequence_end", "ActivitiesMorph", "all" ]
  },

What am I doing wrong? Is there a way to get more information out of the validation process?
Thanks a lot,
Jacopo