Change to folder modification semantics: When anything inside a folder is updated...
[pithos] / src / gr / ebs / gss / server / ejb / ExternalAPIBean.java
index 3262ae7..da10aa0 100644 (file)
@@ -139,6 +139,17 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
         */
        private static Random random = new Random();
 
         */
        private static Random random = new Random();
 
+       private void touchParentFolders(Folder folder, User modifiedBy, Date modificationDate) {
+               Folder f = folder;
+               while (f!=null) {
+                       AuditInfo ai = f.getAuditInfo();
+                       ai.setModifiedBy(modifiedBy);
+                       ai.setModificationDate(modificationDate);
+                       f.setAuditInfo(ai);
+                       f = f.getParent();
+               }
+       }
+
        @Override
        public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException {
                if (userId == null)
        @Override
        public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException {
                if (userId == null)
@@ -264,7 +275,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
        }
 
        @Override
        }
 
        @Override
-       public void createFolder(Long userId, Long parentId, String name)
+       public FolderDTO createFolder(Long userId, Long parentId, String name)
                        throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException {
                // Validate.
                if (userId == null)
                        throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException {
                // Validate.
                if (userId == null)
@@ -291,7 +302,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                                        " to write to this folder");
 
                // Do the actual work.
                                        " to write to this folder");
 
                // Do the actual work.
-               createFolder(name, parent, creator);
+               return createFolder(name, parent, creator);
        }
 
        /**
        }
 
        /**
@@ -300,8 +311,9 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
         * @param name
         * @param parent
         * @param creator
         * @param name
         * @param parent
         * @param creator
+        * @return the new folder
         */
         */
