svn commit: r493122 - in /ofbiz/trunk/applications/content: script/org/ofbiz/content/content/ContentServices.xml servicedef/services.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r493122 - in /ofbiz/trunk/applications/content: script/org/ofbiz/content/content/ContentServices.xml servicedef/services.xml

jaz-3
Author: jaz
Date: Fri Jan  5 10:30:26 2007
New Revision: 493122

URL: http://svn.apache.org/viewvc?view=rev&rev=493122
Log:
final refactor of content upload services; now the upload (save file) service is broken down so it can be reused to upload any content and attach to an existing dataresource. The dataresource shell should be created before calling the upload service

A new createContentFromUploadedFile (group) service will do the following:
1) create data resource
2) accept uploaded stream, update datasource and save the local file
3) create content record associated with data resource


Modified:
    ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml
    ofbiz/trunk/applications/content/servicedef/services.xml

Modified: ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml?view=diff&rev=493122&r1=493121&r2=493122
==============================================================================
--- ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml (original)
+++ ofbiz/trunk/applications/content/script/org/ofbiz/content/content/ContentServices.xml Fri Jan  5 10:30:26 2007
@@ -789,55 +789,78 @@
         <create-value value-name="content"/>
     </simple-method>
 
-    <!-- This method will accept an uploaded file stream and create a generic Content/DataResource record -->
-    <simple-method method-name="createUploadedLocalFileContent" short-description="Creates a Local File Content from an uploaded stream">
-        <!-- check for the uploaded file name and information -->
-        <if-not-empty field-name="_uploadedFile_fileName" map-name="parameters">
-            <call-class-method class-name="org.ofbiz.content.data.DataResourceWorker" method-name="getDataResourceContentUploadPath" ret-field-name="uploadPath"/>
-            <log level="info" message="[createUploadedLocalFileContent] - Found Subdir : ${uploadPath}"/>
-
-            <!-- locate the file extension to use based on mime-type -->
-            <set from-field="parameters._uploadedFile_contentType" field="extenLookup.mimeTypeId"/>
-            <find-by-and entity-name="FileExtension" map-name="extenLookup" list-name="extensions"/>
-            <first-from-list entry-name="extension" list-name="extensions"/>
-            <set-service-fields service-name="createDataResource" map-name="parameters" to-map-name="dataResource"/>
-
-            <!-- obtain a data resource id (needed in advance for the raw file name -->
-            <sequenced-id-to-env sequence-name="DataResource" env-name="dataResourceId"/>
-            <set from-field="dataResourceId" field="dataResource.dataResourceId"/>
-            
-            <!-- create the data resource object -->
-            <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-name="extension">
-                <set value="${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" field="dataResource.objectInfo"/>
-            </if-not-empty>
-            <set value="LOCAL_FILE" field="dataResource.dataResourceTypeId"/>
-            <call-service service-name="createDataResource" in-map-name="dataResource" break-on-error="false">
-                <result-to-field result-name="dataResourceId" field-name="dataResourceId"/>
-                <result-to-field result-name="dataResource" field-name="dataResourceMap"/>
-            </call-service>
-
-            <!-- create the content record -->
-            <set-service-fields service-name="createContent" map-name="parameters" to-map-name="createContentMap"/>
-            <set from-field="parameters._uploadedFile_fileName" field="createContentMap.contentName"/>
-            <set from-field="parameters._uploadedFile_contentType" field="createContentMap.mimeTypeId"/>
-            <set from-field="dataResourceId" field="createContentMap.dataResourceId"/>
-            <call-service service-name="createContent" in-map-name="createContentMap" break-on-error="false">
-                <result-to-field result-name="contentId" field-name="contentId"/>
-            </call-service>
-
-            <!-- store the file -->
-            <set-service-fields service-name="createAnonFile" map-name="dataResourceMap" to-map-name="fileCtx"/>
-            <set from-field="parameters.uploadedFile" field="fileCtx.binData"/>
-            <set from-field="dataResourceMap" field="fileCtx.dataResource"/>
-            <call-service service-name="createAnonFile" in-map-name="fileCtx" include-user-login="true"/>
-            
-            <field-to-result field-name="contentId" />
-       </if-not-empty>
+    <!-- This method will create a skeleton content record from a data resource -->
+    <simple-method method-name="createContentFromDataResource" short-description="Create Content from DataResource Object">
+        <entity-one entity-name="DataResource" value-name="dataResource">
+            <field-map field-name="dataResourceId" env-name="parameters.dataResourceId"/>
+        </entity-one>
+        <if-empty field-name="dataResource">
+            <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
+        </if-empty>
+        <check-errors/>
+
+        <set-service-fields service-name="createContent" map-name="parameters" to-map-name="createContentMap"/>
+
+        <if-empty field-name="createContentMap.contentName">
+            <set field="createContentMap.contentName" from-field="dataResource.dataResourceName"/>
+        </if-empty>
+
+        <if-empty field-name="createContentMap.contentTypeId">
+            <set field="createContentMap.contentTypeId" value="DOCUMENT"/>
+        </if-empty>
+
+        <if-empty field-name="createContentMap.statusId">
+            <set field="createContentMap.statusId" value="CTNT_INITIAL_DRAFT"/>
+        </if-empty>
+
+        <if-empty field-name="createContentMap.mimeTypeId">
+            <set from-field="dataResource.mimeTypeId" field="createContentMap.mimeTypeId"/>
+        </if-empty>
+
+        <call-service service-name="createContent" in-map-name="createContentMap" break-on-error="false">
+            <result-to-field result-name="contentId" field-name="contentId"/>
+        </call-service>
+
+        <field-to-result field-name="contentId" />
     </simple-method>
 
+    <!-- Attaches an uploaded file to an existing data resource object -->
+    <simple-method method-name="attachLocalFileToDataResource" short-description="Attach an uploaded file to a data resource as LOCAL_FILE">
+        <entity-one entity-name="DataResource" value-name="dataResource">
+            <field-map field-name="dataResourceId" env-name="parameters.dataResourceId"/>
+        </entity-one>
+        <if-empty field-name="dataResource">
+            <add-error><fail-message message="No data resource found for ID: [$parameters.dataResourceId}]"/></add-error>
+        </if-empty>
+        <if-empty field-name="_uploadedFile_fileName" map-name="parameters">
+            <add-error><fail-message message="No uploaded content found in context"/></add-error>
+        </if-empty>
+        <check-errors/>
+
+        <call-class-method class-name="org.ofbiz.content.data.DataResourceWorker" method-name="getDataResourceContentUploadPath" ret-field-name="uploadPath"/>
+        <log level="info" message="[attachLocalFileToDataResource] - Found Subdir : ${uploadPath}"/>
+
+        <set from-field="parameters._uploadedFile_contentType" field="extenLookup.mimeTypeId"/>
+        <find-by-and entity-name="FileExtension" map-name="extenLookup" list-name="extensions"/>
+        <first-from-list entry-name="extension" list-name="extensions"/>
+
+        <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-name="extension">
+            <set value="${uploadPath}/${dataResource.dataResourceId}.${extension.fileExtensionId}" field="dataResource.objectInfo"/>
+        </if-not-empty>
+        <set value="LOCAL_FILE" field="dataResource.dataResourceTypeId"/>
+
+        <set-service-fields service-name="createAnonFile" map-name="dataResource" to-map-name="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"/>
+
+        <store-value value-name="dataResource"/>
+        <field-to-result field-name="dataResourceId" map-name="dataResource"/>
+    </simple-method>
+    
     <!-- This method first creates Content, DataResource and ElectronicText, ImageDataResource, etc. entities (if needed)
  by calling persistContentAndAssoc.
 

Modified: ofbiz/trunk/applications/content/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/servicedef/services.xml?view=diff&rev=493122&r1=493121&r2=493122
==============================================================================
--- ofbiz/trunk/applications/content/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/content/servicedef/services.xml Fri Jan  5 10:30:26 2007
@@ -20,6 +20,14 @@
     <description>Content Component Services</description>
     <vendor>OFBiz</vendor>
 
+    <!-- interfaces -->
+    <service name="uploadFileInterface" engine="interface">
+        <description>Contains necessary paramters for all file upload requests via service event handler</description>
+        <attribute name="uploadedFile" type="org.ofbiz.entity.util.ByteWrapper" mode="IN" optional="true"/>
+        <attribute name="_uploadedFile_fileName" type="String" mode="IN" optional="true"/>
+        <attribute name="_uploadedFile_contentType" type="String" mode="IN" optional="false"/>
+    </service>
+
     <!-- WebSite Services -->
     <service name="createWebSite" default-entity-name="WebSite" engine="simple"
         location="org/ofbiz/content/website/WebSiteServices.xml" invoke="createWebSite" auth="true">
@@ -107,20 +115,30 @@
         <implements service="createContent" optional="false"/>
     </service>
 
-    <service name="createLocalFileContentFromStream" default-entity-name="Content" engine="simple" transaction-timeout="300"
-             location="org/ofbiz/content/content/ContentServices.xml" invoke="createUploadedLocalFileContent">
-        <description>Creates a local file, data resource and content records for an uploaded file</description>
-        <auto-attributes mode="IN" include="nonpk" optional="true"/>
-        <attribute name="uploadedFile" type="org.ofbiz.entity.util.ByteWrapper" mode="IN" optional="true"/>
-        <attribute name="_uploadedFile_fileName" type="String" mode="IN" optional="true"/>
-        <attribute name="_uploadedFile_contentType" type="String" mode="IN" optional="false"/>
-        <attribute name="dataCategoryId" type="String" mode="IN" optional="true"/>
-        <attribute name="statusId" type="String" mode="IN" optional="false"/>
-        <attribute name="partyId" type="String" mode="IN" optional="true"/>
+    <service name="createContentFromDataResource" engine="simple"
+             location="org/ofbiz/content/content/ContentServices.xml" invoke="createContentFromDataResource">
+        <description>Creates content record from data resource and allows all content fields to be set</description>
+        <implements service="createContent" optional="true"/>
+        <attribute name="dataResourceId" type="String" mode="IN" optional="false"/>
         <attribute name="contentId" type="String" mode="OUT" optional="false"/>
-        <override name="contentTypeId" optional="false"/>
     </service>
 
+    <service name="uploadFileToDataResource" engine="simple" transaction-timeout="300"
+             location="org/ofbiz/content/content/ContentServices.xml" invoke="attachLocalFileToDataResource">
+        <description>Accepts uploaded content and attaches to an existing data resource</description>
+        <implements service="uploadFileInterface"/>
+        <attribute name="dataResourceId" type="String" mode="INOUT" optional="false"/>        
+    </service>
+
+    <service name="createContentFromUploadedFile" engine="group" transaction-timeout="300">
+        <description>Accepts file upload, creates DataResource and Content records.</description>
+        <group>
+            <invoke name="createDataResource" parameters="preserve" result-to-context="true"/>
+            <invoke name="uploadFileToDataResource" parameters="preserve" result-to-context="true"/>
+            <invoke name="createContentFromDataResource"/>
+        </group>            
+    </service>
+    
     <service name="copyContentAndElectronicTextandAssoc" default-entity-name="Content" engine="simple"
         location="org/ofbiz/content/content/ContentServices.xml" invoke="copyContentAndElectronicTextandAssoc" transaction-timeout="72000" auth="true" >
         <description>Copy a Content, e;ectronic text and assocs</description>
@@ -198,21 +216,7 @@
         <attribute mode="IN" name="entityOperation" optional="true" type="String"/>
         <attribute mode="OUT" name="contentList" optional="false" type="List"/>
     </service>
-
-    <service name="createLocalFileContentFromStream" default-entity-name="Content" engine="simple" transaction-timeout="300"
-             location="org/ofbiz/content/content/ContentServices.xml" invoke="createUploadedLocalFileContent">
-        <description>Creates a local file, data resource and content records for an uploaded file</description>
-        <auto-attributes mode="IN" include="nonpk" optional="true"/>
-        <attribute name="uploadedFile" type="org.ofbiz.entity.util.ByteWrapper" mode="IN" optional="true"/>
-        <attribute name="_uploadedFile_fileName" type="String" mode="IN" optional="true"/>
-        <attribute name="_uploadedFile_contentType" type="String" mode="IN" optional="false"/>
-        <attribute name="dataCategoryId" type="String" mode="IN" optional="true"/>
-        <attribute name="statusId" type="String" mode="IN" optional="false"/>
-        <attribute name="partyId" type="String" mode="IN" optional="true"/>
-        <attribute name="contentId" type="String" mode="OUT" optional="false"/>
-        <override name="contentTypeId" optional="false"/>        
-    </service>
-
+    
     <!--Content Assoc services.-->
     <service name="checkAssocPermission"
         transaction-timeout="72000"