You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/05/18 11:25:27 UTC
[ofbiz-framework] 02/02: Improved: Convert
deactivateAllContentRoles service from mini-lang to groovy DSL
This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 11905d82f5aa6fb06894e82b1ff83538ee15845d
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Mon May 18 13:25:35 2020 +0200
Improved: Convert deactivateAllContentRoles service from mini-lang to groovy DSL
(OFBIZ-11366)
jleroux: I had to slightly rewrite the patch, mostly the Groovy part (see
comment in Jira)
Thanks: Devanshu Vyas for the initial patch
---
.../groovyScripts/content/ContentServices.groovy | 20 +++++++++++++++++++-
.../content/minilang/content/ContentServices.xml | 13 -------------
applications/content/servicedef/services_content.xml | 4 ++--
3 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy
index d860b19..4ecc039 100644
--- a/applications/content/groovyScripts/content/ContentServices.groovy
+++ b/applications/content/groovyScripts/content/ContentServices.groovy
@@ -17,14 +17,19 @@
* under the License.
*/
-import org.apache.ofbiz.base.util.Debug
+import java.sql.Timestamp
+
import org.apache.ofbiz.common.UrlServletHelper
import org.apache.ofbiz.entity.condition.EntityCondition
import org.apache.ofbiz.entity.condition.EntityOperator
+import org.apache.ofbiz.entity.GenericValue
import org.apache.ofbiz.entity.util.EntityListIterator
import org.apache.ofbiz.service.GenericServiceException;
+
import org.apache.ofbiz.service.ModelService
import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.base.util.Debug
+import org.apache.ofbiz.base.util.UtilDateTime
MODULE = "ContentServices.groovy"
def createTextAndUploadedContent(){
@@ -48,6 +53,19 @@ def createTextAndUploadedContent(){
return result
}
+def deactivateAllContentRoles() {
+ List contentRoles = from("ContentRole").
+ where("contentId", parameters.contentId, "partyId", parameters.partyId, "roleTypeId", parameters.roleTypeId)
+ .queryList();
+ if (contentRoles) {
+ for (GenericValue contentRole : contentRoles) {
+ contentRole.put("thruDate", UtilDateTime.nowTimestamp());
+ contentRole.store();
+ }
+ }
+ return success()
+}
+
def createContentAlternativeUrl() {
//create Content Alternative URLs.
String contentCreated
diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml
index 696d7ee..b8e451b 100644
--- a/applications/content/minilang/content/ContentServices.xml
+++ b/applications/content/minilang/content/ContentServices.xml
@@ -164,19 +164,6 @@
<!-- Methods for ContentRole -->
- <simple-method method-name="deactivateAllContentRoles" short-description="Update Content Role">
- <make-value entity-name="ContentRole" value-field="lookupKeyValue"/>
- <set from-field="parameters.contentId" field="lookupKeyValue.contentId"/>
- <set from-field="parameters.partyId" field="lookupKeyValue.partyId"/>
- <set from-field="parameters.roleTypeId" field="lookupKeyValue.roleTypeId"/>
- <find-by-and entity-name="ContentRole" map="lookupKeyValue" list="roleList"/>
- <iterate list="roleList" entry="contentRoleMap">
- <make-value entity-name="ContentRole" value-field="role" map="contentRoleMap"/>
- <now-timestamp field="role.thruDate"/>
- <store-value value-field="role"/>
- </iterate>
- </simple-method>
-
<simple-method method-name="updateSingleContentPurpose" short-description="Updates the purpose making sure there is only one">
<set field="toRemove.contentId" from-field="parameters.contentId"/>
<remove-by-and entity-name="ContentPurpose" map="toRemove"/>
diff --git a/applications/content/servicedef/services_content.xml b/applications/content/servicedef/services_content.xml
index 87be490..ee931fa 100644
--- a/applications/content/servicedef/services_content.xml
+++ b/applications/content/servicedef/services_content.xml
@@ -319,8 +319,8 @@
<auto-attributes include="pk" mode="IN" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
</service>
- <service name="deactivateAllContentRoles" engine="simple" default-entity-name="ContentRole" auth="true"
- location="component://content/minilang/content/ContentServices.xml" invoke="deactivateAllContentRoles">
+ <service name="deactivateAllContentRoles" engine="groovy" default-entity-name="ContentRole" auth="true"
+ location="component://content/groovyScripts/content/ContentServices.groovy" invoke="deactivateAllContentRoles">
<description>Deactivate all ContentRoles</description>
<permission-service service-name="genericContentPermission" main-action="UPDATE"/>
<attribute mode="IN" name="contentId" optional="false" type="String">