1326 |
1326 |
if (parent == null)
|
1327 |
1327 |
throw new ObjectNotFoundException("The specified file has no parent folder");
|
1328 |
1328 |
User user = dao.getEntityById(User.class, userId);
|
1329 |
|
if (!file.hasDeletePermission(user))
|
1330 |
|
throw new InsufficientPermissionsException("User " + user.getUsername() +
|
1331 |
|
" cannot restore file " + file.getName());
|
1332 |
|
|
1333 |
|
file.setDeleted(false);
|
1334 |
|
dao.update(file);
|
|
1329 |
untrashFile(user, file);
|
1335 |
1330 |
touchParentFolders(parent, user, new Date());
|
1336 |
1331 |
}
|
1337 |
1332 |
|
|
1333 |
private void untrashFile(User user, FileHeader file) throws InsufficientPermissionsException {
|
|
1334 |
if (!file.hasDeletePermission(user))
|
|
1335 |
throw new InsufficientPermissionsException("User " + user.getUsername() +
|
|
1336 |
" cannot restore file " + file.getName());
|
|
1337 |
|
|
1338 |
file.setDeleted(false);
|
|
1339 |
}
|
|
1340 |
|
1338 |
1341 |
@Override
|
1339 |
1342 |
public void moveFolderToTrash(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException {
|
1340 |
1343 |
if (userId == null)
|
... | ... | |
1366 |
1369 |
throw new ObjectNotFoundException("No folder specified");
|
1367 |
1370 |
Folder folder = dao.getEntityById(Folder.class, folderId);
|
1368 |
1371 |
User user = dao.getEntityById(User.class, userId);
|
1369 |
|
if (!folder.hasDeletePermission(user))
|
1370 |
|
throw new InsufficientPermissionsException("User " + user.getUsername() +
|
1371 |
|
" cannot restore folder " + folder.getName());
|
1372 |
|
folder.setDeleted(false);
|
1373 |
|
for (FileHeader file : folder.getFiles())
|
1374 |
|
removeFileFromTrash(userId, file.getId());
|
1375 |
|
for (Folder subFolder : folder.getSubfolders())
|
1376 |
|
removeFolderFromTrash(userId, subFolder.getId());
|
1377 |
|
dao.update(folder);
|
|
1372 |
untrashFolder(user, folder);
|
1378 |
1373 |
touchParentFolders(folder, user, new Date());
|
1379 |
1374 |
}
|
1380 |
1375 |
|
|
1376 |
private void untrashFolder(User user, Folder folder) throws ObjectNotFoundException, InsufficientPermissionsException {
|
|
1377 |
if (!folder.hasDeletePermission(user))
|
|
1378 |
throw new InsufficientPermissionsException("User " + user.getUsername() +
|
|
1379 |
" cannot restore folder " + folder.getName());
|
|
1380 |
folder.setDeleted(false);
|
|
1381 |
for (FileHeader file : folder.getFiles())
|
|
1382 |
untrashFile(user, file);
|
|
1383 |
for (Folder subFolder : folder.getSubfolders())
|
|
1384 |
untrashFolder(user, subFolder);
|
|
1385 |
}
|
|
1386 |
|
1381 |
1387 |
@Override
|
1382 |
1388 |
public List<FolderDTO> getDeletedRootFolders(Long userId) throws ObjectNotFoundException {
|
1383 |
1389 |
List<Folder> folders = dao.getDeletedRootFolders(userId);
|
... | ... | |
1910 |
1916 |
}
|
1911 |
1917 |
|
1912 |
1918 |
@Override
|
1913 |
|
public void deleteFiles(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException {
|
1914 |
|
if (userId == null)
|
1915 |
|
throw new ObjectNotFoundException("No user specified");
|
1916 |
|
final User user = dao.getEntityById(User.class, userId);
|
1917 |
|
List<String> filesToRemove = new ArrayList<String>();
|
1918 |
|
//first delete database objects
|
1919 |
|
for(Long fileId : fileIds){
|
1920 |
|
if (fileId == null)
|
1921 |
|
throw new ObjectNotFoundException("No file specified");
|
1922 |
|
final FileHeader file = dao.getEntityById(FileHeader.class, fileId);
|
1923 |
|
final Folder parent = file.getFolder();
|
1924 |
|
if (parent == null)
|
1925 |
|
throw new ObjectNotFoundException("The specified file has no parent folder");
|
1926 |
|
if (!file.hasDeletePermission(user))
|
1927 |
|
throw new InsufficientPermissionsException("User " + user.getId() + " cannot delete file " + file.getName() + "(" + file.getId() + ")");
|
1928 |
|
|
1929 |
|
parent.removeFile(file);
|
1930 |
|
for (final FileBody body : file.getBodies())
|
1931 |
|
filesToRemove.add(body.getStoredFilePath());
|
1932 |
|
dao.delete(file);
|
1933 |
|
touchParentFolders(parent, user, new Date());
|
1934 |
|
}
|
1935 |
|
//then remove physical files if everything is ok
|
1936 |
|
for(String physicalFileName : filesToRemove)
|
1937 |
|
deleteActualFile(physicalFileName);
|
1938 |
|
//then unindex deleted files
|
1939 |
|
for(Long fileId : fileIds)
|
1940 |
|
indexFile(fileId, true);
|
1941 |
|
|
1942 |
|
}
|
1943 |
|
|
1944 |
|
@Override
|
1945 |
|
public void removeFilesFromTrash(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException {
|
1946 |
|
for(Long l : fileIds)
|
1947 |
|
removeFileFromTrash(userId, l);
|
1948 |
|
|
1949 |
|
}
|
1950 |
|
|
1951 |
|
@Override
|
1952 |
1919 |
public Nonce createNonce(Long userId) throws ObjectNotFoundException {
|
1953 |
1920 |
if (userId == null)
|
1954 |
1921 |
throw new ObjectNotFoundException("No user specified");
|
... | ... | |
2015 |
1982 |
}
|
2016 |
1983 |
|
2017 |
1984 |
@Override
|
2018 |
|
public void removeVersion(Long userId, Long fileId, Long bodyId) throws ObjectNotFoundException, InsufficientPermissionsException {
|
2019 |
|
if (userId == null)
|
2020 |
|
throw new ObjectNotFoundException("No user specified");
|
2021 |
|
if (fileId == null)
|
2022 |
|
throw new ObjectNotFoundException("No file specified");
|
2023 |
|
if (bodyId == null)
|
2024 |
|
throw new ObjectNotFoundException("No body specified");
|
2025 |
|
User user = dao.getEntityById(User.class, userId);
|
2026 |
|
FileHeader header = dao.getEntityById(FileHeader.class, fileId);
|
2027 |
|
if(!header.hasWritePermission(user))
|
2028 |
|
throw new InsufficientPermissionsException("You don't have the necessary permissions");
|
2029 |
|
FileBody body = dao.getEntityById(FileBody.class, bodyId);
|
2030 |
|
if(body.equals(header.getCurrentBody())){
|
2031 |
|
|
2032 |
|
if(header.getBodies().size() == 1)
|
2033 |
|
throw new InsufficientPermissionsException("You cant delete this version, Delete file instead!");
|
2034 |
|
for(FileBody b : header.getBodies())
|
2035 |
|
if(b.getVersion() == body.getVersion()-1)
|
2036 |
|
header.setCurrentBody(b);
|
2037 |
|
}
|
2038 |
|
deleteActualFile(body.getStoredFilePath());
|
2039 |
|
header.getBodies().remove(body);
|
2040 |
|
|
2041 |
|
Folder parent = header.getFolder();
|
2042 |
|
touchParentFolders(parent, user, new Date());
|
2043 |
|
|
2044 |
|
}
|
2045 |
|
|
2046 |
|
@Override
|
2047 |
1985 |
public void restoreVersion(Long userId, Long fileId, int version) throws ObjectNotFoundException, InsufficientPermissionsException, GSSIOException, QuotaExceededException {
|
2048 |
1986 |
if (userId == null)
|
2049 |
1987 |
throw new ObjectNotFoundException("No user specified");
|