-       private void createFolder(String name, Folder parent, User creator) {
+       private FolderDTO createFolder(String name, Folder parent, User creator) {
                Folder folder = new Folder();
                folder.setName(name);
                if (parent != null) {
                Folder folder = new Folder();
                folder.setName(name);
                if (parent != null) {
@@ -317,6 +329,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                auditInfo.setModifiedBy(creator);
                auditInfo.setModificationDate(now);
                folder.setAuditInfo(auditInfo);
                auditInfo.setModifiedBy(creator);
                auditInfo.setModificationDate(now);
                folder.setAuditInfo(auditInfo);
+               touchParentFolders(folder, auditInfo.getModifiedBy(), auditInfo.getModificationDate());
 
                if (parent != null)
                        for (Permission p : parent.getPermissions()) {
 
                if (parent != null)
                        for (Permission p : parent.getPermissions()) {
@@ -337,6 +350,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        folder.addPermission(permission);
                }
                dao.create(folder);
                        folder.addPermission(permission);
                }
                dao.create(folder);
+               return folder.getDTO();
        }
 
        /*
        }
 
        /*
@@ -366,6 +380,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                removeSubfolderFiles(folder);
                parent.removeSubfolder(folder);
                dao.delete(folder);
                removeSubfolderFiles(folder);
                parent.removeSubfolder(folder);
                dao.delete(folder);
+               touchParentFolders(parent, user, new Date());
        }
 
        /**
        }
 
        /**
@@ -430,6 +445,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                // Do the actual modification.
                folder.setName(folderName);
                dao.update(folder);
                // Do the actual modification.
                folder.setName(folderName);
                dao.update(folder);
+               touchParentFolders(folder, user, new Date());
                return folder.getDTO();
        }
 
                return folder.getDTO();
        }
 
@@ -445,6 +461,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        throw new ObjectNotFoundException("No user specified");
                if (StringUtils.isEmpty(name))
                        throw new ObjectNotFoundException("New group name is empty");
                        throw new ObjectNotFoundException("No user specified");
                if (StringUtils.isEmpty(name))
                        throw new ObjectNotFoundException("New group name is empty");
+               if (name.indexOf('/')>=0)
+                       throw new IllegalArgumentException("Character '/' is not allowed in group name");
                if (dao.existsGroup(userId, name))
                        throw new DuplicateNameException("A group with the name '" + name + "' already exists");
 
                if (dao.existsGroup(userId, name))
                        throw new DuplicateNameException("A group with the name '" + name + "' already exists");
 
@@ -595,6 +613,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                for (final FileBody body : file.getBodies())
                        deleteActualFile(body.getStoredFilePath());
                dao.delete(file);
                for (final FileBody body : file.getBodies())
                        deleteActualFile(body.getStoredFilePath());
                dao.delete(file);
+               touchParentFolders(parent, user, new Date());
                indexFile(fileId, true);
        }
 
                indexFile(fileId, true);
        }
 
@@ -622,7 +641,11 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
 
                final User user = dao.getEntityById(User.class, userId);
                final FileHeader fh = dao.getEntityById(FileHeader.class, fileHeaderId);
 
                final User user = dao.getEntityById(User.class, userId);
                final FileHeader fh = dao.getEntityById(FileHeader.class, fileHeaderId);
+               final Folder parent = fh.getFolder();
+               if (parent == null)
+                       throw new ObjectNotFoundException("The specified file has no parent folder");
                user.addTag(fh, tag);
                user.addTag(fh, tag);
+               touchParentFolders(parent, user, new Date());
        }
 
        /* (non-Javadoc)
        }
 
        /* (non-Javadoc)
@@ -642,6 +665,10 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                if (fileId == null)
                        throw new ObjectNotFoundException("No file specified");
                FileHeader file = dao.getEntityById(FileHeader.class, fileId);
                if (fileId == null)
                        throw new ObjectNotFoundException("No file specified");
                FileHeader file = dao.getEntityById(FileHeader.class, fileId);
+               final Folder parent = file.getFolder();
+               if (parent == null)
+                       throw new ObjectNotFoundException("The specified file has no parent folder");
+
                User user = dao.getEntityById(User.class, userId);
                if (!file.hasWritePermission(user))
                        throw new InsufficientPermissionsException("User " + user.getId() + " cannot update file " + file.getName() + "(" + file.getId() + ")");
                User user = dao.getEntityById(User.class, userId);
                if (!file.hasWritePermission(user))
                        throw new InsufficientPermissionsException("User " + user.getId() + " cannot update file " + file.getName() + "(" + file.getId() + ")");
@@ -664,6 +691,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        while (st.hasMoreTokens())
                                new FileTag(user, file, st.nextToken().trim());
                }
                        while (st.hasMoreTokens())
                                new FileTag(user, file, st.nextToken().trim());
                }
+               touchParentFolders(parent, user, new Date());
 
                // Re-index the file if it was modified.
                if (name != null || tagSet != null)
 
                // Re-index the file if it was modified.
                if (name != null || tagSet != null)
@@ -1079,6 +1107,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
 
                file.setDeleted(true);
                dao.update(file);
 
                file.setDeleted(true);
                dao.update(file);
+               touchParentFolders(parent, user, new Date());
        }
 
        @Override
        }
 
        @Override
@@ -1111,6 +1140,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        throw new ObjectNotFoundException("No destination file name specified");
 
                FileHeader file = dao.getEntityById(FileHeader.class, fileId);
                        throw new ObjectNotFoundException("No destination file name specified");
 
                FileHeader file = dao.getEntityById(FileHeader.class, fileId);
+               Folder source = file.getFolder();
                Folder destination = dao.getEntityById(Folder.class, destId);
 
                User owner = dao.getEntityById(User.class, userId);
                Folder destination = dao.getEntityById(Folder.class, destId);
 
                User owner = dao.getEntityById(User.class, userId);
@@ -1144,6 +1174,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                }
                // move the file to the destination folder
                file.setFolder(destination);
                }
                // move the file to the destination folder
                file.setFolder(destination);
+               touchParentFolders(source, owner, new Date());
+               touchParentFolders(destination, owner, new Date());
        }
 
        @Override
        }
 
        @Override
@@ -1208,6 +1240,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
 
                file.setDeleted(false);
                dao.update(file);
 
                file.setDeleted(false);
                dao.update(file);
+               touchParentFolders(parent, user, new Date());
        }
 
        @Override
        }
 
        @Override
@@ -1222,6 +1255,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        throw new InsufficientPermissionsException("You don't have the necessary permissions");
                folder.setDeleted(true);
                dao.update(folder);
                        throw new InsufficientPermissionsException("You don't have the necessary permissions");
                folder.setDeleted(true);
                dao.update(folder);
+               touchParentFolders(folder, user, new Date());
                for (FileHeader file : folder.getFiles())
                        moveFileToTrash(userId, file.getId());
                for (Folder subFolder : folder.getSubfolders())
                for (FileHeader file : folder.getFiles())
                        moveFileToTrash(userId, file.getId());
                for (Folder subFolder : folder.getSubfolders())
@@ -1247,6 +1281,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                for (Folder subFolder : folder.getSubfolders())
                        removeFolderFromTrash(userId, subFolder.getId());
                dao.update(folder);
                for (Folder subFolder : folder.getSubfolders())
                        removeFolderFromTrash(userId, subFolder.getId());
                dao.update(folder);
+               touchParentFolders(folder, user, new Date());
        }
 
        @Override
        }
 
        @Override
@@ -1569,6 +1604,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        }
 
                        dao.update(file);
                        }
 
                        dao.update(file);
+                       Folder parent = file.getFolder();
+                       touchParentFolders(parent, user, new Date());
                }
        }
 
                }
        }
 
@@ -1831,6 +1868,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        for (final FileBody body : file.getBodies())
                                filesToRemove.add(body.getStoredFilePath());
                        dao.delete(file);
                        for (final FileBody body : file.getBodies())
                                filesToRemove.add(body.getStoredFilePath());
                        dao.delete(file);
+                       touchParentFolders(parent, user, new Date());
                }
                //then remove physical files if everything is ok
                for(String physicalFileName : filesToRemove)
                }
                //then remove physical files if everything is ok
                for(String physicalFileName : filesToRemove)
@@ -1957,6 +1995,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                deleteActualFile(body.getStoredFilePath());
                header.getBodies().remove(body);
 
                deleteActualFile(body.getStoredFilePath());
                header.getBodies().remove(body);
 
+               Folder parent = header.getFolder();
+               touchParentFolders(parent, user, new Date());
 
        }
 
 
        }
 
@@ -2005,6 +2045,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                }
                header.getCurrentBody().setVersion(1);
 
                }
                header.getCurrentBody().setVersion(1);
 
+               Folder parent = header.getFolder();
+               touchParentFolders(parent, user, new Date());
        }
 
        /* (non-Javadoc)
        }
 
        /* (non-Javadoc)
@@ -2024,7 +2066,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        if(header.isVersioned())
                                removeOldVersions(userId, fileId);
                        header.setVersioned(versioned);
                        if(header.isVersioned())
                                removeOldVersions(userId, fileId);
                        header.setVersioned(versioned);
-
+                       Folder parent = header.getFolder();
+                       touchParentFolders(parent, user, new Date());
                }
        }
 
                }
        }
 
@@ -2239,6 +2282,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                } catch (FileNotFoundException e) {
                        throw new GSSIOException(e);
                }
                } catch (FileNotFoundException e) {
                        throw new GSSIOException(e);
                }
+               touchParentFolders(parent, owner, new Date());
                dao.flush();
                indexFile(file.getId(), false);
 
                dao.flush();
                indexFile(file.getId(), false);
 
@@ -2277,6 +2321,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                } catch (FileNotFoundException e) {
                        throw new GSSIOException(e);
                }
                } catch (FileNotFoundException e) {
                        throw new GSSIOException(e);
                }
+               Folder parent = file.getFolder();
+               touchParentFolders(parent, owner, new Date());
 
                indexFile(fileId, false);
                return file.getDTO();
 
                indexFile(fileId, false);
                return file.getDTO();