@Transactional public Document getDocumentByPath(String path, User user) throws InsufficientPrivilagesException { int lastSlash = path.lastIndexOf('/'); String folderPath = path.substring(0, lastSlash); Folder f = folderDao.getFolderByPath(folderPath, user); if (!f.canRead(user)) throw new InsufficientPrivilagesException(); Document doc = f.getDocumentByName(path.substring(lastSlash + 1)); return doc; }
@Transactional public void deleteDocument(String path, User user) throws InsufficientPrivilagesException { String folderPath = path.substring(0, path.lastIndexOf('/')); Folder f = getFolderByPath(folderPath, user); if (!f.getOwner().getUsername().equals(user.getUsername()) && !f.canWrite(user)) throw new InsufficientPrivilagesException( "User " + user + " does not have permission to delete documents from this folder"); Document doc = f.getDocumentByName(path.substring(path.lastIndexOf('/') + 1)); File docFile = new File(docsFolderPath + doc.getUuid()); f.removeDocument(doc); documentDao.makeTransient(doc); docFile.delete(); }