You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/02/24 11:11:00 UTC

[jira] [Commented] (OFBIZ-12761) Multi Param Model Service Map

    [ https://issues.apache.org/jira/browse/OFBIZ-12761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17693139#comment-17693139 ] 

ASF subversion and git services commented on OFBIZ-12761:
---------------------------------------------------------

Commit efd20201a1e44a861dd60453e2b1fd0d02496f71 in ofbiz-framework's branch refs/heads/trunk from Nicolas Malin
[ https://gitbox.apache.org/repos/asf?p=ofbiz-framework.git;h=efd20201a1 ]

Improvement: Multi Param Model Service Map (OFBIZ-12761)

When you define a service with a map as parameter or a List like the following example :

    <service name="exampleService" location="component:..." invoke="exampleService">
        <description>Service example use case with internal attributes to validate </description>
        <attribute name="partyId" type="String" mode="IN"/>
        <attribute name="header" type="java.util.Map" mode="IN"/>
    </service>

You can't define the "header" map structure to ensure data quality.

The services.xsd currently supports attribute elements as children so we can improve the previous example

    <service name="exampleService" location="component:..."
        invoke="exampleService" transaction-timeout="7200">
        <description> Service example use case with internal attributes to validate </description>
        <implements service="ApiJsonInterface"/>
        <attribute name="partyId" type="String" mode="IN"/>
        <attribute name="header" type="java.util.Map" mode="IN">
            <attribute name="internalCode" type="String" optional="false"/>
        </attribute>
    </service>

This commit improves the service engine to analyze the Map content or List of Map, if the service defines is

        <attribute name="header" type="java.util.Map" mode="IN">
            <attribute name="internalCode" type="String" optional="false"/>
        </attribute>

It accepts a context like `[partyId: "foo", [header: [internalCode: "bar"]]]`
or

        <attribute name="header" type="java.util.List" mode="IN">
            <attribute name="internalCode" type="String" optional="false"/>
        </attribute>

It accepts a context like `[partyId: "foo", header: [[internalCode: "bar"]]]`

By the way while improving the code to support this, we took the opportunity to refactor outdated code using java streams and cover it by unit tests.

Thanks to Gaetan Chaboussie for helping me with this improvement


> Multi Param Model Service Map
> -----------------------------
>
>                 Key: OFBIZ-12761
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-12761
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework/service
>    Affects Versions: 22.01.01, Upcoming Branch
>            Reporter: Gaetan Chaboussie
>            Assignee: Nicolas Malin
>            Priority: Minor
>              Labels: patch
>         Attachments: MultiParamServiceMapAndTest.patch
>
>
> Hello community.
> We had a use case with the need for validation of IN params of services.
> For example we had to check that the following service definition was correctly filled.
> ```xml
>     <service name="exampleService" location="component:..."
>         invoke="exampleService" transaction-timeout="7200">
>         <description> Service example use case with internal attributes to validate </description>
>         <implements service="ApiJsonInterface"/>
>         <attribute name="partyId" type="String" mode="IN"/>
>         <attribute name="header" type="java.util.Map" mode="IN">
>             <attribute name="internal_code" type="String" optional="false"/>
>         </attribute>
>     </service>
> ```
> As is, the framework doesn't offer any clean way of doing this, so we implemented some modification to ModelService.
> So we used TDD to develop the improvement we needed and that may prove a valuable improvement for the framework.
> Using these tests, we took the opportunity to refactor outdated code using java streams.
> Please see the patch attached to the ticket containing code and tests.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)