From: Christos V. Stathis Date: Tue, 18 Jan 2011 16:21:49 +0000 (+0200) Subject: Avoid unnecessary calls to touchParentFolders when moving resources to trash X-Git-Tag: pithos/v0.7.8~323^2~14^2~81^2^2~4 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/a0b9d31e60846c6db667fae23499370b2bb09a2c Avoid unnecessary calls to touchParentFolders when moving resources to trash --- diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPI.java b/src/gr/ebs/gss/server/ejb/ExternalAPI.java index 790a22f..a1df8a0 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPI.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPI.java @@ -648,19 +648,6 @@ public interface ExternalAPI { public void removeFileFromTrash(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException; /** - * Marks the specified files as deleted in the specified user's namespace. - * - * @param userId the ID of the current user - * @param fileIds the IDs of the file to delete - * @throws ObjectNotFoundException if the user or file was not found, with - * the exception message mentioning the precise problem - * @throws InsufficientPermissionsException if the user does not have the - * appropriate privileges - */ - public void moveFilesToTrash(Long userId, List fileIds) - throws ObjectNotFoundException, InsufficientPermissionsException; - - /** * Marks the specified deleted files as undeleted in the specified user's namespace. * * @param userId the ID of the current user diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java index eca69be..7f78ab1 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java @@ -19,6 +19,8 @@ package gr.ebs.gss.server.ejb; import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration; + +import gr.ebs.gss.admin.client.ui.UsersTable; import gr.ebs.gss.client.exceptions.DuplicateNameException; import gr.ebs.gss.client.exceptions.GSSIOException; import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; @@ -1143,14 +1145,17 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { if (parent == null) throw new ObjectNotFoundException("The specified file has no parent folder"); User user = dao.getEntityById(User.class, userId); - if (!file.hasDeletePermission(user)) - throw new InsufficientPermissionsException("User " + user.getId() + " cannot delete file " + file.getName() + "(" + file.getId() + ")"); - - file.setDeleted(true); - dao.update(file); - touchParentFolders(parent, user, new Date()); + trashFile(user, file); + touchParentFolders(parent, user, new Date()); } + private void trashFile(User user, FileHeader file) throws InsufficientPermissionsException { + if (!file.hasDeletePermission(user)) + throw new InsufficientPermissionsException("User " + user.getId() + " cannot delete file " + file.getName() + "(" + file.getId() + ")"); + + file.setDeleted(true); + } + @Override public void moveFileToPath(Long userId, Long ownerId, Long fileId, String dest) throws ObjectNotFoundException, InsufficientPermissionsException, QuotaExceededException { if (userId == null) @@ -1332,23 +1337,25 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { @Override public void moveFolderToTrash(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException { - if (userId == null) - throw new ObjectNotFoundException("No user specified"); - if (folderId == null) - throw new ObjectNotFoundException("No folder specified"); - Folder folder = dao.getEntityById(Folder.class, folderId); - User user = dao.getEntityById(User.class, userId); - if (!folder.hasDeletePermission(user)) - 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()) - moveFolderToTrash(userId, subFolder.getId()); - - } + if (userId == null) + throw new ObjectNotFoundException("No user specified"); + if (folderId == null) + throw new ObjectNotFoundException("No folder specified"); + Folder folder = dao.getEntityById(Folder.class, folderId); + User user = dao.getEntityById(User.class, userId); + trashFolder(user, folder); + touchParentFolders(folder, user, new Date()); + } + + private void trashFolder(User user, Folder folder) throws ObjectNotFoundException, InsufficientPermissionsException { + if (!folder.hasDeletePermission(user)) + throw new InsufficientPermissionsException("You don't have the necessary permissions"); + folder.setDeleted(true); + for (FileHeader file : folder.getFiles()) + trashFile(user, file); + for (Folder subFolder : folder.getSubfolders()) + trashFolder(user, subFolder); + } @Override public void removeFolderFromTrash(Long userId, Long folderId) @@ -1935,13 +1942,6 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public void moveFilesToTrash(Long userId, List fileIds) throws ObjectNotFoundException, InsufficientPermissionsException { - for(Long l : fileIds) - moveFileToTrash(userId, l); - - } - - @Override public void removeFilesFromTrash(Long userId, List fileIds) throws ObjectNotFoundException, InsufficientPermissionsException { for(Long l : fileIds) removeFileFromTrash(userId, l);