blob: 6ddd5dd420717b55ddf16237a82ffa763921ce1f [file] [log] [blame]
<?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="always" 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"/>
<log level="always" message="result:${result}"/>
<log level="always" message="parameters:${parameters}"/>
</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>