You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2020/03/06 13:58:32 UTC

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

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 27aa238  Improved: Convert createTextAndUploadedContent service from mini-lang to groovy DSL (OFBIZ-11368)
27aa238 is described below

commit 27aa23833ce1bf4bff541426938eb6680b1722f2
Author: Nicolas Malin <ni...@nereide.fr>
AuthorDate: Fri Mar 6 14:58:15 2020 +0100

    Improved: Convert createTextAndUploadedContent service from mini-lang to groovy DSL
    (OFBIZ-11368)
    
    Thanks to Rohit Hukkeri for providing the patch
---
 .../groovyScripts/content/ContentServices.groovy   | 41 ++++++++++++++++++++++
 .../content/minilang/content/ContentServices.xml   | 22 ------------
 .../content/servicedef/services_content.xml        |  4 +--
 3 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy
new file mode 100644
index 0000000..1ad1374
--- /dev/null
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+import org.apache.ofbiz.service.ModelService
+
+def createTextAndUploadedContent(){
+    Map result = success()
+
+    Map serviceResult = run service: 'createContent', with: parameters
+    parameters.parentContentId = serviceResult.contentId
+
+    if (parameters.uploadedFile) {
+        logInfo('Uploaded file found; processing sub-content')
+        Map uploadContext = dispatcher.getDispatchContext()
+                .makeValidContext('createContentFromUploadedFile', ModelService.IN_PARAM, parameters)
+        uploadContext.ownerContentId = parameters.parentContentId
+        uploadContext.contentIdFrom = parameters.parentContentId
+        uploadContext.contentAssocTypeId = 'SUB_CONTENT'
+        uploadContext.contentPurposeTypeId = 'SECTION'
+        run service: 'createContentFromUploadedFile', with: uploadContext
+    }
+
+    result.contentId = parameters.parentContentId
+    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 4adf1bb..ad08f90 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -183,28 +183,6 @@
         <call-service service-name="createContentPurpose" in-map-name="parameters"/>
     </simple-method>
 
-    <!-- combined text + uploaded file service -->
-    <simple-method method-name="createTextAndUploadedContent" short-description="Creates Text and Optionally Uploaded (sub) Content records">
-        <set-service-fields service-name="createTextContent" map="parameters" to-map="textContext"/>
-        <call-service service-name="createTextContent" in-map-name="textContext">
-            <result-to-field result-name="contentId" field="parameters.parentContentId"/>
-        </call-service>
-
-        <log level="info" message="${parameters}"/>
-
-        <if-not-empty field="parameters.uploadedFile">
-            <log level="info" message="Uploaded file found; processing sub-content"/>
-            <set-service-fields service-name="createContentFromUploadedFile" map="parameters" to-map="uploadContext"/>
-            <set field="uploadContext.ownerContentId" from-field="parameters.parentContentId"/>
-            <set field="uploadContext.contentIdFrom" from-field="parameters.parentContentId"/>
-            <set field="uploadContext.contentAssocTypeId" value="SUB_CONTENT"/>
-            <set field="uploadContext.contentPurposeTypeId" value="SECTION"/>
-            <call-service service-name="createContentFromUploadedFile" in-map-name="uploadContext"/>
-        </if-not-empty>
-
-        <field-to-result field="parameters.parentContentId" result-name="contentId"/>
-    </simple-method>
-
     <!-- Util -->
     <simple-method method-name="findAssocContent" short-description="Find associated content">
         <set from-field="parameters.contentId" field="queryMap.contentId"/>
diff --git a/applications/content/servicedef/services_content.xml b/applications/content/servicedef/services_content.xml
index ea0d701..87be490 100644
--- a/applications/content/servicedef/services_content.xml
+++ b/applications/content/servicedef/services_content.xml
@@ -46,8 +46,8 @@
         <override name="description" allow-html="safe"/>
     </service>
 
-    <service name="createTextAndUploadedContent" engine="simple" auth="true"
-            location="component://content/minilang/content/ContentServices.xml" invoke="createTextAndUploadedContent">
+    <service name="createTextAndUploadedContent" engine="groovy" auth="true"
+            location="component://content/groovyScripts/content/ContentServices.groovy" invoke="createTextAndUploadedContent">
         <description>Creates text content and optional uploaded sub-content</description>
         <implements service="createTextContent"/>
         <implements service="uploadFileInterface" optional="true"/>