Move file uploads via WebDAV and PUT API calls out of the transaction boundary, so...
authorpastith <devnull@localhost>
Tue, 26 May 2009 10:00:58 +0000 (10:00 +0000)
committerpastith <devnull@localhost>
Tue, 26 May 2009 10:00:58 +0000 (10:00 +0000)
gss/src/gr/ebs/gss/server/ejb/ExternalAPI.java
gss/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java
gss/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java
gss/src/gr/ebs/gss/server/rest/FilesHandler.java
gss/src/gr/ebs/gss/server/soap/WSAPIBean.java
gss/src/gr/ebs/gss/server/webdav/Webdav.java

index c97a3d8..3cdfcee 100644 (file)
@@ -458,25 +458,6 @@ public interface ExternalAPI {
                        throws ObjectNotFoundException;
 
        /**
-        * Create a new FileBody with the supplied contents and make it the current body
-        * of the file.
-        *
-        * @param userId the ID of the current user
-        * @param fileId the ID of the file header object
-        * @param mimeType the content type of the file
-        * @param resourceInputStream a stream of the file contents
-        * @return The FileHeaderDTO created
-        * @throws ObjectNotFoundException if the user or file was not found, with
-        *                      the exception message mentioning the precise problem
-        * @throws GSSIOException if there was an error while storing the file contents
-        * @throws InsufficientPermissionsException
-        * @throws QuotaExceededException
-        */
-       public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType,
-                               InputStream resourceInputStream) throws ObjectNotFoundException,
-                               GSSIOException, InsufficientPermissionsException, QuotaExceededException;
-
-       /**
         * Copy the provided file to the specified destination.
         *
         * @param userId the ID of the current user
index 37b1f19..6adcf34 100644 (file)
@@ -811,8 +811,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                return folder.getDTO();
        }
 
-       @Override
-       public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
+       private FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
                File file = null;
                try {
                        file = uploadFile(resourceInputStream, userId);
index 60de9d5..e3b52bc 100644 (file)
@@ -347,22 +347,6 @@ public interface ExternalAPIRemote {
                        throws ObjectNotFoundException;
 
        /**
-        * Create a new FileBody with the supplied contents and make it the current body
-        * of the file.
-        *
-        * @param userId the ID of the current user
-        * @param fileId the ID of the file header object
-        * @param mimeType the content type of the file
-        * @param resourceInputStream a stream of the file contents
-        * @return The FileHeaderDTO updated
-        * @throws ObjectNotFoundException if the user or file was not found, with
-        *                      the exception message mentioning the precise problem
-        * @throws GSSIOException if there was an error while storing the file contents
-        * @throws InsufficientPermissionsException
-        */
-       public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException;
-
-       /**
         * Copy the provided file to the specified destination.
         *
         * @param userId the ID of the current user
index e1e8ebe..cfc6c01 100644 (file)
@@ -1470,12 +1470,17 @@ public class FilesHandler extends RequestHandler {
                        folder = (FolderDTO) parent;
                String name = getLastElement(path);
                String mimeType = context.getMimeType(name);
-            // FIXME: Add attributes
+               File uploadedFile = null;
+               try {
+                               uploadedFile = getService().uploadFile(resourceInputStream, user.getId());
+                       } catch (IOException ex) {
+                               throw new GSSIOException(ex, false);
+                       }
                FileHeaderDTO fileDTO = null;
             if (exists)
-               fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, resourceInputStream);
+               fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, uploadedFile);
                        else
-                               fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, resourceInputStream);
+                               fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, uploadedFile);
             getService().updateAccounting(user, new Date(), fileDTO.getFileSize());
                        getService().removeFileUploadProgress(user.getId(), fileDTO.getName());
         } catch(ObjectNotFoundException e) {
index 569b749..bc5acb2 100644 (file)
@@ -381,13 +381,15 @@ public class WSAPIBean implements WSAPIRemote{
        @XmlMimeType(value = "application/octet-stream")
        @Override
        public void updateFileContents(@WebParam(name="userId") Long userId, @WebParam(name="fileId") Long fileId, @WebParam(name="mimeType") String mimeType, @WebParam(name="resourceStream") DataHandler resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
-               try {
-                       FileHeaderDTO file = api.updateFileContents(userId, fileId, mimeType, resourceInputStream.getInputStream());
-                       User user = api.getUser(userId);
-                       api.updateAccounting(user, new Date(), file.getFileSize());
-               } catch (IOException e) {
-                       throw new GSSIOException(e);
+       File uploadedFile = null;
+       try {
+                       uploadedFile = api.uploadFile(resourceInputStream.getInputStream(), userId);
+               } catch (IOException ex) {
+                       throw new GSSIOException(ex, false);
                }
+               FileHeaderDTO file = api.updateFileContents(userId, fileId, mimeType, uploadedFile);
+               User user = api.getUser(userId);
+               api.updateAccounting(user, new Date(), file.getFileSize());
        }
 
        /* (non-Javadoc)
index ecc21bf..ed03a9d 100644 (file)
@@ -731,12 +731,18 @@ public class Webdav extends HttpServlet {
                        folder = (FolderDTO) parent;
                        String name = getLastElement(path);
                        String mimeType = getServletContext().getMimeType(name);
+               File uploadedFile = null;
+               try {
+                               uploadedFile = getService().uploadFile(resourceInputStream, user.getId());
+                       } catch (IOException ex) {
+                               throw new GSSIOException(ex, false);
+                       }
                        // FIXME: Add attributes
                        FileHeaderDTO fileDTO = null;
                        if (exists)
-                               fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, resourceInputStream);
+                               fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, uploadedFile);
                        else
-                               fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, resourceInputStream);
+                               fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, uploadedFile);
                        getService().updateAccounting(user, new Date(), fileDTO.getFileSize());
                } catch (ObjectNotFoundException e) {
                        result = false;