[ofbiz-framework] branch trunk updated: Improved: Convert party/LookupServices.xml mini-lang to groovyDSL (OFBIZ-11362)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Convert party/LookupServices.xml mini-lang to groovyDSL (OFBIZ-11362)

nmalin
This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2b98727  Improved: Convert party/LookupServices.xml mini-lang to groovyDSL (OFBIZ-11362)
2b98727 is described below

commit 2b98727c5f71003f26cd70ee135e35a7b6c999dd
Author: Nicolas Malin <[hidden email]>
AuthorDate: Wed Mar 4 21:25:23 2020 +0100

    Improved: Convert party/LookupServices.xml mini-lang to groovyDSL
    (OFBIZ-11362)
   
    Deprecate lookupParty service by performFindParty and rewrite to work as bridge during the deprecation time
---
 .../groovyScripts/party/LookupServices.groovy      | 32 ++++++++++++++++
 applications/party/minilang/LookupServices.xml     | 43 ----------------------
 applications/party/servicedef/services.xml         |  8 +++-
 3 files changed, 38 insertions(+), 45 deletions(-)

diff --git a/applications/party/groovyScripts/party/LookupServices.groovy b/applications/party/groovyScripts/party/LookupServices.groovy
new file mode 100644
index 0000000..a13f773
--- /dev/null
+++ b/applications/party/groovyScripts/party/LookupServices.groovy
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * lookupParty is deprecated, and only present for backward compatibility during the deprecation time
+ */
+def lookupParty() {
+    Map serviceResult = run service: 'performFindParty', with: parameters
+    List lookupResult = []
+    serviceResult.listIt.getCompleteList().each {
+        lookupResult << [label: it.firstName, value: it.partyId]
+    }
+    Map result = success()
+    result.lookupResult = lookupResult
+    return result
+}
\ No newline at end of file
diff --git a/applications/party/minilang/LookupServices.xml b/applications/party/minilang/LookupServices.xml
deleted file mode 100644
index 7959ef5..0000000
--- a/applications/party/minilang/LookupServices.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
-    <simple-method method-name="lookupParty" short-description="Lookup a party">
-        <if-not-empty field="parameters.firstName">
-            <set from-field="parameters.firstName" field="LookupMap.firstName"/>
-        </if-not-empty>
-        <if-not-empty field="parameters.lastName">
-            <set from-field="parameters.lastName" field="LookupMap.lastName"/>
-        </if-not-empty>
-        <find-by-and entity-name="Person" map="LookupMap" list="parties"/>
-        <iterate list="parties" entry="party">
-            <set from-field="party.firstName" field="resultEntry.label"/>
-            <set from-field="party.partyId" field="resultEntry.value"/>
-            <field-to-list field="resultEntry" list="lookupResult"/>
-        </iterate>
-        <if-empty field="parties">
-            <set value="No match" field="resultEntry.label"/>
-            <set value="" field="resultEntry.value"/>
-            <field-to-list field="resultEntry" list="lookupResult"/>
-        </if-empty>
-        <field-to-result field="lookupResult"/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/party/servicedef/services.xml b/applications/party/servicedef/services.xml
index 2e8f2ab..22b8e9f 100644
--- a/applications/party/servicedef/services.xml
+++ b/applications/party/servicedef/services.xml
@@ -233,9 +233,13 @@ under the License.
         <attribute name="partyIdTo" type="String" mode="IN" optional="false"/>
     </service>
 
-    <service name="lookupParty" engine="simple"
-        location="component://party/minilang/LookupServices.xml" invoke="lookupParty" auth="true">
+    <service name="lookupParty" engine="groovy"
+        location="component://party/groovyScripts/party/LookupServices.groovy" invoke="lookupParty" auth="true">
         <description>Performs a lookup for parties</description>
+        <deprecated use-instead="performFindParty" since="Upcoming Branch">
+            use performFindParty to realize your search, the service lookupParty is inconsistent
+            and need to replace by appropriate service
+        </deprecated>
         <attribute name="firstName" type="String" form-display="true" form-label="First name" mode="IN" optional="true"/>
         <attribute name="lastName" type="String" form-display="true" form-label="Last name" mode="IN" optional="true"/>
         <attribute name="lookupResult" type="List" mode="OUT" optional="false"/>