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 The following commit(s) were added to refs/heads/trunk by this push: new 200c0e8 Implemented: Convert createContentAlternativeUrl service from mini-lang to Groovy 200c0e8 is described below commit 200c0e85fcc392131cb01e7685f87618259c2d22 Author: Jacques Le Roux <[hidden email]> AuthorDate: Sun Apr 19 09:48:14 2020 +0200 Implemented: Convert createContentAlternativeUrl service from mini-lang to Groovy (OFBIZ-11389) Thanks: Priya Sharma for patch and Pawan Verma for review --- .../groovyScripts/content/ContentServices.groovy | 123 +++++++++++++++++++++ .../content/minilang/content/ContentServices.xml | 112 ------------------- applications/content/servicedef/services.xml | 4 +- 3 files changed, 125 insertions(+), 114 deletions(-) diff --git a/applications/content/groovyScripts/content/ContentServices.groovy b/applications/content/groovyScripts/content/ContentServices.groovy index 1ad1374..71408a3 100644 --- a/applications/content/groovyScripts/content/ContentServices.groovy +++ b/applications/content/groovyScripts/content/ContentServices.groovy @@ -17,8 +17,16 @@ * under the License. */ +import org.apache.ofbiz.base.util.Debug +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.util.EntityListIterator +import org.apache.ofbiz.service.GenericServiceException; import org.apache.ofbiz.service.ModelService +import org.apache.ofbiz.service.ServiceUtil +MODULE = "ContentServices.groovy" def createTextAndUploadedContent(){ Map result = success() @@ -38,4 +46,119 @@ def createTextAndUploadedContent(){ result.contentId = parameters.parentContentId return result +} + +def createContentAlternativeUrl() { + //create Content Alternative URLs. + String contentCreated + Map serviceResult = [:] + Map serviceContext = [:] + defaultLocaleString = parameters.locale ?: "en" + EntityListIterator contents + + if (parameters.contentId) { + entryExprs = EntityCondition.makeCondition([ + EntityCondition.makeCondition("contentName", EntityOperator.NOT_EQUAL, null), + EntityCondition.makeCondition("contentId", EntityOperator.EQUALS, parameters.contentId), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("contentTypeId", EntityOperator.EQUALS, "DOCUMENT"), + EntityCondition.makeCondition("contentTypeId", EntityOperator.EQUALS, "WEB_SITE_PUB_PT")], EntityOperator.OR) + ], EntityOperator.AND) + } else { + entryExprs = EntityCondition.makeCondition([ + EntityCondition.makeCondition("contentName", EntityOperator.NOT_EQUAL, null), + EntityCondition.makeCondition([ + EntityCondition.makeCondition("contentTypeId", EntityOperator.EQUALS, "DOCUMENT"), + EntityCondition.makeCondition("contentTypeId", EntityOperator.EQUALS, "WEB_SITE_PUB_PT")], EntityOperator.OR) + ], EntityOperator.AND) + } + + contents = select("contentId", "contentName", "localeString").from("Content").where(entryExprs).queryIterator() + List contentAssocDataResources = [] + String localeString + + while (content = contents.next()) { + localeString = content.localeString ?: defaultLocaleString + contentAssocDataResources = select("contentIdStart", "dataResourceId", "localeString", "drObjectInfo", "caFromDate", "caThruDate").from("ContentAssocDataResourceViewTo"). + where("caContentAssocTypeId", "ALTERNATIVE_URL", "contentIdStart", content.contentId, "localeString", localeString.toString()).filterByDate("caFromDate", "caThruDate").queryList() + if (!contentAssocDataResources) { + if (content.contentName) { + uri = UrlServletHelper.invalidCharacter(content.contentName) + if (uri) { + serviceContext.dataResourceId = delegator.getNextSeqId("DataResource") + serviceContext.dataResourceTypeId = "URL_RESOURCE" + serviceContext.localeString = localeString.toString() + serviceContext.objectInfo = uri + "-" + content.contentId + "-content" + serviceContext.statusId = "CTNT_IN_PROGRESS" + serviceContext.userLogin = userLogin + try { + serviceResult = run service: "createDataResource", with: serviceContext + if (ServiceUtil.isSuccess(serviceResult)) { + dataResourceId = serviceResult.dataResourceId + } + } catch (GenericServiceException e) { + Debug.logInfo(e, MODULE) + } + if (dataResourceId) { + serviceContext.clear() + serviceContext.dataResourceId = dataResourceId + serviceContext.statusId = "CTNT_IN_PROGRESS" + serviceContext.localeString = localeString.toString() + serviceContext.userLogin = userLogin + try { + serviceResult = run service: "createContent", with: serviceContext + if (ServiceUtil.isSuccess(serviceResult)) { + contentIdTo = serviceResult.contentId + } + } catch (GenericServiceException e) { + Debug.logInfo(e, MODULE) + } + if (contentIdTo) { + serviceContext.clear() + serviceContext.contentId = content.contentId + serviceContext.contentIdTo = contentIdTo + serviceContext.contentAssocTypeId = "ALTERNATIVE_URL" + serviceContext.userLogin = userLogin + try { + serviceResult = run service: "createContentAssoc", with: serviceContext + if (ServiceUtil.isSuccess(serviceResult)) { + contentIdTo = serviceResult.contentId + } + } catch (GenericServiceException e) { + Debug.logInfo(e, MODULE) + } + } + } + contentCreated = "Y" + } + } + } else { + if (contentAssocDataResources && contentAssocDataResources.get(0).drObjectInfo) { + if (content.contentName) { + uri = UrlServletHelper.invalidCharacter(content.contentName) + if (uri) { + serviceContext.clear() + serviceContext.dataResourceId = contentAssocDataResources.get(0).dataResourceId + serviceContext.objectInfo = "/" + uri + "-" + content.contentId + "-content" + serviceContext.userLogin = userLogin + try { + serviceResult = run service: "updateDataResource", with: serviceContext + if (ServiceUtil.isSuccess(serviceResult)) { + contentIdTo = serviceResult.contentId + } + } catch (GenericServiceException e) { + Debug.logInfo(e, MODULE) + } + contentCreated = "Y" + } + } + } else { + contentCreated = "N" + } + } + } + + map = success() + map.contentCreated = contentCreated + return map } \ No newline at end of file diff --git a/applications/content/minilang/content/ContentServices.xml b/applications/content/minilang/content/ContentServices.xml index ad08f90..aad853a 100644 --- a/applications/content/minilang/content/ContentServices.xml +++ b/applications/content/minilang/content/ContentServices.xml @@ -712,118 +712,6 @@ </call-class-method> </simple-method> - <simple-method method-name="createContentAlternativeUrl" short-description="Create Content Alternative URLs."> - <set field="defaultLocaleString" from-field="parameters.locale" default-value="en"/> - <set field="contents" type="List"/> - <if> - <condition> - <or> - <if-empty field="parameters.contentId"/> - <if-compare operator="equals" value="null" field="parameters.contentId"/> - </or> - </condition> - <then> - <entity-condition entity-name="Content" list="contents"> - <condition-list combine="and"> - <condition-expr field-name="contentName" operator="not-equals" from-field="nullField"/> - <condition-list combine="or"> - <condition-expr field-name="contentTypeId" operator="equals" value="DOCUMENT"/> - <condition-expr field-name="contentTypeId" operator="equals" value="WEB_SITE_PUB_PT"/> - </condition-list> - </condition-list> - <select-field field-name="contentId"/> - <select-field field-name="contentName"/> - <select-field field-name="localeString"/> - </entity-condition> - </then> - <else> - <entity-condition entity-name="Content" list="contents"> - <condition-list combine="and"> - <condition-expr field-name="contentName" operator="not-equals" from-field="nullField"/> - <condition-expr field-name="contentId" operator="equals" from-field="parameters.contentId"/> - <condition-list combine="or"> - <condition-expr field-name="contentTypeId" operator="equals" value="DOCUMENT"/> - <condition-expr field-name="contentTypeId" operator="equals" value="WEB_SITE_PUB_PT"/> - </condition-list> - </condition-list> - <select-field field-name="contentId"/> - <select-field field-name="contentName"/> - <select-field field-name="localeString"/> - </entity-condition> - </else> - </if> - <iterate list="contents" entry="content"> - <set field="localeString" from-field="content.localeString" default-value="${defaultLocaleString}"/> - <entity-condition entity-name="ContentAssocDataResourceViewTo" list="contentAssocDataResources"> - <condition-list combine="and"> - <condition-expr field-name="caContentAssocTypeId" operator="equals" value="ALTERNATIVE_URL"/> - <condition-expr field-name="contentIdStart" operator="equals" from-field="content.contentId"/> - <condition-expr field-name="localeString" operator="equals" from-field="localeString"/> - </condition-list> - <select-field field-name="contentIdStart"/> - <select-field field-name="dataResourceId"/> - <select-field field-name="localeString"/> - <select-field field-name="drObjectInfo"/> - <select-field field-name="caFromDate"/> - <select-field field-name="caThruDate"/> - </entity-condition> - <filter-list-by-date list="contentAssocDataResources" from-field-name="caFromDate" thru-field-name="caThruDate"/> - <if-empty field="contentAssocDataResources"> - <if-not-empty field="content.contentName"> - <call-class-method method-name="invalidCharacter" class-name="org.apache.ofbiz.common.UrlServletHelper" ret-field="uri"> - <field field="content.contentName"/> - </call-class-method> - <if-not-empty field="uri"> - <sequenced-id sequence-name="DataResource" field="dataResourceCtx.dataResourceId"/> - <set field="dataResourceCtx.dataResourceTypeId" value="URL_RESOURCE"/> - <set field="dataResourceCtx.localeString" from-field="localeString"/> - <set field="dataResourceCtx.objectInfo" value="/${uri}-${content.contentId}-content"/> - <set field="dataResourceCtx.statusId" value="CTNT_IN_PROGRESS"/> - <call-service service-name="createDataResource" in-map-name="dataResourceCtx" break-on-error="false" include-user-login="true"> - <result-to-field result-name="dataResourceId" field="dataResourceId"/> - </call-service> - <if-not-empty field="dataResourceId"> - <set field="contentCtx.dataResourceId" from-field="dataResourceId"/> - <set field="contentCtx.statusId" value="CTNT_IN_PROGRESS"/> - <set field="contentCtx.localeString" from-field="localeString"/> - <call-service service-name="createContent" in-map-name="contentCtx" break-on-error="false" include-user-login="true"> - <result-to-field result-name="contentId" field="contentIdTo"/> - </call-service> - <if-not-empty field="contentIdTo"> - <set field="createContentAssocCtx.contentId" from-field="content.contentId"/> - <set field="createContentAssocCtx.contentIdTo" from-field="contentIdTo"/> - <set field="createContentAssocCtx.contentAssocTypeId" value="ALTERNATIVE_URL"/> - <call-service service-name="createContentAssoc" in-map-name="createContentAssocCtx" include-user-login="true" break-on-error="false"/> - </if-not-empty> - </if-not-empty> - <set field="contentCreated" value="Y"/> - <field-to-result field="contentCreated" result-name="contentCreated"/> - </if-not-empty> - </if-not-empty> - <else> - <if-empty field="contentAssocDataResources[0].drObjectInfo"> - <if-not-empty field="content.contentName"> - <call-class-method method-name="invalidCharacter" class-name="org.apache.ofbiz.common.UrlServletHelper" ret-field="uri"> - <field field="content.contentName"/> - </call-class-method> - <if-not-empty field="uri"> - <set field="dataResourceCtx.dataResourceId" from-field="contentAssocDataResources[0].dataResourceId"/> - <set field="dataResourceCtx.objectInfo" value="/${uri}-${content.contentId}-content"/> - <call-service service-name="updateDataResource" in-map-name="dataResourceCtx" break-on-error="false" include-user-login="true"/> - <set field="contentCreated" value="Y"/> - <field-to-result field="contentCreated" result-name="contentCreated"/> - </if-not-empty> - </if-not-empty> - <else> - <set field="contentCreated" value="N"/> - <field-to-result field="contentCreated" result-name="contentCreated"/> - </else> - </if-empty> - </else> - </if-empty> - </iterate> - </simple-method> - <simple-method method-name="createMissingContentAltUrls" short-description="create missing content alternative urls."> <now-timestamp field="now"/> <set field="contentsNotUpdated" value="0" type="Integer"/> diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml index 19a8d9d..170675a 100644 --- a/applications/content/servicedef/services.xml +++ b/applications/content/servicedef/services.xml @@ -1160,8 +1160,8 @@ <attribute name="dataResourceId" type="String" mode="IN" optional="true"/> </service> - <service name="createContentAlternativeUrl" engine="simple" - location="component://content/minilang/content/ContentServices.xml" invoke="createContentAlternativeUrl" auth="true" transaction-timeout="7200"> + <service name="createContentAlternativeUrl" engine="groovy" + location="component://content/groovyScripts/content/ContentServices.groovy" invoke="createContentAlternativeUrl" auth="true" transaction-timeout="7200"> <description>Create Content Alternative URL</description> <attribute name="contentId" mode="IN" type="String" optional="true"></attribute> <attribute name="contentCreated" mode="OUT" type="String" optional="true"></attribute> |
Free forum by Nabble | Edit this page |