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

mridulpathak 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 f9a05c8  Improved: Convert setContentStatus service from mini-lang to 
groovy DSL(OFBIZ-11365). Thanks Devanshu Vyas for the contribution.
     new dc5f8a6  Merge branch 'trunk' of 
https://gitbox.apache.org/repos/asf/ofbiz-framework into trunk
f9a05c8 is described below

commit f9a05c8e30f5f7f593e53a6591b990b2760ffbd1
Author: Mridul Pathak <mridulpat...@apache.org>
AuthorDate: Sat May 23 18:12:13 2020 +0530

    Improved: Convert setContentStatus service from mini-lang to groovy 
DSL(OFBIZ-11365). Thanks Devanshu Vyas for the contribution.
---
 .../groovyScripts/content/ContentServices.groovy   | 22 ++++++++++++++++++
 .../content/minilang/content/ContentServices.xml   | 26 ----------------------
 .../content/servicedef/services_content.xml        |  4 ++--
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/applications/content/groovyScripts/content/ContentServices.groovy 
b/applications/content/groovyScripts/content/ContentServices.groovy
index 4ecc039..fef62e4 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -319,3 +319,25 @@ def createArticleContent() {
     result.contentId = contentId
     return result
 }
+
+def setContentStatus() {
+    Map resultMap = new HashMap()
+    content = from("Content").where("contentId", 
parameters.contentId).queryOne()
+    if (content) {
+        oldStatusId = content.statusId
+        resultMap.oldStatusId = oldStatusId
+        if (!oldStatusId.equals(parameters.statusId)) {
+            statusChange = from("StatusValidChange").where("statusId", 
oldStatusId, "statusIdTo", parameters.statusId).queryOne()
+            if (statusChange) {
+                content.put("statusId", parameters.statusId)
+                content.store()
+            } else {
+                resultMap.errorMessage = "Cannot change from " + oldStatusId + 
" to " + parameters.statusId
+                logError(resultMap.errorMessage)
+            }
+        }
+    } else {
+        return failure("No Content is not available in the system with content 
ID - " + parameters.contentId)
+    }
+    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 b8e451b..d920e1d 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -46,32 +46,6 @@
         </if-not-empty>
     </simple-method>
 
-    <!-- update content; just status -->
-    <simple-method method-name="setContentStatus" short-description="Set The 
Content Status">
-
-        <entity-one entity-name="Content" value-field="content"/>
-        <field-to-result field="content.statusId" result-name="oldStatusId"/>
-
-       <if-compare-field field="content.statusId" 
to-field="parameters.statusId" operator="not-equals">
-            <entity-one entity-name="StatusValidChange" 
value-field="statusChange" auto-field-map="false">
-                <field-map field-name="statusId" 
from-field="content.statusId"/>
-                <field-map field-name="statusIdTo" 
from-field="parameters.statusId"/>
-            </entity-one>
-
-            <if-empty field="statusChange">
-                <add-error>
-                    <fail-property resource="ContentUiLabels" 
property="ContentCannotChangeStatus"/>
-                </add-error>
-                <log level="error" message="Cannot change from 
${content.statusId} to ${parameters.statusId}"/>
-                <check-errors/>
-                <else>
-                    <set from-field="parameters.statusId" 
field="content.statusId"/>
-                    <store-value value-field="content"/>
-                </else>
-            </if-empty>
-        </if-compare-field>
-    </simple-method>
-
     <simple-method method-name="copyContentAndElectronicTextandAssoc" 
short-description="copy a content, electronic text and assocs and set status in 
progress">
         <set-service-fields service-name="getContent" map="parameters" 
to-map="getC"/>
         <call-service service-name="getContent" in-map-name="getC">
diff --git a/applications/content/servicedef/services_content.xml 
b/applications/content/servicedef/services_content.xml
index ee931fa..a85b902 100644
--- a/applications/content/servicedef/services_content.xml
+++ b/applications/content/servicedef/services_content.xml
@@ -288,8 +288,8 @@
     </service>
 
     <!-- content status services -->
-    <service name="setContentStatus" engine="simple" auth="true"
-            
location="component://content/minilang/content/ContentServices.xml" 
invoke="setContentStatus">
+    <service name="setContentStatus" engine="groovy" auth="true"
+            
location="component://content/groovyScripts/content/ContentServices.groovy" 
invoke="setContentStatus">
         <description>Set the Content Status</description>
         <permission-service service-name="genericContentPermission" 
main-action="UPDATE"/>
         <attribute name="contentId" type="String" mode="IN" optional="false">

Reply via email to