[ofbiz-framework] branch trunk updated: Improved: Converted getContentAndDataResource service from mini-lang to groovy DSL. (OFBIZ-11382) Thanks Devanshu Vyas for reporting and Ravi Lodhi for the patch.

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: Converted getContentAndDataResource service from mini-lang to groovy DSL. (OFBIZ-11382) Thanks Devanshu Vyas for reporting and Ravi Lodhi for the patch.

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

surajk 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 84f82a4  Improved: Converted getContentAndDataResource service from mini-lang to groovy DSL. (OFBIZ-11382) Thanks Devanshu Vyas for reporting and Ravi Lodhi for the patch.
     new dcc848b  Merge branch 'trunk' of https://gitbox.apache.org/repos/asf/ofbiz-framework into trunk
84f82a4 is described below

commit 84f82a44d15b6bad38b3d89f3e6dcece7edbb659
Author: Suraj Khurana <[hidden email]>
AuthorDate: Sat Jul 4 14:44:29 2020 +0530

    Improved: Converted getContentAndDataResource service from mini-lang to groovy DSL.
    (OFBIZ-11382)
    Thanks Devanshu Vyas for reporting and Ravi Lodhi for the patch.
---
 .../groovyScripts/content/ContentServices.groovy   | 23 ++++++++++++++++------
 .../content/minilang/content/ContentServices.xml   | 23 ++--------------------
 applications/content/servicedef/services.xml       |  4 ++--
 3 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy
index a87c276..66f3403 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -50,7 +50,6 @@ def createTextAndUploadedContent(){
     result.contentId = parameters.parentContentId
     return result
 }
-
 def deactivateAllContentRoles() {
     List contentRoles = from("ContentRole").
             where("contentId", parameters.contentId, "partyId", parameters.partyId, "roleTypeId", parameters.roleTypeId)
@@ -63,7 +62,6 @@ def deactivateAllContentRoles() {
     }
     return success()
 }
-
 def createContentAlternativeUrl() {
     //create Content Alternative URLs.
     String contentCreated
@@ -173,7 +171,6 @@ def createContentAlternativeUrl() {
             }
         }
     }
-
     map = success()
     map.contentCreated = contentCreated
     return map
@@ -190,7 +187,6 @@ def updateEmailContent() {
         run service: "updateElectronicText", with: [dataResourceId: parameters.htmlBodyDataResourceId, textData: parameters.htmlBody]
     }
 }
-
 def createArticleContent() {
     // Post a new Content article Entry
     String origContentAssocTypeId = parameters.contentAssocTypeId
@@ -317,7 +313,6 @@ def createArticleContent() {
     result.contentId = contentId
     return result
 }
-
 def setContentStatus() {
     Map resultMap = new HashMap()
     content = from("Content").where("contentId", parameters.contentId).queryOne()
@@ -357,7 +352,6 @@ def updateDownloadContent() {
     }
     return result
 }
-
 def getDataResource() {
     Map result = success()
     resultData = [:]
@@ -374,4 +368,21 @@ def getDataResource() {
     }
     result.resultData = resultData
     return result
+}
+def getContentAndDataResource () {
+    resultMap = [:];
+    resultDataContent = [:];
+    content = from("Content").where("contentId", parameters.contentId).queryOne();
+    resultDataContent.content = content;
+    if (content && content.dataResourceId) {
+        result = runService("getDataResource", ["dataResourceId": content.dataResourceId, "userLogin": userLogin]);
+        if (result) {
+            resultData = result.resultData;
+            resultDataContent.dataResource = resultData.dataResource;
+            resultDataContent.electronicText = resultData.electronicText;
+            resultDataContent.imageDataResource = resultData.imageDataResource;
+        }
+    }
+    resultMap.resultData = resultDataContent;
+    return resultMap;
 }
\ No newline at end of file
diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml
index 9b63809..1d495f7 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -394,40 +394,21 @@
         </if-not-empty>
     </simple-method-->
 
-    <!-- retrieve Data resource information -->
-    <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"/>
-        </entity-one>
-        <if-not-empty field="resultDataContent.content">
-            <if-not-empty field="resultDataContent.content.dataResourceId">
-                <set field="parameters.dataResourceId" from-field="resultDataContent.content.dataResourceId"/>
-                <call-simple-method method-name="getDataResource"/>
-                <set field="resultDataContent.dataResource" from-field="resultData.dataResource"/>
-                <set field="resultDataContent.electronicText" from-field="resultData.electronicText"/>
-                <set field="resultDataContent.imageDataResource" from-field="resultData.imageDataResource"/>
-            </if-not-empty>
-            <field-to-result field="resultDataContent" result-name="resultData"/>
-        </if-not-empty>
-    </simple-method>
-
     <simple-method method-name="getPublicForumMessage" short-description="get the content and related resource information without security" login-required="false">
         <set field="publicForumMessage" value="true"/>
-        <call-simple-method method-name="getContentAndDataResource"/>
+        <set-service-fields service-name="getContentAndDataResource" map="parameters" to-map="getC"/>
+        <call-service service-name="getContentAndDataResource" in-map-name="getC"/>
     </simple-method>
-
     <simple-method method-name="forceIndexContentKeywords" short-description="induce all the keywords of a content">
         <entity-one entity-name="Content" value-field="content"/>
         <call-class-method class-name="org.apache.ofbiz.content.content.ContentKeywordIndex" method-name="forceIndexKeywords">
             <field field="content" type="org.apache.ofbiz.entity.GenericValue"/>
         </call-class-method>
     </simple-method>
-    
     <simple-method method-name="deleteContentKeywords" short-description="delete all the keywords of a content">
         <entity-one entity-name="Content" value-field="content"/>
         <remove-related value-field="content" relation-name="ContentKeyword"/>
     </simple-method>
-
     <simple-method method-name="indexContentKeywords" short-description="Index the Keywords for a Content" login-required="false">
         <!-- this service is meant to be called from an entity ECA for entities that include a contentId -->
         <!-- if it is the Content entity itself triggering this action, then a [contentInstance] parameter
diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml
index bb2a3ed..3d32a82 100644
--- a/applications/content/servicedef/services.xml
+++ b/applications/content/servicedef/services.xml
@@ -40,8 +40,8 @@
         <attribute mode="OUT" name="resultData" optional="true" type="java.util.Map"/>
     </service>
 
-    <service name="getContentAndDataResource" engine="simple" default-entity-name="Content" auth="true"
-            location="component://content/minilang/content/ContentServices.xml" invoke="getContentAndDataResource">
+    <service name="getContentAndDataResource" engine="groovy" default-entity-name="Content" auth="true"
+            location="component://content/groovyScripts/content/ContentServices.groovy" invoke="getContentAndDataResource">
         <description>Get Content and resource information</description>
         <permission-service service-name="genericContentPermission" main-action="VIEW"/>
         <auto-attributes include="pk" mode="IN" optional="false"/>