This is an automated email from the ASF dual-hosted git repository.
mbrohl 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 f5788b2 Improved: Converts DataServices.xml to Groovy. (OFBIZ-11469) f5788b2 is described below commit f5788b2a81ebf37df7f9d32ba9634ccbdabc2424 Author: Benjamin Jugl <[hidden email]> AuthorDate: Mon Feb 1 14:01:46 2021 +0100 Improved: Converts DataServices.xml to Groovy. (OFBIZ-11469) --- .../content/groovyScripts/data/DataServices.groovy | 388 +++++++++++ .../content/minilang/data/DataServices.xml | 746 --------------------- .../content/servicedef/services_content.xml | 4 +- applications/content/servicedef/services_data.xml | 12 +- 4 files changed, 396 insertions(+), 754 deletions(-) diff --git a/applications/content/groovyScripts/data/DataServices.groovy b/applications/content/groovyScripts/data/DataServices.groovy new file mode 100644 index 0000000..c829073 --- /dev/null +++ b/applications/content/groovyScripts/data/DataServices.groovy @@ -0,0 +1,388 @@ +import java.sql.Timestamp + +import org.apache.ofbiz.base.util.UtilDateTime +import org.apache.ofbiz.base.util.UtilProperties +import org.apache.ofbiz.content.data.DataResourceWorker +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.entity.util.EntityUtil +import org.apache.ofbiz.service.ModelService +import org.apache.ofbiz.service.ServiceUtil + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +//Methods for DataResource +/** + * Create a Data Resource + * + * @return + */ + +def createDataResource() { + Map result = success() + + GenericValue newEntity = makeValue("DataResource", parameters) + + if (!newEntity.dataResourceId) { + newEntity.dataResourceId = delegator.getNextSeqId("DataResource") + } + + Timestamp nowTimestamp = UtilDateTime.nowTimestamp() + GenericValue userLogin = parameters.userLogin + newEntity.lastModifiedByUserLogin = userLogin.userLoginId + newEntity.createdByUserLogin = userLogin.userLoginId + newEntity.lastModifiedDate = nowTimestamp + newEntity.createdDate = nowTimestamp + + if (!parameters.dataTemplateTypeId) { + newEntity.dataTemplateTypeId = "NONE" + } + + if (!parameters.statusId) { + //get first status item + GenericValue statusItem = from("StatusItem") + .where("statusTypeId", "CONTENT_STATUS") + .orderBy("sequenceId") + .queryFirst() + newEntity.statusId = statusItem.statusId + } + + if (!newEntity.mimeTypeId && parameters.uploadedFile) { + newEntity.mimeTypeId = DataResourceWorker.getMimeTypeWithByteBuffer(parameters.uploadedFile) + } + + newEntity.create() + result.dataResourceId = newEntity.dataResourceId + result.dataResource = newEntity + + return result +} + +/** + * Create a Data Resource and return the data resource type + * + * @return + */ +def createDataResourceAndAssocToContent() { + + GenericValue content = from("Content").where(parameters).queryOne() + if (!content) { + return error(UtilProperties.getMessage("ContentErrorUiLabels", "layoutEvents.content_empty", parameters.locale)) + } + + Map serviceResult = run service: "createDataResource", with: parameters + if (!ServiceUtil.isSuccess(serviceResult)) { + return serviceResult + } + GenericValue dataResource = serviceResult.dataResource + + Map contentCtx = [:] + if (parameters.templateDataResource && parameters.templateDataResource == "Y") { + contentCtx.put("templateDataResourceId", parameters.dataResourceId) + } else { + contentCtx.put("dataRessourceId", parameters.dataResourceId) + } + contentCtx.put("contentId", parameters.contentId) + + Map result = run service: "updateContent", with: contentCtx + if (!ServiceUtil.isSuccess(result)) { + return result + } + + result.contentId = parameters.contentId + if (dataResource.dataResourceTypeId && + (dataResource.dataResourceTypeId == "ELECTRONIC_TEXT" || + dataResource.dataResourceTypeId == "IMAGE_OBJECT")) { + result.put(ModelService.RESPONSE_MESSAGE, "${dataResource.dataResourceTypeId}") + } + return result +} + +/** + * Get Electronic Text + * @return + */ +def getElectronicText() { + Map result = success() + GenericValue userLogin = parameters.userLogin + GenericValue currentContent = parameters.content + logInfo("GETELECTRONICTEXT, currentContent:${currentContent}") + + if (!currentContent) { + if (parameters.contentId) { + currentContent = from("Content").where(parameters).queryOne() + } + if (!currentContent) { + return error(UtilProperties.getMessage("ContentUiLabels", "ContentNeitherContentSupplied", parameters.locale)) + } + } + if (!currentContent.dataResourceId) { + return error(UtilProperties.getMessage("ContentUiLabels", "ContentDataResourceNotFound", parameters.locale)) + } + result.dataResourceId = currentContent.dataResourceId + GenericValue eText = from("ElectronicText").where("dataResourceId", currentContent.dataResourceId).queryOne() + if (!eText) { + return error(UtilProperties.getMessage("ContentUiLabels", "ContentElectronicTextNotFound", parameters.locale)) + } + result.textData = eText.textData + return result +} + +/** + * Attach an uploaded file to a data resource + * + * @return + */ +def attachUploadToDataResource() { + boolean isUpdate = false + boolean forceLocal = UtilProperties.getPropertyValue("content.properties", "content.upload.always.local.file") + List validLocalFileTypes = [ + "LOCAL_FILE", + "OFBIZ_FILE", + "CONTEXT_FILE", + "LOCAL_FILE_BIN", + "OFBIZ_FILE_BIN", + "CONTEXT_FILE_BIN" + ] + boolean isValidLocalType = parameters.dataResourceTypeId in validLocalFileTypes + if (forceLocal && !isValidLocalType) { + parameters.dataResourceTypeId = "LOCAL_FILE" + } + + if (!parameters.dataResourceTypeId) { + // create default behaviour + if (parameters._uploadedFile_contentType) { + switch (parameters._uploadedFile_contentType) { + case ~/image.*/: + parameters.dataResourceTypeId = "IMAGE_OBJECT" + break + case ~/video.*/: + parameters.dataResourceTypeId = "VIDEO_OBJECT" + break + case ~/audio.*/: + parameters.dataResourceTypeId = "AUDIO_OBJECT" + break + default: + parameters.dataResourceTypeId = "OTHER_OBJECT" + } + } else { + parameters.dataResourceTypeId = "OTHER_OBJECT" + } + } + switch (parameters.dataResourceTypeId) { + case ["LOCAL_FILE", "LOCAL_FILE_BIN", "OFBIZ_FILE", "OFBIZ_FILE_BIN", "CONTEXT_FILE", "CONTEXT_FILE_BIN"]: + return saveLocalFileDataResource(parameters.dataResourceTypeId) + case "IMAGE_OBJECT": + GenericValue dataResObj = from("ImageDataResource") + .where("dataResourceId", parameters.dataResourceId) + .queryOne() + if (dataResObj) { + isUpdate = true + } + break + case "VIDEO_OBJECT": + GenericValue dataResObj = from("VideoDataResource") + .where("dataResourceId", parameters.dataResourceId) + .queryOne() + if (dataResObj) { + isUpdate = true + } + break + case "AUDIO_OBJECT": + GenericValue dataResObj = from("AudioDataResource") + .where("dataResourceId", parameters.dataResourceId) + .queryOne() + if (dataResObj) { + isUpdate = true + } + break + case "OTHER_OBJECT": + GenericValue dataResObj = from("OtherDataResource") + .where("dataResourceId", parameters.dataResourceId) + .queryOne() + if (dataResObj) { + isUpdate = true + } + break + } + + return saveExtFileDataResource(isUpdate, parameters.dataResourceTypeId) +} + +/** + * Attach an uploaded file to a data resource as a Local File-Type (Local, OfBiz or Context) + * + * @param absolute + * @return + */ +def saveLocalFileDataResource(String mode) { + Map result = success() + List errorList = [] + boolean isUpdate = false + GenericValue dataResource = from("DataResource").where(parameters).queryOne() + if (!dataResource) { + errorList.add(UtilProperties.getMessage("ContentUiLabels", "ContentDataResourceNotFound", parameters.locale)) + } else { + if (dataResource.objectInfo) { + isUpdate = true + } + } + if (!parameters._uploadedFile_fileName) { + if (isUpdate) { + // upload is found on an update; its okay, don't do anything just return + result.dataResourceId = dataResource.dataResourceId + result.mimeTypeId = dataResource.mimeTypeId + return result + } else { + errorList.add(UtilProperties.getMessage("ContentUiLabels", "ContentNoUploadedContentFound", parameters.locale)) + } + } + String uploadPath = null + switch (mode) { + case ["LOCAL_FILE", "LOCAL_FILE_BIN"]: + uploadPath = DataResourceWorker.getDataResourceContentUploadPath(delegator, true) + break + case ["OFBIZ_FILE", "OFBIZ_FILE_BIN"]: + uploadPath = DataResourceWorker.getDataResourceContentUploadPath(delegator, false) + break + case ["CONTEXT_FILE", "CONTEXT_FILE_BIN"]: + uploadPath = parameters.rootDir + break + } + if (!uploadPath) { + errorList.add(UtilProperties.getMessage("ContentErrorUiLabels", "uploadContentAndImage.noRootDirProvided", parameters.locale)) + } + if (errorList) { + return ServiceUtil.returnError(errorList) + } + logInfo("[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}") + GenericValue extension = from("FileExtension") + .where("mimeTypeId", parameters._uploadedFile_contentType) + .queryFirst() + dataResource.dataResourceName = parameters._uploadedFile_fileName + dataResource.objectInfo = extension ? + "${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" : + "${uploadPath}/${dataResource.dataResourceId}" + dataResource.dataResourceTypeId = parameters.dataResourceTypeId + dataResource.store() + + ModelService cafService = dispatcher.getDispatchContext().getModelService("createAnonFile") + Map fileCtx = cafService.makeValid(dataResource, "IN") + fileCtx.binData = parameters.uploadedFile + fileCtx.dataResource = dataResource + result = run service: "createAnonFile", with: fileCtx + result.dataResourceId = dataResource.dataResourceId + result.mimeTypeId = dataResource.mimeTypeId + + return result +} + +def saveExtFileDataResource(boolean isUpdate, String mode) { + Map result = success() + List errorList = [] + GenericValue dataResource = from("DataResource") + .where("dataResourceId", parameters.dataResourceId) + .queryOne() + if (!dataResource) { + errorList.add(UtilProperties.getMessage("ContentUiLabels", "ContentDataResourceNotFound", parameters.locale)) + } + if (!parameters._uploadedFile_fileName) { + if (isUpdate) { + // upload is found on an update; its okay, don't do anything just return + result.dataResourceId = dataResource.dataResourceId + result.mimeTypeId = dataResource.mimeTypeId + return result + } else { + errorList.add(UtilProperties.getMessage("ContentUiLabels", "ContentNoUploadedContentFound", parameters.locale)) + } + } + // update the data resource with file data + dataResource.dataResourceTypeId = parameters.dataResourceTypeId + dataResource.dataResourceName = parameters._uploadedFile_fileName + dataResource.mimeTypeId = parameters._uploadedFile_contentType + dataResource.store() + + Map serviceContext = prepareServiceContext(dataResource, mode) + + if (isUpdate) { + switch (mode) { + case "IMAGE_OBJECT": + result = run service: "updateImageDataResource", with: serviceContext + break + case "VIDEO_OBJECT": + result = run service: "updateVideoDataResource", with: serviceContext + break + case "AUDIO_OBJECT": + result = run service: "updateAudioDataResource", with: serviceContext + break + case "OTHER_OBJECT": + result = run service: "updateOtherDataResource", with: serviceContext + break + } + + } else { + switch (mode) { + case "IMAGE_OBJECT": + result = run service: "createImageDataResource", with: serviceContext + break + case "VIDEO_OBJECT": + result = run service: "createVideoDataResource", with: serviceContext + break + case "AUDIO_OBJECT": + result = run service: "createAudioDataResource", with: serviceContext + break + case "OTHER_OBJECT": + result = run service: "createOtherDataResource", with: serviceContext + break + } + } + + result.dataResourceId = dataResource.dataResourceId + result.mimeTypeId = dataResource.mimeTypeId + + return result +} + +Map prepareServiceContext(GenericValue dataResource, String mode) { + switch (mode) { + case "IMAGE_OBJECT": + ModelService service = dispatcher.getDispatchContext().getModelService("createImageDataResource") + Map serviceContext = service.makeValid(dataResource, "IN") + serviceContext.imageData = parameters.uploadedFile + serviceContext.dataResource = dataResource + return serviceContext + case "VIDEO_OBJECT": + ModelService service = dispatcher.getDispatchContext().getModelService("updateVideoDataResource") + Map serviceContext = service.makeValid(dataResource, "IN") + serviceContext.videoData = parameters.uploadedFile + return serviceContext + case "AUDIO_OBJECT": + ModelService service = dispatcher.getDispatchContext().getModelService("createAudioDataResource") + Map serviceContext = service.makeValid(dataResource, "IN") + serviceContext.audioData + return serviceContext + case "OTHER_OBJECT": + ModelService service = dispatcher.getDispatchContext().getModelService("createOtherDataResource") + Map serviceContext = service.makeValid(dataResource, "IN") + serviceContext.dataResourceContent = parameters.uploadedFile + return serviceContext + } + return error +} diff --git a/applications/content/minilang/data/DataServices.xml b/applications/content/minilang/data/DataServices.xml deleted file mode 100644 index c845e90..0000000 --- a/applications/content/minilang/data/DataServices.xml +++ /dev/null @@ -1,746 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <!-- Methods for DataResource --> - <simple-method method-name="createDataResource" short-description="Create a Data Resource"> - <make-value entity-name="DataResource" value-field="newEntity"/> - <set-nonpk-fields map="parameters" value-field="newEntity"/> - <set-pk-fields map="parameters" value-field="newEntity"/> - - <if-empty field="newEntity.dataResourceId"> - <sequenced-id sequence-name="DataResource" field="newEntity.dataResourceId"/> - </if-empty> - - <now-timestamp field="nowTimestamp"/> - <set field="newEntity.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/> - <set field="newEntity.createdByUserLogin" from-field="userLogin.userLoginId"/> - <set field="newEntity.lastModifiedDate" from-field="nowTimestamp"/> - <set field="newEntity.createdDate" from-field="nowTimestamp"/> - - <if-empty field="parameters.dataTemplateTypeId"> - <set field="newEntity.dataTemplateTypeId" value="NONE"/> - </if-empty> - - <if-empty field="parameters.statusId"> - <!-- get the first status item --> - <entity-and entity-name="StatusItem" list="contentStatus"> - <field-map field-name="statusTypeId" value="CONTENT_STATUS"/> - <order-by field-name="sequenceId"/> - </entity-and> - <first-from-list list="contentStatus" entry="statusItem"/> - <set field="newEntity.statusId" from-field="statusItem.statusId"/> - </if-empty> - - <if-empty field="newEntity.mimeTypeId"> - <if-not-empty field="parameters.uploadedFile"> - <call-class-method class-name="org.apache.ofbiz.content.data.DataResourceWorker" method-name="getMimeTypeWithByteBuffer" ret-field="newEntity.mimeTypeId"> - <field field="parameters.uploadedFile" type="java.nio.ByteBuffer"/> - </call-class-method> - </if-not-empty> - </if-empty> - - <create-value value-field="newEntity"/> - <field-to-result field="newEntity.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="newEntity" result-name="dataResource"/> - </simple-method> - - <simple-method method-name="createDataResourceAndAssocToContent" short-description="Create a Data Resource and return the data resource type"> - <entity-one entity-name="Content" value-field="content"/> - <if-empty field="content"> - <add-error> - <fail-property resource="ContentErrorUiLabels" property="layoutEvents.content_empty"/> - </add-error> - <check-errors/> - </if-empty> - - <set-service-fields service-name="createDataResource" map="parameters" to-map="dataResourceCtx"/> - <call-service service-name="createDataResource" in-map-name="dataResourceCtx"> - <result-to-field result-name="dataResource"/> - </call-service> - - <if-compare field="parameters.templateDataResource" operator="equals" value="Y"> - <set field="contentCtx.templateDataResourceId" from-field="parameters.dataResourceId" /> - <else> - <set field="contentCtx.dataResourceId" from-field="parameters.dataResourceId" /> - </else> - </if-compare> - <set field="contentCtx.contentId" from-field="parameters.contentId"/> - <call-service service-name="updateContent" in-map-name="contentCtx"/> - - <field-to-result field="parameters.contentId" result-name="contentId"/> - <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="ELECTRONIC_TEXT"><return response-code="${dataResource.dataResourceTypeId}"/></if-compare> - <if-compare field="dataResource.dataResourceTypeId" operator="equals" value="IMAGE_OBJECT"><return response-code="${dataResource.dataResourceTypeId}"/></if-compare> - </simple-method> - - <!-- - getElectronicText - Passed a Content GenericValue or a contentId, this service returns the text data from - ElectronicText in result.textData. - - Not that this service does not now do permission checking. - --> - <simple-method method-name="getElectronicText" short-description="Get Electronic Text" login-required="false"> - <set field="userLogin" from-field="parameters.userLogin"/> - <set field="currentContent" from-field="parameters.content"/> - <log level="info" message="GETELECTRONICTEXT, currentContent:${currentContent}"/> - - <if-empty field="currentContent"> - <if-not-empty field="parameters.contentId"> - <entity-one entity-name="Content" value-field="currentContent" use-cache="true"/> - </if-not-empty> - <if-empty field="currentContent"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNeitherContentSupplied"/> - </add-error> - </if-empty> - </if-empty> - <check-errors/> - <if-empty field="currentContent.dataResourceId"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentDataResourceNotFound"/> - </add-error> - </if-empty> - <check-errors/> - <field-to-result field="currentContent.dataResourceId" result-name="dataResourceId"/> - <entity-one entity-name="ElectronicText" value-field="eText"> - <field-map field-name="dataResourceId" from-field="currentContent.dataResourceId"/> - </entity-one> - <if-empty field="eText"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentElectronicTextNotFound"/> - </add-error> - </if-empty> - <check-errors/> - - <field-to-result field="eText.textData" result-name="textData"/> - </simple-method> - - <simple-method method-name="attachUploadToDataResource" short-description="Attach an uploaded file to a data resource"> - <set field="isUpdate" value="false"/> - <property-to-field resource="content.properties" property="content.upload.always.local.file" field="forceLocal"/> - <if> - <condition> - <and> - <if-compare field="forceLocal" value="true" operator="equals"/> - <not> - <or> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="LOCAL_FILE"/> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="OFBIZ_FILE"/> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="CONTEXT_FILE"/> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="LOCAL_FILE_BIN"/> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="OFBIZ_FILE_BIN"/> - <if-compare field="parameters.dataResourceTypeId" operator="equals" value="CONTEXT_FILE_BIN"/> - </or> - </not> - </and> - </condition> - <then> - <set field="parameters.dataResourceTypeId" value="LOCAL_FILE"/> - </then> - </if> - - <if-empty field="parameters.dataResourceTypeId"> - <!-- create default behavior --> - <if> - <condition> - <not> - <if-empty field="parameters._uploadedFile_contentType"/> - </not> - </condition> - <then> - <if> - <condition> - <if-regexp field="parameters._uploadedFile_contentType" expr="image.*"/> - </condition> - <then> - <set field="parameters.dataResourceTypeId" value="IMAGE_OBJECT"/> - </then> - <else-if> - <condition> - <if-regexp field="parameters._uploadedFile_contentType" expr="video.*"/> - </condition> - <then> - <set field="parameters.dataResourceTypeId" value="VIDEO_OBJECT"/> - </then> - </else-if> - <else-if> - <condition> - <if-regexp field="parameters._uploadedFile_contentType" expr="audio.*"/> - </condition> - <then> - <set field="parameters.dataResourceTypeId" value="AUDIO_OBJECT"/> - </then> - </else-if> - <else> - <set field="parameters.dataResourceTypeId" value="OTHER_OBJECT"/> - </else> - </if> - </then> - <else> - <set field="parameters.dataResourceTypeId" value="OTHER_OBJECT"/> - </else> - </if> - </if-empty> - - <if> - <condition> - <or> - <if-compare field="parameters.dataResourceTypeId" value="LOCAL_FILE" operator="equals"/> - <if-compare field="parameters.dataResourceTypeId" value="LOCAL_FILE_BIN" operator="equals"/> - </or> - </condition> - <then> - <call-simple-method method-name="saveLocalFileDataResource"/> - <return/> - </then> - </if> - - <if> - <condition> - <or> - <if-compare field="parameters.dataResourceTypeId" value="OFBIZ_FILE" operator="equals"/> - <if-compare field="parameters.dataResourceTypeId" value="OFBIZ_FILE_BIN" operator="equals"/> - </or> - </condition> - <then> - <call-simple-method method-name="saveOfbizFileDataResource"/> - <return/> - </then> - </if> - - <if> - <condition> - <or> - <if-compare field="parameters.dataResourceTypeId" value="CONTEXT_FILE" operator="equals"/> - <if-compare field="parameters.dataResourceTypeId" value="CONTEXT_FILE_BIN" operator="equals"/> - </or> - </condition> - <then> - <call-simple-method method-name="saveContextFileDataResource"/> - <return/> - </then> - </if> - - <if-compare field="parameters.dataResourceTypeId" value="IMAGE_OBJECT" operator="equals"> - <entity-one entity-name="ImageDataResource" value-field="dataResObj"> - <field-map field-name="dataResourceId" from-field="parameters.dataResourceId"/> - </entity-one> - <if-not-empty field="dataResObj"> - <set field="isUpdate" value="true"/> - </if-not-empty> - <call-simple-method method-name="saveImageObjectDateResource"/> - <return/> - </if-compare> - - <if-compare field="parameters.dataResourceTypeId" value="VIDEO_OBJECT" operator="equals"> - <entity-one entity-name="VideoDataResource" value-field="dataResObj"> - <field-map field-name="dataResourceId" from-field="parameters.dataResourceId"/> - </entity-one> - <if-not-empty field="dataResObj"> - <set field="isUpdate" value="true"/> - </if-not-empty> - <call-simple-method method-name="saveVideoObjectDateResource"/> - <return/> - </if-compare> - - <if-compare field="parameters.dataResourceTypeId" value="AUDIO_OBJECT" operator="equals"> - <entity-one entity-name="AudioDataResource" value-field="dataResObj"> - <field-map field-name="dataResourceId" from-field="parameters.dataResourceId"/> - </entity-one> - <if-not-empty field="dataResObj"> - <set field="isUpdate" value="true"/> - </if-not-empty> - <call-simple-method method-name="saveAudioObjectDateResource"/> - <return/> - </if-compare> - - <if-compare field="parameters.dataResourceTypeId" value="OTHER_OBJECT" operator="equals"> - <entity-one entity-name="OtherDataResource" value-field="dataResObj"> - <field-map field-name="dataResourceId" from-field="parameters.dataResourceId"/> - </entity-one> - <if-not-empty field="dataResObj"> - <set field="isUpdate" value="true"/> - </if-not-empty> - <call-simple-method method-name="saveOtherObjectDateResource"/> - <return/> - </if-compare> - - <add-error> - <fail-property resource="ContentUiLabels" property="ContentDataTypeNotYetSupported"/> - </add-error> - <check-errors/> - </simple-method> - - <!-- save LOCAL_FILE data --> - <simple-method method-name="saveLocalFileDataResource" short-description="Attach an uploaded file to a data resource as LOCAL_FILE"> - <entity-one entity-name="DataResource" value-field="dataResource"/> - <if-empty field="dataResource"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentDataResourceNotFound"/> - </add-error> - <else> - <if-not-empty field="dataResource.objectInfo"> - <set field="isUpdate" value="Y"/> - </if-not-empty> - </else> - </if-empty> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - <set field="absolute" value="true" type="Boolean"/> - <call-class-method method-name="getDataResourceContentUploadPath" class-name="org.apache.ofbiz.content.data.DataResourceWorker" ret-field="uploadPath"> - <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/> - <field field="absolute" type="boolean"/> - </call-class-method> - <log level="info" message="[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}"/> - - <set from-field="parameters._uploadedFile_contentType" field="extenLookup.mimeTypeId"/> - <find-by-and entity-name="FileExtension" map="extenLookup" list="extensions"/> - <first-from-list list="extensions" entry="extension"/> - - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set value="${uploadPath}/${dataResource.dataResourceId}" field="dataResource.objectInfo"/> - <if-not-empty field="extension"> - <set value="${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" field="dataResource.objectInfo"/> - </if-not-empty> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <store-value value-field="dataResource"/> - - <set-service-fields service-name="createAnonFile" map="dataResource" to-map="fileCtx"/> - <set from-field="parameters.uploadedFile" field="fileCtx.binData"/> - <set from-field="dataResource" field="fileCtx.dataResource"/> - <call-service service-name="createAnonFile" in-map-name="fileCtx" include-user-login="true"/> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save OFBIZ_FILE data --> - <simple-method method-name="saveOfbizFileDataResource" short-description="Attach an uploaded file to a data resource as OFBIZ_FILE"> - <entity-one entity-name="DataResource" value-field="dataResource"/> - <if-empty field="dataResource"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentDataResourceNotFound"/> - </add-error> - <else> - <if-not-empty field="dataResource.objectInfo"> - <set field="isUpdate" value="Y"/> - </if-not-empty> - </else> - </if-empty> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <set field="absolute" value="false" type="Boolean"/> - <call-class-method method-name="getDataResourceContentUploadPath" class-name="org.apache.ofbiz.content.data.DataResourceWorker" ret-field="uploadPath"> - <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/> - <field field="absolute" type="boolean"/> - </call-class-method> - <log level="info" message="[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}"/> - - <set from-field="parameters._uploadedFile_contentType" field="extenLookup.mimeTypeId"/> - <find-by-and entity-name="FileExtension" map="extenLookup" list="extensions"/> - <first-from-list list="extensions" entry="extension"/> - - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <set value="${uploadPath}/${dataResource.dataResourceId}" field="dataResource.objectInfo"/> - <if-not-empty field="extension"> - <set value="${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" field="dataResource.objectInfo"/> - </if-not-empty> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <store-value value-field="dataResource"/> - - <set-service-fields service-name="createAnonFile" map="dataResource" to-map="fileCtx"/> - <set from-field="parameters.uploadedFile" field="fileCtx.binData"/> - <set from-field="dataResource" field="fileCtx.dataResource"/> - <call-service service-name="createAnonFile" in-map-name="fileCtx" include-user-login="true"/> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save OTHER_OBJECT data --> - <simple-method method-name="saveOtherObjectDateResource" short-description="Attach an uploaded file to a data resource as OTHER_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> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <!-- update the data resource with file data --> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <store-value value-field="dataResource"/> - - <!-- fields serviceName and fileField are required to be set by calling method --> - <set-service-fields service-name="createOtherDataResource" map="dataResource" to-map="serviceContext"/> - <set from-field="parameters.uploadedFile" field="serviceContext.dataResourceContent"/> - - <if-compare field="isUpdate" value="true" operator="equals"> - <call-service service-name="updateOtherDataResource" in-map-name="serviceContext"/> - <else> - <call-service service-name="createOtherDataResource" in-map-name="serviceContext"/> - </else> - </if-compare> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save IMAGE_OBJECT data --> - <simple-method method-name="saveImageObjectDateResource" short-description="Attach an uploaded file to a data resource as IMAGE_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> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <!-- update the data resource with file data --> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <store-value value-field="dataResource"/> - - <!-- fields serviceName and fileField are required to be set by calling method --> - <set-service-fields service-name="createImageDataResource" map="dataResource" to-map="serviceContext"/> - <set from-field="parameters.uploadedFile" field="serviceContext.imageData"/> - - <if-compare field="isUpdate" value="true" operator="equals"> - <call-service service-name="updateImageDataResource" in-map-name="serviceContext"/> - <else> - <call-service service-name="createImageDataResource" in-map-name="serviceContext"/> - </else> - </if-compare> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save VIDEO_OBJECT data --> - <simple-method method-name="saveVideoObjectDateResource" short-description="Attach an uploaded file to a data resource as VIDEO_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> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <!-- update the data resource with file data --> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <store-value value-field="dataResource"/> - - <!-- fields serviceName and fileField are required to be set by calling method --> - <set-service-fields service-name="createVideoDataResource" map="dataResource" to-map="serviceContext"/> - <set from-field="parameters.uploadedFile" field="serviceContext.videoData"/> - - <if-compare field="isUpdate" value="true" operator="equals"> - <call-service service-name="updateVideoDataResource" in-map-name="serviceContext"/> - <else> - <call-service service-name="createVideoDataResource" in-map-name="serviceContext"/> - </else> - </if-compare> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save AUDIO_OBJECT data --> - <simple-method method-name="saveAudioObjectDateResource" short-description="Attach an uploaded file to a data resource as AUDIO_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> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <!-- update the data resource with file data --> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <store-value value-field="dataResource"/> - - <!-- fields serviceName and fileField are required to be set by calling method --> - <set-service-fields service-name="createAudioDataResource" map="dataResource" to-map="serviceContext"/> - <set from-field="parameters.uploadedFile" field="serviceContext.audioData"/> - - <if-compare field="isUpdate" value="true" operator="equals"> - <call-service service-name="updateAudioDataResource" in-map-name="serviceContext"/> - <else> - <call-service service-name="createAudioDataResource" in-map-name="serviceContext"/> - </else> - </if-compare> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> - - <!-- save CONTEXT_FILE data --> - <simple-method method-name="saveContextFileDataResource" short-description="Attach an uploaded file to a data resource as CONTEXT_FILE"> - <entity-one entity-name="DataResource" value-field="dataResource"/> - <if-empty field="dataResource"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentDataResourceNotFound"/> - </add-error> - <else> - <if-not-empty field="dataResource.objectInfo"> - <set field="isUpdate" value="Y"/> - </if-not-empty> - </else> - </if-empty> - <if> - <condition> - <if-empty field="parameters._uploadedFile_fileName"/> - </condition> - <then> - <if> - <condition> - <or> - <if-empty field="isUpdate"/> - <if-compare field="isUpdate" value="Y" operator="not-equals"/> - </or> - </condition> - <then> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentNoUploadedContentFound"/> - </add-error> - </then> - <else> - <!-- if not upload is found on an update; its okay, don't do anything just return --> - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - <return/> - </else> - </if> - - </then> - </if> - <check-errors/> - - <set field="uploadPath" from-field="parameters.rootDir"/> - <log level="info" message="[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}"/> - <if-empty field="uploadPath"> - <add-error> - <fail-property resource="ContentErrorUiLabels" property="uploadContentAndImage.noRootDirProvided"/> - </add-error> - <check-errors/> - </if-empty> - <log level="info" message="[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}"/> - - <set from-field="parameters._uploadedFile_contentType" field="extenLookup.mimeTypeId"/> - <find-by-and entity-name="FileExtension" map="extenLookup" list="extensions"/> - <first-from-list list="extensions" entry="extension"/> - - <set from-field="parameters._uploadedFile_fileName" field="dataResource.dataResourceName"/> - <set from-field="parameters._uploadedFile_contentType" field="dataResource.mimeTypeId"/> - <set value="${uploadPath}/${dataResource.dataResourceId}" field="dataResource.objectInfo"/> - <if-not-empty field="extension"> - <set value="${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" field="dataResource.objectInfo"/> - </if-not-empty> - <set from-field="parameters.dataResourceTypeId" field="dataResource.dataResourceTypeId"/> - <store-value value-field="dataResource"/> - - <set-service-fields service-name="createAnonFile" map="dataResource" to-map="fileCtx"/> - <set from-field="parameters.uploadedFile" field="fileCtx.binData"/> - <set from-field="dataResource" field="fileCtx.dataResource"/> - <call-service service-name="createAnonFile" in-map-name="fileCtx" include-user-login="true"/> - - <field-to-result field="dataResource.dataResourceId" result-name="dataResourceId"/> - <field-to-result field="dataResource.mimeTypeId" result-name="mimeTypeId"/> - </simple-method> -</simple-methods> diff --git a/applications/content/servicedef/services_content.xml b/applications/content/servicedef/services_content.xml index 4466335..a701a73 100644 --- a/applications/content/servicedef/services_content.xml +++ b/applications/content/servicedef/services_content.xml @@ -80,8 +80,8 @@ <attribute name="uploadedFile" type="java.nio.ByteBuffer" mode="IN" optional="true"/> </service> - <service name="attachUploadToDataResource" engine="simple" transaction-timeout="300" - location="component://content/minilang/data/DataServices.xml" invoke="attachUploadToDataResource"> + <service name="attachUploadToDataResource" engine="groovy" transaction-timeout="300" + location="component://content/groovyScripts/data/DataServices.groovy" invoke="attachUploadToDataResource"> <description>Accepts uploaded content and attaches to an existing data resource</description> <!-- uses createContent internally; additonal permission(s) not necessary --> <implements service="uploadFileInterface"/> diff --git a/applications/content/servicedef/services_data.xml b/applications/content/servicedef/services_data.xml index 48ffe5d..145fde5 100644 --- a/applications/content/servicedef/services_data.xml +++ b/applications/content/servicedef/services_data.xml @@ -23,8 +23,8 @@ <vendor>OFBiz</vendor> <!-- DataResource services --> - <service name="createDataResource" default-entity-name="DataResource" engine="simple" - location="component://content/minilang/data/DataServices.xml" invoke="createDataResource" auth="true"> + <service name="createDataResource" default-entity-name="DataResource" engine="groovy" + location="component://content/groovyScripts/data/DataServices.groovy" invoke="createDataResource" auth="true"> <description>Create a DataResource</description> <permission-service service-name="genericDataResourcePermission" main-action="CREATE"/> <auto-attributes include="nonpk" mode="IN" optional="true"/> @@ -40,8 +40,8 @@ <override name="objectInfo" allow-html="safe"/> <override name="dataResourceName" allow-html="safe"/> </service> - <service name="createDataResourceAndAssocToContent" default-entity-name="DataResource" engine="simple" - location="component://content/minilang/data/DataServices.xml" invoke="createDataResourceAndAssocToContent" auth="true"> + <service name="createDataResourceAndAssocToContent" default-entity-name="DataResource" engine="groovy" + location="component://content/groovyScripts/data/DataServices.groovy" invoke="createDataResourceAndAssocToContent" auth="true"> <description>Create a DataResource and link this data to the content present</description> <permission-service service-name="genericDataResourcePermission" main-action="CREATE"/> <implements service="createDataResource" optional="true"/> @@ -147,8 +147,8 @@ <permission-service service-name="genericDataResourcePermission" main-action="DELETE"/> <auto-attributes include="pk" mode="IN" optional="false"/> </service> - <service name="getElectronicText" engine="simple" - location="component://content/minilang/data/DataServices.xml" invoke="getElectronicText" default-entity-name="ElectronicText" auth="false" > + <service name="getElectronicText" engine="groovy" + location="component://content/groovyScripts/data/DataServices.groovy" invoke="getElectronicText" default-entity-name="ElectronicText" auth="false" > <description>Get a ElectronicText: Can pass either content value object or contentId</description> <attribute mode="IN" name="contentId" optional="true" type="String"/> <attribute mode="IN" name="content" optional="true" type="org.apache.ofbiz.entity.GenericValue"/> |
Free forum by Nabble | Edit this page |