Fix a typo.
[pithos] / src / gr / ebs / gss / server / ejb / ExternalAPIBean.java
index dd47a17..28af26a 100644 (file)
@@ -299,7 +299,6 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
         * @param name
         * @param parent
         * @param creator
         * @param name
         * @param parent
         * @param creator
-        * @param owner
         */
        private void createFolder(String name, Folder parent, User creator) {
                Folder folder = new Folder();
         */
        private void createFolder(String name, Folder parent, User creator) {
                Folder folder = new Folder();
@@ -1249,6 +1248,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                auditInfo.setModificationDate(now);
                user.setAuditInfo(auditInfo);
                user.generateAuthToken();
                auditInfo.setModificationDate(now);
                user.setAuditInfo(auditInfo);
                user.generateAuthToken();
+               user.generateWebDAVPassword();
                dao.create(user);
                // Make sure we get an ID in the user object.
                dao.flush();
                dao.create(user);
                // Make sure we get an ID in the user object.
                dao.flush();
@@ -1333,10 +1333,15 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                Folder folder = dao.getEntityById(Folder.class, folderId);
                if(!folder.hasModifyACLPermission(user))
                        throw new InsufficientPermissionsException("You don't have the necessary permissions");
                Folder folder = dao.getEntityById(Folder.class, folderId);
                if(!folder.hasModifyACLPermission(user))
                        throw new InsufficientPermissionsException("You don't have the necessary permissions");
+               // Delete previous entries
+               for (Permission perm: folder.getPermissions())
+                       dao.delete(perm);
                folder.getPermissions().clear();
                for (PermissionDTO dto : permissions) {
                        if (dto.getUser()!=null && dto.getUser().getId().equals(folder.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
                                        throw new InsufficientPermissionsException("Can't remove permissions from owner");
                folder.getPermissions().clear();
                for (PermissionDTO dto : permissions) {
                        if (dto.getUser()!=null && dto.getUser().getId().equals(folder.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
                                        throw new InsufficientPermissionsException("Can't remove permissions from owner");
+                       // Don't include 'empty' permission
+                       if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue;
                        folder.addPermission(getPermission(dto));
                }
                dao.update(folder);
                        folder.addPermission(getPermission(dto));
                }
                dao.update(folder);
@@ -1500,19 +1505,24 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        else
                                throw new InsufficientPermissionsException("Only the owner can change the read-for-all flag");
 
                        else
                                throw new InsufficientPermissionsException("Only the owner can change the read-for-all flag");
 
-               if (permissions != null && !permissions.isEmpty()) {
-                       file.getPermissions().clear();
-                       for (PermissionDTO dto : permissions) {
-                               if (dto.getUser()!=null && dto.getUser().getId().equals(file.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
-                                       throw new InsufficientPermissionsException("Can't remove permissions from owner");
-                               file.addPermission(getPermission(dto));
+               // Update the file if there was a change.
+               if (readForAll != null || permissions != null && !permissions.isEmpty()) {
+                       if (permissions != null && !permissions.isEmpty()) {
+                               // Delete previous entries
+                               for (Permission perm: file.getPermissions())
+                                       dao.delete(perm);
+                               file.getPermissions().clear();
+                               for (PermissionDTO dto : permissions) {
+                                       if (dto.getUser()!=null && dto.getUser().getId().equals(file.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
+                                               throw new InsufficientPermissionsException("Can't remove permissions from owner");
+                                       // Don't include 'empty' permission
+                                       if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue;
+                                       file.addPermission(getPermission(dto));
+                               }
                        }
                        }
-               }
 
 
-               // Update the file if there was a change.
-               if (readForAll != null || permissions != null && !permissions.isEmpty())
                        dao.update(file);
                        dao.update(file);
-
+               }
        }
 
        @Override
        }
 
        @Override
@@ -1991,13 +2001,13 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
 
        /**
         * Gets the quota for specified userId
 
        /**
         * Gets the quota for specified userId
-     * @param userId
-     * @return
-     */
-    private Long getQuota(@SuppressWarnings("unused") Long userId){
-        Long quota = getConfiguration().getLong("quota", new Long(52428800L));
-        return quota;
-    }
+        * @param userId
+        * @return
+        */
+       private Long getQuota(@SuppressWarnings("unused") Long userId){
+               Long quota = getConfiguration().getLong("quota", new Long(52428800L));
+               return quota;
+       }
 
        public void rebuildSolrIndex() {
                MessageProducer sender = null;
 
        public void rebuildSolrIndex() {
                MessageProducer sender = null;
@@ -2270,6 +2280,16 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
        private void createFileBody(String name, String mimeType, File uploadedFile,
                                FileHeader header, AuditInfo auditInfo, User owner)
                        throws FileNotFoundException, QuotaExceededException {
        private void createFileBody(String name, String mimeType, File uploadedFile,
                                FileHeader header, AuditInfo auditInfo, User owner)
                        throws FileNotFoundException, QuotaExceededException {
+
+               long currentTotalSize = 0;
+               if (!header.isVersioned() && header.getCurrentBody() != null && header.getBodies() != null)
+                       currentTotalSize = header.getTotalSize();
+               Long quotaLeft = getQuotaLeft(header.getOwner().getId());
+               if(quotaLeft < uploadedFile.length()-currentTotalSize) {
+                       uploadedFile.delete();
+                       throw new QuotaExceededException("Not enough free space available");
+               }
+
                FileBody body = new FileBody();
 
                // if no mime type or the generic mime type is defined by the client, then try to identify it from the filename extension
                FileBody body = new FileBody();
 
                // if no mime type or the generic mime type is defined by the client, then try to identify it from the filename extension
@@ -2278,7 +2298,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                                        || "octet/stream".equals(mimeType) || "application/unknown".equals(mimeType))
                        body.setMimeType(identifyMimeType(name));
                else
                                        || "octet/stream".equals(mimeType) || "application/unknown".equals(mimeType))
                        body.setMimeType(identifyMimeType(name));
                else
-               body.setMimeType(mimeType);
+                       body.setMimeType(mimeType);
                body.setAuditInfo(auditInfo);
                body.setFileSize(uploadedFile.length());
                body.setOriginalFilename(name);
                body.setAuditInfo(auditInfo);
                body.setFileSize(uploadedFile.length());
                body.setOriginalFilename(name);
@@ -2299,9 +2319,6 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        }
                }
 
                        }
                }
 
-               Long quotaLeft = getQuotaLeft(owner.getId());
-               if(quotaLeft < uploadedFile.length())
-                       throw new QuotaExceededException("Not enough free space available");
                dao.flush();
                header.addBody(body);
 
                dao.flush();
                header.addBody(body);
 
@@ -2460,4 +2477,20 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                return true;
        }
 
                return true;
        }
 
+       /**
+        * Reset WebDAV password for given user.
+        *
+        * @param userId
+        * @return the new password
+        * @throws ObjectNotFoundException
+        */
+       @Override
+       public String resetWebDAVPassword(Long userId) throws ObjectNotFoundException {
+               if (userId == null)
+                       throw new ObjectNotFoundException("No user specified");
+               User user = dao.getEntityById(User.class, userId);
+               user.generateWebDAVPassword();
+               return user.getWebDAVPassword();
+       }
+
 }
 }