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 73ab86737a4d527cfa24b07fb3d9517de7a79254 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Thu Jun 1 19:26:36 2023 +0200 Improved: Convert createCommContentDataResource service from mini-lang to groovy DSL (OFBIZ-11378) Thanks to Devanshu Vyas for the patch --- .../groovyScripts/content/ContentServices.groovy | 33 ++++++++++++++++++++-- .../content/servicedef/services_commevent.xml | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy index 9fa1c46283..65e5808c71 100644 --- a/applications/content/groovyScripts/content/ContentServices.groovy +++ b/applications/content/groovyScripts/content/ContentServices.groovy @@ -150,8 +150,7 @@ Map createContentAlternativeUrl() { .queryIterator() GenericValue content - while (contents.hasNext()) { - content = contents.next() + while (content = contents.next()) { String localeString = content.localeString ?: defaultLocaleString List contentAssocDataResources = select('contentIdStart', 'dataResourceId', 'localeString', 'drObjectInfo', 'caFromDate', 'caThruDate') .from('ContentAssocDataResourceViewTo') @@ -637,4 +636,34 @@ List createMissingContentAltUrlInline(String contentId) { contentCreatedList.addAll(createMissingContentAltUrlInline(contentIdTo)) } return contentCreatedList +} + +/** + * This method first creates Content, DataResource and ElectronicText, ImageDataResource, etc. entities (if needed) + * by calling persistContentAndAssoc. + * + * It then takes the contentId coming out of that service, the passed in communicationEventId + * and calls the "createCommEventContentAssoc" service to tie the CommunicationEvent and Content entities together. + */ +Map createCommContentDataResource() { + + // let's take a guess at what the dataResourceTypeId should be if it is empty + if (!parameters.dataResourceTypeId && parameters.drMimeTypeId) { + parameters.dataResourceTypeId = parameters.drMimeTypeId.startsWith('text') ? + 'ELECTRONIC_TEXT' : 'IMAGE_OBJECT' + } + Map persistServiceResult = run service: 'persistContentAndAssoc', with: parameters + Map serviceResult = run service: 'createCommEventContentAssoc', with: [contentId: persistServiceResult.contentId, + communicationEventId: parameters.communicationEventId, + sequenceNum: parameters.sequenceNum] + return success([contentId: persistServiceResult.contentId, + dataResourceId: persistServiceResult.dataResourceId, + drDataResourceId: persistServiceResult.drDataResourceId, + caContentIdTo: persistServiceResult.caContentIdTo, + caContentId: persistServiceResult.caContentId, + caContentAssocTypeId: persistServiceResult.caContentAssocTypeId, + caFromDate: persistServiceResult.caFromDate, + caSequenceNum: persistServiceResult.caSequenceNum, + roleTypeList: persistServiceResult.roleTypeList, + fromDate: serviceResult.fromDate]) } \ No newline at end of file diff --git a/applications/content/servicedef/services_commevent.xml b/applications/content/servicedef/services_commevent.xml index 3e0f36645f..d44a226b1f 100644 --- a/applications/content/servicedef/services_commevent.xml +++ b/applications/content/servicedef/services_commevent.xml @@ -35,8 +35,8 @@ under the License. Second, it must create a CommEventContentAssoc record. The fromData should be defaulted if not passed in. --> - <service name="createCommContentDataResource" engine="simple" - location="component://content/minilang/content/ContentServices.xml" invoke="createCommContentDataResource" auth="true"> + <service name="createCommContentDataResource" engine="groovy" + location="component://content/groovyScripts/content/ContentServices.groovy" invoke="createCommContentDataResource"> <description>Create CommunicationEvent and Content</description> <implements service="persistContentAndAssoc"/> <attribute name="communicationEventId" type="String" mode="IN" optional="false">