Hello,

In my opinion, the semantics of calling an event handler vs a service
implementation are different, albeit similar enough that most
handler/implementation authors wouldn't necessarily care how the code was
called.

The untyped nature of Groovy had allowed a certain degree of flexibility in
code that GroovyBaseScript#success could be relied upon to prepare a
response appropriate to the calling conventions of an event handler or
service implementation. However over the last decade, possibly driven by
increased use of linters/static analysers, we have seen a push back towards
explicit typing, particularly on public methods.

If we continue to adopt the guidance from static analysers and apply
explicit typing to public methods in our groovy code, then we need to avoid
the black box approach of GroovyBaseScript#success figuring out what
calling conventions (i.e. event or service) are in play and, instead, a
groovy method should be intentionally written as either a service or event
handler.

If we have cases where a groovy method is used to provide implementations
for both a service and an event handler, then we can employ a thin adapter
layer to convert the result type between the two calling conventions. Do we
know if many such cases currently exist in OFBiz?

My preference would be to see GroovyBaseScript#success deprecated and
replaced with methods along the lines of GroovyBaseScript#scriptSuccess and
GroovyCaseScript#eventSuccess that return a Map<String, Object> and String
respectively.

Thanks,

Dan.

On Wed, 19 Apr 2023 at 16:44, Jacques Le Roux <jacques.le.r...@les7arts.com>
wrote:

> Hi All,
>
> At OFBIZ-12801, we had a discussion with Daniel and Gil about the
> described issue (last comments there)
> We are unsure of the best solution, so this thread to discuss and decide.
>
> As Gil reported, Jacopo's comment of the related commit* contains
>
>     <<these helper methods have been enhanced in order to be used by
> groovy method executed as services or events in a transparent way.>>
>
> What would be your opinion about a best solution?
>
> TIA
>
> Jacques
>
> * http://svn.apache.org/viewvc?view=revision&revision=1298908
>


-- 
Daniel Watford

Reply via email to