[ofbiz-framework] branch trunk updated: Improved: Convert getDataResource service from mini-lang to groovy DSL(OFBIZ-11381)

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 getDataResource service from mini-lang to groovy DSL(OFBIZ-11381)

Pawan Verma-2
This is an automated email from the ASF dual-hosted git repository.

pawan 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 9e97730  Improved: Convert getDataResource service from mini-lang to groovy DSL(OFBIZ-11381)
9e97730 is described below

commit 9e97730288eda4a49637c4a8e0b1976fd27bb459
Author: Pawan Verma <[hidden email]>
AuthorDate: Wed Jul 1 16:02:33 2020 +0530

    Improved: Convert getDataResource service from mini-lang to groovy DSL(OFBIZ-11381)
   
    Thanks: Devanshu for report and Kirti for the patch.
---
 .../groovyScripts/content/ContentServices.groovy       | 18 ++++++++++++++++++
 .../content/minilang/content/ContentServices.xml       | 15 ---------------
 applications/content/servicedef/services.xml           |  4 ++--
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy
index efb8bd0..a87c276 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -357,3 +357,21 @@ def updateDownloadContent() {
     }
     return result
 }
+
+def getDataResource() {
+    Map result = success()
+    resultData = [:]
+
+    GenericValue dataResource = from('DataResource').where(parameters).queryOne()
+    if (dataResource) {
+        resultData.dataResource = dataResource
+        if ("ELECTRONIC_TEXT" == dataResource.dataResourceTypeId) {
+            resultData.electronicText = dataResource.getRelatedOne('ElectronicText', false)
+        }
+        if ("IMAGE_OBJECT" == dataResource.dataResourceTypeId) {
+            resultData.imageDataResource = dataResource.getRelatedOne('ImageDataResource', false)
+        }
+    }
+    result.resultData = resultData
+    return result
+}
\ No newline at end of file
diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml
index 3ff187f..9b63809 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -395,21 +395,6 @@
     </simple-method-->
 
     <!-- retrieve Data resource information -->
-    <simple-method method-name="getDataResource" short-description="get the content and relasted resource information" login-required="false">
-        <entity-one entity-name="DataResource" value-field="resultData.dataResource"/>
-        <if-not-empty field="resultData.dataResource">
-            <if-compare field="resultData.dataResource.dataResourceTypeId" value="ELECTRONIC_TEXT" operator="equals">
-                <get-related-one value-field="resultData.dataResource" relation-name="ElectronicText"
-                    to-value-field="resultData.electronicText"/>
-            </if-compare>
-            <if-compare field="resultData.dataResource.dataResourceTypeId" value="IMAGE_OBJECT" operator="equals">
-                <get-related-one value-field="resultData.dataResource" relation-name="ImageDataResource"
-                    to-value-field="resultData.imageDataResource"/>
-            </if-compare>
-        </if-not-empty>
-        <field-to-result field="resultData" result-name="resultData"/>
-    </simple-method>
-
     <simple-method method-name="getContentAndDataResource" short-description="get the content and related resource information" login-required="false">
         <entity-one entity-name="Content" value-field="resultDataContent.content">
             <field-map field-name="contentId" from-field="parameters.contentId"/>
diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml
index 71a6b6c..bb2a3ed 100644
--- a/applications/content/servicedef/services.xml
+++ b/applications/content/servicedef/services.xml
@@ -48,8 +48,8 @@
         <attribute mode="OUT" name="resultData" optional="true" type="java.util.Map"/>
     </service>
 
-    <service name="getDataResource" engine="simple" default-entity-name="DataResource" auth="true"
-            location="component://content/minilang/content/ContentServices.xml" invoke="getDataResource">
+    <service name="getDataResource" engine="groovy" default-entity-name="DataResource" auth="true"
+            location="component://content/groovyScripts/content/ContentServices.groovy" invoke="getDataResource">
         <description>Get Content and resource information</description>
         <permission-service service-name="genericContentPermission" main-action="VIEW"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>