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
commit 46d53b513eb455f453950db221d45e9023a0b04c Author: Nicolas Malin <[email protected]> AuthorDate: Tue Sep 14 14:24:22 2021 +0200 Improved: Convert findAssocContent service from mini-lang to groovy DSL (OFBIZ-11369) Thanks to Prakhar Kumar --- .../groovyScripts/content/ContentServices.groovy | 17 ++++++++++++++ .../content/minilang/content/ContentServices.xml | 26 ---------------------- applications/content/servicedef/services.xml | 17 ++++---------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy index 7d33c96..c689bd3 100644 --- a/applications/content/groovyScripts/content/ContentServices.groovy +++ b/applications/content/groovyScripts/content/ContentServices.groovy @@ -28,6 +28,7 @@ import org.apache.ofbiz.entity.condition.EntityOperator import org.apache.ofbiz.entity.util.EntityListIterator import org.apache.ofbiz.service.GenericServiceException +import org.apache.ofbiz.entity.condition.EntityConditionBuilder import org.apache.ofbiz.service.ModelService import org.apache.ofbiz.service.ServiceUtil import org.apache.ofbiz.base.util.UtilDateTime @@ -52,6 +53,22 @@ def createTextAndUploadedContent() { return result } +def findAssocContent() { + EntityCondition condition = new EntityConditionBuilder().AND() { + EQUALS(contentId: parameters.contentId) + IN(mapKey: parameters.mapKeys) + } + List contentAssocs = from("ContentAssoc") + .where(condition) + .filterByDate() + .cache() + .queryList() + + Map result = success() + if (contentAssocs) result.contentAssocs = contentAssocs + return result +} + def updateSingleContentPurpose() { delegator.removeByAnd("ContentPurpose", [contentId: parameters.contentId]) run service : "createContentPurpose", with: parameters diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml index 6ae3e1d..2aef8a1 100644 --- a/applications/content/minilang/content/ContentServices.xml +++ b/applications/content/minilang/content/ContentServices.xml @@ -136,32 +136,6 @@ <check-errors/> </simple-method> - <!-- Util --> - <simple-method method-name="findAssocContent" short-description="Find associated content"> - <set from-field="parameters.contentId" field="queryMap.contentId"/> - <set field="mapKeys" from-field="parameters.mapKeys"/> - <field-to-list field="mapKey" list="mapKeys"/> - <iterate list="mapKeys" entry="mapKey"> - <set from-field="mapKey" field="queryMap.mapKey"/> - <find-by-and list="resultMap" entity-name="ContentAssoc" map="queryMap"/> - <filter-list-by-date list="resultMap" to-list="validContent"/> - <iterate list="validContent" entry="contentAssoc"> - <field-to-list field="contentAssoc" list="result"/> - </iterate> - </iterate> - <if> - <condition> - <if-empty field="parameters.mapKey"/> - </condition> - <then> - <field-to-result field="result" result-name="contentAssocs"/> - </then> - <else> - <field-to-result field="result" result-name="contentAssoc"/> - </else> - </if> - </simple-method> - <simple-method method-name="updateSimpleTextContent" short-description="Update Simple Text Content"> <if-not-empty field="parameters.textDataResourceId"> <set from-field="parameters.textDataResourceId" field="updateSimpleText.dataResourceId"/> diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml index 37b44e7..40c8775 100644 --- a/applications/content/servicedef/services.xml +++ b/applications/content/servicedef/services.xml @@ -176,19 +176,10 @@ </service> <!-- Util --> - <service name="findAssocContent" engine="simple" - location="component://content/minilang/content/ContentServices.xml" invoke="findAssocContent" auth="true"> - <attribute name="contentId" type="String" mode="IN" optional="false"> - <type-validate> - <fail-property resource="ContentErrorUiLabels" property="ContentRequiredFieldMissingContentId"/> - </type-validate> - </attribute> - <attribute name="mapKeys" type="List" mode="IN" optional="false"> - <type-validate> - <fail-property resource="ContentErrorUiLabels" property="ContentRequiredFieldMissingMapKeys"/> - </type-validate> - </attribute> - <attribute name="contentAssocs" type="List" mode="OUT" optional="true"/> + <service name="findAssocContent" engine="groovy" location="component://content/groovyScripts/content/ContentServices.groovy" invoke="findAssocContent" auth="true"> + <attribute name="contentId" mode="IN" type="String" optional="false"/> + <attribute name="mapKeys" mode="IN" type="List" optional="false"/> + <attribute name="contentAssocs" mode="OUT" type="List" optional="true"/> </service> <!-- Complex Contentservices -->

