apache / incubator-kie-kogito-runtimes

Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
Apache License 2.0
533 stars 205 forks source link

Provide ability to map a Script Task to a java class/operation in the same way a Service Task is used. #1925

Open StephenOTT opened 2 years ago

StephenOTT commented 2 years ago

Description

The BPMN is a visual semantic with varying abilities as part of its implementation. The Service task have the ability to call a interface/operation which provides nice re-use ability. But the script task is missing this.
From a visual semantics, a Service Task is often used to represent some sort of system interaction (such as calling an API) or performing some sort of library call (such as "Convert the file into another format"). But a script task is often used for data modifications, data prep, data lookups, etc. A script task would benefit from being able to call an interface/operation in the same way a service task is used. Imagine having common Java functions that are reused for script like purposes: it would be highly beneficial t have the ability to reference a class/method rather than having to re-paste the java snippet into each definition.

Implementation ideas

No response

fjtirado commented 2 years ago

This ability is provided by Kogito out of the box for service tasks
See https://github.com/kiegroup/kogito-examples/tree/stable/kogito-quarkus-examples/process-service-calls-quarkus ( I know you are aware of it, just including the link for reference) In my opinion, allowing the script task to use the same functionality than service task will blur the difference making the script one pointless. The usage you are describing is also a good fit for service task. In a service task, which might accept KogitoProcessContext as latest parameter, you can perform all the operations you are mentioning, see an example of providing context to a service call (context is always the last parameter and is optional) On summary, you use script when you have a code snippet, you use service when you code is complex enough that it deserve a method. In my case, and this is a question of taste, I will be using service for almost everything, but that are people that might feel more comfortable using code snippets inside the bpmn.

StephenOTT commented 2 years ago

@fjtirado What you are describing is the service task's and script tasks chosen implementation. I am describing the BPMN business semantic and visual usage for describing a process/workflow. In other BPM engines a script task is often literal "script" like javascript, etc. But with codegen, the default is to embed the java in the same way a gateway logic is written. But just as with gateway logic, you often want to re-use snippets of code (common utility methods, etc). So you want to be able to reference another file and call that method.

Having the same code snippet repeatedly does not warrant "use a service task", as this changes the semantics of what the BPMN is describing. Why not just have service task everywhere and have a impl called script? Why split script task into its own task type?... because the BPMN business process is visually describing a different semantic. Why use a Message Throw if i could just use a service task? Why use a Blank Start Event if i could use a Message Start Event? And why use a Send/Receive Event if i could just use Messages? Because the semantics are different and the tell a different business story.