import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
*/
private static Random random = new Random();
+ private void touchParentFolders(Folder folder, User modifiedBy, Date modificationDate) {
+ Folder f = folder;
+ while (f!=null) {
+ AuditInfo ai = f.getAuditInfo();
+ ai.setModifiedBy(modifiedBy);
+ ai.setModificationDate(modificationDate);
+ f.setAuditInfo(ai);
+ f = f.getParent();
+ }
+ }
+
@Override
public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException {
if (userId == null)
}
@Override
- public void createFolder(Long userId, Long parentId, String name)
+ public FolderDTO createFolder(Long userId, Long parentId, String name)
throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException {
// Validate.
if (userId == null)
" to write to this folder");
// Do the actual work.
- createFolder(name, parent, creator);
+ return createFolder(name, parent, creator);
}
/**
* @param name
* @param parent
* @param creator
+ * @return the new folder
*/
- private void createFolder(String name, Folder parent, User creator) {
+ private FolderDTO createFolder(String name, Folder parent, User creator) {
Folder folder = new Folder();
folder.setName(name);
if (parent != null) {
auditInfo.setModifiedBy(creator);
auditInfo.setModificationDate(now);
folder.setAuditInfo(auditInfo);
+ touchParentFolders(folder, auditInfo.getModifiedBy(), auditInfo.getModificationDate());
if (parent != null)
for (Permission p : parent.getPermissions()) {
folder.addPermission(permission);
}
dao.create(folder);
+ return folder.getDTO();
}
/*
removeSubfolderFiles(folder);
parent.removeSubfolder(folder);
dao.delete(folder);
+ touchParentFolders(parent, user, new Date());
}
/**
}
@Override
- public void modifyFolder(Long userId, Long folderId, String folderName)
+ public FolderDTO modifyFolder(Long userId, Long folderId, String folderName)
throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException {
// Validate.
// Do the actual modification.
folder.setName(folderName);
dao.update(folder);
+ touchParentFolders(folder, user, new Date());
+ return folder.getDTO();
}
/*
throw new ObjectNotFoundException("No user specified");
if (StringUtils.isEmpty(name))
throw new ObjectNotFoundException("New group name is empty");
+ if (name.indexOf('/')>=0)
+ throw new IllegalArgumentException("Character '/' is not allowed in group name");
if (dao.existsGroup(userId, name))
throw new DuplicateNameException("A group with the name '" + name + "' already exists");
for (final FileBody body : file.getBodies())
deleteActualFile(body.getStoredFilePath());
dao.delete(file);
+ touchParentFolders(parent, user, new Date());
indexFile(fileId, true);
}
final User user = dao.getEntityById(User.class, userId);
final FileHeader fh = dao.getEntityById(FileHeader.class, fileHeaderId);
+ final Folder parent = fh.getFolder();
+ if (parent == null)
+ throw new ObjectNotFoundException("The specified file has no parent folder");
user.addTag(fh, tag);
+ touchParentFolders(parent, user, new Date());
}
/* (non-Javadoc)
if (fileId == null)
throw new ObjectNotFoundException("No file specified");
FileHeader file = dao.getEntityById(FileHeader.class, fileId);
+ final Folder parent = file.getFolder();
+ if (parent == null)
+ throw new ObjectNotFoundException("The specified file has no parent folder");
+
User user = dao.getEntityById(User.class, userId);
if (!file.hasWritePermission(user))
throw new InsufficientPermissionsException("User " + user.getId() + " cannot update file " + file.getName() + "(" + file.getId() + ")");
while (st.hasMoreTokens())
new FileTag(user, file, st.nextToken().trim());
}
+ touchParentFolders(parent, user, new Date());
// Re-index the file if it was modified.
if (name != null || tagSet != null)
file.setDeleted(true);
dao.update(file);
+ touchParentFolders(parent, user, new Date());
}
@Override
- public void moveFileToPath(Long userId, Long ownerId, Long fileId, String dest) throws ObjectNotFoundException, InsufficientPermissionsException, DuplicateNameException, GSSIOException, QuotaExceededException {
+ public void moveFileToPath(Long userId, Long ownerId, Long fileId, String dest) throws ObjectNotFoundException, InsufficientPermissionsException, QuotaExceededException {
if (userId == null)
throw new ObjectNotFoundException("No user specified");
if (ownerId == null)
throw new ObjectNotFoundException("No destination file name specified");
FileHeader file = dao.getEntityById(FileHeader.class, fileId);
+ Folder source = file.getFolder();
Folder destination = dao.getEntityById(Folder.class, destId);
User owner = dao.getEntityById(User.class, userId);
}
// move the file to the destination folder
file.setFolder(destination);
+ touchParentFolders(source, owner, new Date());
+ touchParentFolders(destination, owner, new Date());
}
@Override
file.setDeleted(false);
dao.update(file);
+ touchParentFolders(parent, user, new Date());
}
@Override
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())
for (Folder subFolder : folder.getSubfolders())
removeFolderFromTrash(userId, subFolder.getId());
dao.update(folder);
+ touchParentFolders(folder, user, new Date());
}
@Override
}
dao.update(file);
+ Folder parent = file.getFolder();
+ touchParentFolders(parent, user, new Date());
}
}
* @see gr.ebs.gss.server.ejb.ExternalAPI#moveFiles(java.lang.Long, java.util.List, java.lang.Long)
*/
@Override
- public void moveFiles(Long userId, List<Long> fileIds, Long destId) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException, GSSIOException, QuotaExceededException {
+ public void moveFiles(Long userId, List<Long> fileIds, Long destId) throws InsufficientPermissionsException, ObjectNotFoundException, QuotaExceededException {
for(Long l : fileIds){
FileHeader file = dao.getEntityById(FileHeader.class, l);
moveFile(userId, l, destId, file.getName());
for (final FileBody body : file.getBodies())
filesToRemove.add(body.getStoredFilePath());
dao.delete(file);
+ touchParentFolders(parent, user, new Date());
}
//then remove physical files if everything is ok
for(String physicalFileName : filesToRemove)
deleteActualFile(body.getStoredFilePath());
header.getBodies().remove(body);
+ Folder parent = header.getFolder();
+ touchParentFolders(parent, user, new Date());
}
}
header.getCurrentBody().setVersion(1);
+ Folder parent = header.getFolder();
+ touchParentFolders(parent, user, new Date());
}
/* (non-Javadoc)
if(header.isVersioned())
removeOldVersions(userId, fileId);
header.setVersioned(versioned);
-
+ Folder parent = header.getFolder();
+ touchParentFolders(parent, user, new Date());
}
}
} catch (FileNotFoundException e) {
throw new GSSIOException(e);
}
+ touchParentFolders(parent, owner, new Date());
dao.flush();
indexFile(file.getId(), false);
} catch (FileNotFoundException e) {
throw new GSSIOException(e);
}
+ Folder parent = file.getFolder();
+ touchParentFolders(parent, owner, new Date());
indexFile(fileId, false);
return file.getDTO();
*/
private String identifyMimeType(String filename) {
if (filename.indexOf('.') != -1) {
- String extension = filename.substring(filename.lastIndexOf('.'));
+ String extension = filename.substring(filename.lastIndexOf('.')).toLowerCase(Locale.ENGLISH);
if (".doc".equals(extension))
return "application/msword";
else if (".xls".equals(extension))
return "application/vnd.ms-powerpoint";
else if (".pdf".equals(extension))
return "application/pdf";
+ else if (".gif".equals(extension))
+ return "image/gif";
+ else if (".jpg".equals(extension) || ".jpeg".equals(extension) || ".jpe".equals(extension))
+ return "image/jpeg";
+ else if (".tiff".equals(extension) || ".tif".equals(extension))
+ return "image/tiff";
+ else if (".png".equals(extension))
+ return "image/png";
+ else if (".bmp".equals(extension))
+ return "image/bmp";
}
// when all else fails assign the default mime type
return DEFAULT_MIME_TYPE;