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

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

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 7799673  Improved: Convert createEmailContent service from mini-lang to groovy DSL(OFBIZ-11370)
7799673 is described below

commit 7799673fa3e7aa9a1d5bc542c7e7a43fc2d93f20
Author: Pawan Verma <[hidden email]>
AuthorDate: Sat Jul 18 22:25:55 2020 +0530

    Improved: Convert createEmailContent service from mini-lang to groovy DSL(OFBIZ-11370)
   
    Thanks, Devanshu for the report and Rohit for initial patch and Nicolas for updated patch and review.
---
 .../groovyScripts/content/ContentServices.groovy   | 37 ++++++++++++++++++++
 .../content/minilang/content/ContentServices.xml   | 39 ----------------------
 applications/content/servicedef/services.xml       |  2 +-
 3 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy
index ed39c78..75e2d8f 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -51,6 +51,43 @@ def createTextAndUploadedContent(){
     result.contentId = parameters.parentContentId
     return result
 }
+
+def createEmailContent() {
+    Map result = success()
+    Map createContentMap = dispatcher.getDispatchContext()
+            .makeValidContext('createContent', ModelService.IN_PARAM, parameters)
+
+    //Create subject
+    Map serviceResult = run service: 'createElectronicText', with: [textData: parameters.subject]
+    createContentMap.dataResourceId = serviceResult.dataResourceId
+    serviceResult = run service: 'createContent', with: createContentMap
+
+    //Create plain body and assoc with subject
+    Map createBodyAssoc = [contentId: serviceResult.contentId,
+                           contentAssocTypeId: 'TREE_CHILD',
+                           mapKey: 'plainBody']
+
+    serviceResult = run service: 'createElectronicText', with: [textData: parameters.plainBody]
+    createContentMap.dataResourceId = serviceResult.dataResourceId
+    serviceResult = run service: 'createContent', with: createContentMap
+
+    createBodyAssoc.contentIdTo = serviceResult.contentId
+
+    run service: 'createContentAssoc', with: createBodyAssoc
+    result.contentId = createBodyAssoc.contentId
+
+    if (parameters.htmlBody) {
+        serviceResult = run service: 'createElectronicText', with: [textData: parameters.htmlBody]
+        createContentMap.dataResourceId = serviceResult.dataResourceId
+        serviceResult = run service: 'createContent', with: createContentMap
+        createBodyAssoc.contentIdTo = serviceResult.contentId
+        createBodyAssoc.mapKey = 'htmlBody'
+        run service: 'createContentAssoc', with: createBodyAssoc
+    }
+
+    return result
+}
+
 def deactivateAllContentRoles() {
     List contentRoles = from("ContentRole").
             where("contentId", parameters.contentId, "partyId", parameters.partyId, "roleTypeId", parameters.roleTypeId)
diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml
index 285e6ad..61e528f 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -170,45 +170,6 @@
         </if>
     </simple-method>
 
-    <!-- Generic content services -->
-    <simple-method method-name="createEmailContent" short-description="Create Email as Content">
-        <!-- Create subject -->
-        <set-service-fields service-name="createContent" map="parameters" to-map="createSubjectContent"/>
-        <set from-field="parameters.subject" field="createSubjectEtext.textData"/>
-        <call-service service-name="createElectronicText" in-map-name="createSubjectEtext">
-            <result-to-field result-name="dataResourceId" field="createSubjectContent.dataResourceId"/>
-        </call-service>
-        <call-service service-name="createContent" in-map-name="createSubjectContent">
-            <result-to-field result-name="contentId" field="createBodyAssoc.contentId"/>
-        </call-service>
-
-        <!-- Create plain body -->
-        <set from-field="parameters.plainBody" field="createPlainBodyEtext.textData"/>
-        <call-service service-name="createElectronicText" in-map-name="createPlainBodyEtext">
-            <result-to-field result-name="dataResourceId" field="createPlainBodyContent.dataResourceId"/>
-        </call-service>
-        <call-service service-name="createContent" in-map-name="createPlainBodyContent">
-            <result-to-field result-name="contentId" field="createBodyAssoc.contentIdTo"/>
-        </call-service>
-        <!-- Create content assoc between subject and plain body -->
-        <set value="TREE_CHILD" field="createBodyAssoc.contentAssocTypeId"/>
-        <set value="plainBody" field="createBodyAssoc.mapKey"/>
-        <call-service service-name="createContentAssoc" in-map-name="createBodyAssoc"/>
-
-        <!-- Create HTML body -->
-        <set from-field="parameters.htmlBody" field="createHtmlBodyEtext.textData"/>
-        <call-service service-name="createElectronicText" in-map-name="createHtmlBodyEtext">
-            <result-to-field result-name="dataResourceId" field="createHtmlBodyContent.dataResourceId"/>
-        </call-service>
-        <call-service service-name="createContent" in-map-name="createHtmlBodyContent">
-            <result-to-field result-name="contentId" field="createBodyAssoc.contentIdTo"/>
-        </call-service>
-        <!-- Create content assoc between subject and html body -->
-        <set value="htmlBody" field="createBodyAssoc.mapKey"/>
-        <call-service service-name="createContentAssoc" in-map-name="createBodyAssoc"/>
-
-        <field-to-result field="createBodyAssoc.contentId" result-name="contentId"/>
-    </simple-method>
     <simple-method method-name="createSimpleTextContent" short-description="Create Simple Text Content">
         <set-service-fields service-name="createContent" map="parameters" to-map="createSimpleTextContent"/>
         <set value="DOCUMENT" field="createSimpleTextContent.contentTypeId"/>
diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml
index 3d32a82..925bcca 100644
--- a/applications/content/servicedef/services.xml
+++ b/applications/content/servicedef/services.xml
@@ -117,7 +117,7 @@
     </service>
 
     <!-- Generic Content Services -->
-    <service name="createEmailContent" engine="simple" location="component://content/minilang/content/ContentServices.xml" invoke="createEmailContent">
+    <service name="createEmailContent" engine="groovy" location="component://content/groovyScripts/content/ContentServices.groovy" invoke="createEmailContent">
         <permission-service service-name="contentManagerPermission" main-action="CREATE"/>
         <auto-attributes mode="IN" entity-name="Content" optional="true"/>
         <attribute name="subject" type="String" mode="IN" optional="false">