Java Service Task in Designer / Modeler

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

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

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

Martin

Hi,

where should I specify the delegate class?

Thanks,
Jacopo

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

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

Hi,

I had a look at the code of SequenceflowValidator. As far as I understood the sourceRef and targetRef are both empty for the custom tasks I added in the stencilset.

I don’t understand why it happens and how to avoid it. Could anybody help me with that? :pray:

Thanks a lot,
Jacopo

Hi Jacopo.

It’s hard to guess. It would be better if you provide small jUnit test for that.

Regards
Martin

Hi Martin,

what kind of jUnit test should I provide? I’m not yet to the point or running the workflow since it cannot be validated.

Is there a sample custom task that you can show me that works?
Is there any step I am missing maybe? The only thinkg I did was modifying the stencil set json.

Thanks a lot,
Jacopo

Hi Jacopo.

The test which shows how your model validation fails.

yes I posted the links to my pull request with the changes for simulation and testing framework in previous comment. may be I should write a short blog about it.

Martin

Hi Martin,

i am also trying to add custom task but always have many problem and did not find any proper steps guide that i can add custom task in flowable modeler.

Can you please guide me i just want to add custom task with custom dropdown properties, with associated java delegate.

so in delegate i can have all selected properties and userinput in that delegate after business logic move to next task.

please help me out from this problem.

Is there a way to externalize a custom task into a separate JAR? I’d like to avoid forking the engine and it seems that the converters are inside the engine.

I don’t think is possible to externalize a custom task into a separate JAR, because you need to modify several flowable-modules (listed in this post: How to extend Flowable to add "Business Domain" specific BPMN elements) to make it work.

Hi ,I am new to flowable.I am trying to customize the pallete.Require little clarification regarding the steps to be followed for the same.I am using apache tomcat server for flowable.I followed the steps mentioned above and was able to make changes in Stencilset_bpmn file.But while generating jar for the flowable-ui-modeler-logic using STS(spring tool) facing below issues:

[INFO] Scanning for projects…
[INFO]
[INFO] ---------------< org.flowable:flowable-ui-modeler-logic >---------------
[INFO] Building flowable-ui-modeler-logic 6.6.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.flowable:flowable-ui-common:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-bpmn-model:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-bpmn-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-bpmn-layout:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-process-validation:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-image-generator:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-json-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-cmmn-model:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-cmmn-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-cmmn-json-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-cmmn-image-generator:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-dmn-xml-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-dmn-json-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-dmn-image-generator:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-form-model:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-form-json-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-event-registry-model:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-event-registry-json-converter:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.flowable:flowable-app-engine-api:jar:6.6.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.855 s
[INFO] Finished at: 2020-10-12T12:06:39+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project flowable-ui-modeler-logic: Could not resolve dependencies for project org.flowable:flowable-ui-modeler-logic:jar:6.6.0-SNAPSHOT: The following artifacts could not be resolved: org.flowable:flowable-ui-common:jar:6.6.0-SNAPSHOT, org.flowable:flowable-bpmn-model:jar:6.6.0-SNAPSHOT, org.flowable:flowable-bpmn-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-bpmn-layout:jar:6.6.0-SNAPSHOT, org.flowable:flowable-process-validation:jar:6.6.0-SNAPSHOT, org.flowable:flowable-image-generator:jar:6.6.0-SNAPSHOT, org.flowable:flowable-json-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-cmmn-model:jar:6.6.0-SNAPSHOT, org.flowable:flowable-cmmn-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-cmmn-json-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-cmmn-image-generator:jar:6.6.0-SNAPSHOT, org.flowable:flowable-dmn-xml-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-dmn-json-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-dmn-image-generator:jar:6.6.0-SNAPSHOT, org.flowable:flowable-form-model:jar:6.6.0-SNAPSHOT, org.flowable:flowable-form-json-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-event-registry-model:jar:6.6.0-SNAPSHOT, org.flowable:flowable-event-registry-json-converter:jar:6.6.0-SNAPSHOT, org.flowable:flowable-app-engine-api:jar:6.6.0-SNAPSHOT: Could not find artifact org.flowable:flowable-ui-common:jar:6.6.0-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Help me to solve the issue so that I can generate jar.

run mvn install -DskipTests=true -Pdistro in the project root dir. It will install all snapshot dependencies to your local mvn repo.

Hi Martin,

Thanks for your help.Now I am able to generate jar and customize the pallete as shown below.


But, when I try to validate the modeled process it gives error as shown below.
Please help me to solve the issue.

Hi,

It’s hard to guess what is going on. I would say that the problem is in the process model.

Martin

Hi Japelleg,

I am trying with customizing pallete.I was extend the pallete succesfully but facing the similar issue when validating the workflow.Kindly guide me in sorting the issue.

The fact the sequence flow validator isn’t seeing it as a real ‘task’, it means probably it isn’t registered as such. Can you share a bit how your palette elements looks like?

Hi Martin,

For adding custom task I had followed these two steps:

  1. Add new node to stencilset_bpmn.json. After this step new node is added to modeler paletes.
    2)Implement json -> bpmn and bpmn -> json converter and add it to the converters.
  2. Generate jar for the flowable ui and deploy the same in tomcat.

Thanks martin and joram