- public List<FileBodyDTO> getVersions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException {
- if (userId == null)
- throw new ObjectNotFoundException("No user specified");
- if (fileId == null)
- throw new ObjectNotFoundException("No file specified");
- User user = dao.getEntityById(User.class, userId);
- FileHeader header = dao.getEntityById(FileHeader.class, fileId);
- if(!header.hasReadPermission(user))
- throw new InsufficientPermissionsException("You don't have the necessary permissions");
- List<FileBodyDTO> result = new LinkedList<FileBodyDTO>();
- for(int i = header.getBodies().size()-1 ; i>=0; i--)
- result.add(header.getBodies().get(i).getDTO());
- return result;
- }
-
- @Override
- public void removeVersion(Long userId, Long fileId, Long bodyId) throws ObjectNotFoundException, InsufficientPermissionsException {
- if (userId == null)
- throw new ObjectNotFoundException("No user specified");
- if (fileId == null)
- throw new ObjectNotFoundException("No file specified");
- if (bodyId == null)
- throw new ObjectNotFoundException("No body specified");
- User user = dao.getEntityById(User.class, userId);
- FileHeader header = dao.getEntityById(FileHeader.class, fileId);
- if(!header.hasWritePermission(user))
- throw new InsufficientPermissionsException("You don't have the necessary permissions");
- FileBody body = dao.getEntityById(FileBody.class, bodyId);
- if(body.equals(header.getCurrentBody())){
-
- if(header.getBodies().size() == 1)
- throw new InsufficientPermissionsException("You cant delete this version, Delete file instead!");
- for(FileBody b : header.getBodies())
- if(b.getVersion() == body.getVersion()-1)
- header.setCurrentBody(b);
- }
- deleteActualFile(body.getStoredFilePath());
- header.getBodies().remove(body);
-
- Folder parent = header.getFolder();
- touchParentFolders(parent, user, new Date());
-
- }
-
- @Override