Revision 1704842b

b/src/gr/ebs/gss/server/ejb/ExternalAPI.java
345 345
	public void deleteFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException;
346 346

  
347 347
	/**
348
	 * Deletes the specified file in the specified user's namespace.
349
	 *
350
	 * @param userId the ID of the current user
351
	 * @param fileIds the IDs of the files to delete
352
	 * @throws ObjectNotFoundException if the user or file was not found, with
353
	 *             the exception message mentioning the precise problem
354
	 * @throws InsufficientPermissionsException if the user does not have the
355
	 *             appropriate privileges
356
	 */
357
	public void deleteFiles(Long userId, List<Long> fileIds)
358
			throws ObjectNotFoundException, InsufficientPermissionsException;
359

  
360
	/**
361 348
	 * Creates a new tag for the specified user and file.
362 349
	 *
363 350
	 * @param userId the creator of the tag
......
648 635
	public void removeFileFromTrash(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException;
649 636

  
650 637
	/**
651
	 * Marks  the specified deleted files as undeleted in the specified user's namespace.
652
	 *
653
	 * @param userId the ID of the current user
654
	 * @param fileIds the IDs of the file to undelete
655
	 * @throws ObjectNotFoundException if the user or file was not found, with
656
	 *             the exception message mentioning the precise problem
657
	 * @throws InsufficientPermissionsException if the user does not have the
658
	 *             appropriate privileges
659
	 */
660
	public void removeFilesFromTrash(Long userId, List<Long> fileIds) throws ObjectNotFoundException, InsufficientPermissionsException;
661

  
662
	/**
663 638
	 * Marks  the specified folder as deleted in the specified user's namespace.
664 639
	 *
665 640
	 * @param userId the ID of the current user
......
1059 1034
			throws ObjectNotFoundException, InsufficientPermissionsException,  GSSIOException, QuotaExceededException;
1060 1035

  
1061 1036
	/**
1062
	 * Remove file version identified by bodyId
1063
	 *
1064
	 * @param userId the ID of the user
1065
	 * @param fileId the ID of the file
1066
	 * @param bodyId the ID of the body
1067
	 *
1068
	 * @throws ObjectNotFoundException
1069
	 * @throws InsufficientPermissionsException
1070
	 *
1071
	 */
1072
	public void removeVersion(Long userId, Long fileId, Long bodyId)
1073
			throws ObjectNotFoundException, InsufficientPermissionsException;
1074

  
1075
	/**
1076 1037
	 * Removes all old file versions for specified file keeping only the current revision
1077 1038
	 *
1078 1039
	 * @param userId the ID of the user
b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java
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");

Also available in: Unified diff