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<Long> 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
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;
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)
@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)
}
@Override
- public void moveFilesToTrash(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException {
- for(Long l : fileIds)
- moveFileToTrash(userId, l);
-
- }
-
- @Override
public void removeFilesFromTrash(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException {
for(Long l : fileIds)
removeFileFromTrash(userId, l);