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 9223d40 Improved: Converted createContentFromDataResource service
from mini-lang to groovy DSL. (OFBIZ-11377) Thanks Devanshu Vyas for reporting
and Anushi Gupta for the patch.
9223d40 is described below
commit 9223d402042e2ed3c10f139dcbf4709f45da8a87
Author: Suraj Khurana <[email protected]>
AuthorDate: Sat Jul 4 14:53:12 2020 +0530
Improved: Converted createContentFromDataResource service from mini-lang to
groovy DSL.
(OFBIZ-11377)
Thanks Devanshu Vyas for reporting and Anushi Gupta for the patch.
---
.../groovyScripts/content/ContentServices.groovy | 23 ++++++++++++++
.../content/minilang/content/ContentServices.xml | 37 ----------------------
.../content/servicedef/services_content.xml | 4 +--
3 files changed, 25 insertions(+), 39 deletions(-)
diff --git a/applications/content/groovyScripts/content/ContentServices.groovy
b/applications/content/groovyScripts/content/ContentServices.groovy
index 66f3403..c752752 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -385,4 +385,27 @@ def getContentAndDataResource () {
}
resultMap.resultData = resultDataContent;
return resultMap;
+}
+/* create content from data resource */
+/*This method will create a skeleton content record from a data resource */
+def createContentFromDataResource() {
+ dataResource = from("DataResource").where("dataResourceId",
parameters.dataResourceId).queryOne()
+ if (dataResource == null) {
+ return error(UtilProperties.getMessage("ContentUiLabels",
"ContentDataResourceNotFound", UtilMisc.toMap("parameters.dataResourceId",
parameters.dataResourceId), parameters.locale))
+ }
+ Map createContentMap =
dispatcher.getDispatchContext().makeValidContext('createContent',
ModelService.IN_PARAM, parameters)
+ if (!(createContentMap.contentName)) {
+ createContentMap.contentName = dataResource.dataResourceName
+ }
+ if (!(createContentMap.contentTypeId)) {
+ createContentMap.contentTypeId = "DOCUMENT"
+ }
+ if (!(createContentMap.statusId)) {
+ createContentMap.statusId = "CTNT_INITIAL_DRAFT"
+ }
+ if (!(createContentMap.mimeTypeId)) {
+ createContentMap.mimeTypeId = dataResource.mimeTypeId
+ }
+ Map result = run service: "createContent", with: createContentMap
+ 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 1d495f7..a62139d 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -238,43 +238,6 @@
</if-not-empty>
</simple-method>
- <!-- This method will create a skeleton content record from a data
resource -->
- <simple-method method-name="createContentFromDataResource"
short-description="Create Content from DataResource Object">
- <entity-one entity-name="DataResource" value-field="dataResource">
- <field-map field-name="dataResourceId"
from-field="parameters.dataResourceId"/>
- </entity-one>
- <if-empty field="dataResource">
- <add-error>
- <fail-property resource="ContentUiLabels"
property="ContentDataResourceNotFound"/>
- </add-error>
- </if-empty>
- <check-errors/>
-
- <set-service-fields service-name="createContent" map="parameters"
to-map="createContentMap"/>
-
- <if-empty field="createContentMap.contentName">
- <set field="createContentMap.contentName"
from-field="dataResource.dataResourceName"/>
- </if-empty>
-
- <if-empty field="createContentMap.contentTypeId">
- <set field="createContentMap.contentTypeId" value="DOCUMENT"/>
- </if-empty>
-
- <if-empty field="createContentMap.statusId">
- <set field="createContentMap.statusId" value="CTNT_INITIAL_DRAFT"/>
- </if-empty>
-
- <if-empty field="createContentMap.mimeTypeId">
- <set from-field="dataResource.mimeTypeId"
field="createContentMap.mimeTypeId"/>
- </if-empty>
-
- <call-service service-name="createContent"
in-map-name="createContentMap" break-on-error="false">
- <result-to-field result-name="contentId" field="contentId"/>
- </call-service>
-
- <field-to-result field="contentId"/>
- </simple-method>
-
<!-- This method first creates Content, DataResource and ElectronicText,
ImageDataResource, etc. entities (if needed)
by calling persistContentAndAssoc.
diff --git a/applications/content/servicedef/services_content.xml
b/applications/content/servicedef/services_content.xml
index a85b902..d0bc6c3 100644
--- a/applications/content/servicedef/services_content.xml
+++ b/applications/content/servicedef/services_content.xml
@@ -63,8 +63,8 @@
</group>
</service>
- <service name="createContentFromDataResource" engine="simple"
-
location="component://content/minilang/content/ContentServices.xml"
invoke="createContentFromDataResource">
+ <service name="createContentFromDataResource" engine="groovy"
+
location="component://content/groovyScripts/content/ContentServices.groovy"
invoke="createContentFromDataResource">
<description>Creates content record from data resource and allows all
content fields to be set</description>
<!-- uses createContent internally; additonal permission(s) not
necessary -->
<implements service="createContent" optional="true"/>