From: fstamatelopoulos Date: Tue, 21 Dec 2010 16:03:57 +0000 (+0200) Subject: removed even more DTOs X-Git-Tag: pithos/v0.7.8~323^2~14^2~54^2~1^2~1^2~3 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/f7c44c3322a3ec1edf2953ed976506d6803686be removed even more DTOs --- diff --git a/src/gr/ebs/gss/server/domain/FileBody.java b/src/gr/ebs/gss/server/domain/FileBody.java index bbed3bd..3b69060 100644 --- a/src/gr/ebs/gss/server/domain/FileBody.java +++ b/src/gr/ebs/gss/server/domain/FileBody.java @@ -100,6 +100,11 @@ public final class FileBody implements Serializable{ */ private long fileSize; + + public Long getId() { + return id; + } + /** * Returns the version * @@ -136,6 +141,11 @@ public final class FileBody implements Serializable{ header = newHeader; } + + public AuditInfo getAuditInfo() { + return auditInfo; + } + /** * Retrieve the MIME type. * diff --git a/src/gr/ebs/gss/server/domain/FileHeader.java b/src/gr/ebs/gss/server/domain/FileHeader.java index ef14217..469e81a 100644 --- a/src/gr/ebs/gss/server/domain/FileHeader.java +++ b/src/gr/ebs/gss/server/domain/FileHeader.java @@ -18,7 +18,7 @@ */ package gr.ebs.gss.server.domain; -import gr.ebs.gss.server.domain.dto.FileHeaderDTO; +import gr.ebs.gss.server.domain.dto.UserDTO; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -325,6 +325,19 @@ public final class FileHeader implements Serializable{ } /** + * Retrieve the file tags as a list of strings. + * + * @return the list of file tag strings + */ + public List getFileTagsAsStrings() { + List result = new ArrayList(); + for (FileTag ft : fileTags) { + result.add(ft.getTag()); + } + return result; + } + + /** * Retrieve the file tags. * * @return the list of file tags @@ -431,34 +444,6 @@ public final class FileHeader implements Serializable{ } /** - * Constructs and returns a DTO for this instance for use by remote clients - * - * @return FileHeaderDTO - */ - public FileHeaderDTO getDTO() { - final FileHeaderDTO f = new FileHeaderDTO(); - f.setId(id); - f.setName(name); - f.setPath(getPath()); - f.setFolder(folder.getDTO()); - f.setVersioned(versioned); - f.setVersion(currentBody.getVersion()); - f.setOwner(owner.getDTO()); - f.setFileSize(currentBody.getFileSize()); - f.setOriginalFilename(currentBody.getOriginalFilename()); - f.setOriginalFilenameEncoded(currentBody.getOriginalFilenameEncoded()); - f.setMimeType(currentBody.getMimeType()); - f.setDeleted(deleted); - f.setReadForAll(readForAll); - List tags = new ArrayList(); - for (FileTag tag : fileTags) - tags.add(tag.getTag()); - f.setTags(tags); - f.setAuditInfo(auditInfo.getDTO()); - return f; - } - - /** * Checks if the specified user has permission to delete this file, by * checking if the user has write permission to this object. * diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPI.java b/src/gr/ebs/gss/server/ejb/ExternalAPI.java index 70140c7..b9c8c79 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPI.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPI.java @@ -24,16 +24,19 @@ import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; import gr.ebs.gss.client.exceptions.InvitationUsedException; import gr.ebs.gss.client.exceptions.ObjectNotFoundException; import gr.ebs.gss.client.exceptions.QuotaExceededException; +import gr.ebs.gss.server.domain.FileBody; import gr.ebs.gss.server.domain.FileHeader; import gr.ebs.gss.server.domain.FileUploadStatus; +import gr.ebs.gss.server.domain.Folder; +import gr.ebs.gss.server.domain.Group; import gr.ebs.gss.server.domain.Invitation; import gr.ebs.gss.server.domain.Nonce; +import gr.ebs.gss.server.domain.Permission; import gr.ebs.gss.server.domain.User; import gr.ebs.gss.server.domain.UserClass; import gr.ebs.gss.server.domain.dto.FileBodyDTO; import gr.ebs.gss.server.domain.dto.FileHeaderDTO; import gr.ebs.gss.server.domain.dto.FolderDTO; -import gr.ebs.gss.server.domain.dto.GroupDTO; import gr.ebs.gss.server.domain.dto.PermissionDTO; import gr.ebs.gss.server.domain.dto.StatsDTO; import gr.ebs.gss.server.domain.dto.UserDTO; @@ -67,7 +70,7 @@ public interface ExternalAPI { * @return Folder * @throws ObjectNotFoundException if no Folder or user was found */ - public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException; + public Folder getRootFolder(Long userId) throws ObjectNotFoundException; /** * Retrieve the folder with the specified ID. @@ -78,7 +81,7 @@ public interface ExternalAPI { * @throws ObjectNotFoundException if the folder or the user was not found * @throws InsufficientPermissionsException if ther user does not have read permissions for folder */ - public FolderDTO getFolder(Long userId, Long folderId) throws ObjectNotFoundException, + public Folder getFolder(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; /** @@ -106,7 +109,7 @@ public interface ExternalAPI { * @return The Group object * @throws ObjectNotFoundException if the group cannot be found */ - public GroupDTO getGroup(Long groupId) throws ObjectNotFoundException; + public Group getGroup(Long groupId) throws ObjectNotFoundException; /** * Returns the group with the specified name that belongs to the @@ -117,7 +120,7 @@ public interface ExternalAPI { * @return The Group object * @throws ObjectNotFoundException if the group cannot be found */ - public GroupDTO getGroup(Long userId, String name) throws ObjectNotFoundException; + public Group getGroup(Long userId, String name) throws ObjectNotFoundException; /** * Retrieve the list of groups for a particular user. @@ -126,7 +129,7 @@ public interface ExternalAPI { * @return a List of Groups that belong to the specified User * @throws ObjectNotFoundException if the user was not found */ - public List getGroups(Long userId) throws ObjectNotFoundException; + public List getGroups(Long userId) throws ObjectNotFoundException; /** * Returns a list of files contained in the folder specified by its id. @@ -138,7 +141,7 @@ public interface ExternalAPI { * @throws ObjectNotFoundException if the user or the folder cannot be found * @throws InsufficientPermissionsException */ - public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException, + public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException, InsufficientPermissionsException; /** @@ -175,7 +178,7 @@ public interface ExternalAPI { * problem * @throws InsufficientPermissionsException */ - public FolderDTO createFolder(Long userId, Long parentId, String name) throws DuplicateNameException, + public Folder createFolder(Long userId, Long parentId, String name) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException; /** @@ -265,9 +268,9 @@ public interface ExternalAPI { * @throws DuplicateNameException if the specified name already exists in * the parent folder, as either a folder or file */ - public FolderDTO updateFolder(Long userId, Long folderId, String folderName, + public Folder updateFolder(Long userId, Long folderId, String folderName, Boolean readForAll, - Set permissions) + Set permissions) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException; /** @@ -392,7 +395,7 @@ public interface ExternalAPI { */ public void updateFile(Long userId, Long fileId, String name, String tagSet, Date modificationDate, Boolean versioned, Boolean readForAll, - Set permissions) + Set permissions) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException; /** @@ -438,7 +441,7 @@ public interface ExternalAPI { * the exception message mentioning the precise problem * @throws InsufficientPermissionsException */ - public FileHeaderDTO getFile(Long userId, Long fileId) throws ObjectNotFoundException, + public FileHeader getFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException; /** @@ -884,7 +887,7 @@ public interface ExternalAPI { * @throws ObjectNotFoundException if the user or folder could not be found * @throws InsufficientPermissionsException */ - public Set getFolderPermissions(Long userId, Long folderId) + public Set getFolderPermissions(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; /** @@ -896,7 +899,7 @@ public interface ExternalAPI { * @throws ObjectNotFoundException if the user or folder could not be found * @throws InsufficientPermissionsException */ - public Set getFilePermissions(Long userId, Long fileId) + public Set getFilePermissions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException; /** @@ -1128,7 +1131,7 @@ public interface ExternalAPI { * @throws InsufficientPermissionsException * @throws QuotaExceededException */ - public FileHeaderDTO createFile(Long userId, Long folderId, String name, String mimeType, long fileSize, String filePath) + public FileHeader createFile(Long userId, Long folderId, String name, String mimeType, long fileSize, String filePath) throws DuplicateNameException, ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException; @@ -1148,7 +1151,7 @@ public interface ExternalAPI { * @throws InsufficientPermissionsException * @throws QuotaExceededException */ - public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, + public FileHeader updateFileContents(Long userId, Long fileId, String mimeType, long fileSize, String filePath) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException; @@ -1185,7 +1188,7 @@ public interface ExternalAPI { * @throws InsufficientPermissionsException if the user does not * have enough privileges for reading this file */ - public FileBodyDTO getFileVersion(Long userId, Long fileId, int version) throws ObjectNotFoundException, InsufficientPermissionsException; + public FileBody getFileVersion(Long userId, Long fileId, int version) throws ObjectNotFoundException, InsufficientPermissionsException; /** * Search the system for a user with the specified email address. diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java index 2a37719..84d4f34 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java @@ -153,15 +153,15 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException { + public Folder getRootFolder(Long userId) throws ObjectNotFoundException { if (userId == null) throw new ObjectNotFoundException("No user specified"); Folder folder = dao.getRootFolder(userId); - return folder.getDTO(); + return folder; } @Override - public FolderDTO getFolder(final Long userId, final Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException { + public Folder getFolder(final Long userId, final Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (folderId == null) @@ -171,7 +171,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { // Check permissions if (!folder.hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the permissions to read this folder"); - return folder.getDTO(); + return folder; } @Override @@ -187,15 +187,15 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public GroupDTO getGroup(final Long groupId) throws ObjectNotFoundException { + public Group getGroup(final Long groupId) throws ObjectNotFoundException { if (groupId == null) throw new ObjectNotFoundException("No group specified"); final Group group = dao.getEntityById(Group.class, groupId); - return group.getDTO(); + return group; } @Override - public GroupDTO getGroup(Long userId, String name) throws ObjectNotFoundException { + public Group getGroup(Long userId, String name) throws ObjectNotFoundException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (name == null) @@ -204,23 +204,20 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { List groups = user.getGroupsSpecified(); for (Group group: groups) if (group.getName().equals(name)) - return group.getDTO(); + return group; throw new ObjectNotFoundException("Group " + name + " not found"); } @Override - public List getGroups(final Long userId) throws ObjectNotFoundException { + public List getGroups(final Long userId) throws ObjectNotFoundException { if (userId == null) throw new ObjectNotFoundException("No user specified"); final List groups = dao.getGroups(userId); - final List result = new ArrayList(); - for (final Group g : groups) - result.add(g.getDTO()); - return result; + return groups; } @Override - public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) + public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException, InsufficientPermissionsException { // Validate. if (userId == null) @@ -231,12 +228,8 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { Folder folder = dao.getEntityById(Folder.class, folderId); if (!folder.hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the permissions to read this folder"); - // Do the actual work. - List result = new ArrayList(); List files = dao.getFiles(folderId, userId, ignoreDeleted); - for (FileHeader f : files) - result.add(f.getDTO()); - return result; + return files; } @Override @@ -256,7 +249,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FolderDTO createFolder(Long userId, Long parentId, String name) + public Folder createFolder(Long userId, Long parentId, String name) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException { // Validate. if (userId == null) @@ -294,7 +287,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { * @param creator * @return the new folder */ - private FolderDTO createFolder(String name, Folder parent, User creator) { + private Folder createFolder(String name, Folder parent, User creator) { Folder folder = new Folder(); folder.setName(name); if (parent != null) { @@ -335,7 +328,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { folder.setReadForAll(parent.isReadForAll()); dao.create(folder); - return folder.getDTO(); + return folder; } @Override @@ -401,9 +394,9 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FolderDTO updateFolder(Long userId, Long folderId, String folderName, + public Folder updateFolder(Long userId, Long folderId, String folderName, Boolean readForAll, - Set permissions) + Set permissions) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException { @@ -440,7 +433,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { folder.getAuditInfo().setModifiedBy(user); dao.update(folder); touchParentFolders(folder, user, new Date()); - return folder.getDTO(); + return folder; } @Override @@ -638,7 +631,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { @Override public void updateFile(Long userId, Long fileId, String name, String tagSet, Date modificationDate, Boolean versioned, - Boolean readForAll, Set permissions) + Boolean readForAll, Set permissions) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); @@ -774,7 +767,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FileHeaderDTO getFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException { + public FileHeader getFile(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (fileId == null) @@ -783,7 +776,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { final FileHeader file = dao.getEntityById(FileHeader.class, fileId); if (!file.hasReadPermission(user) && !file.getFolder().hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the necessary permissions"); - return file.getDTO(); + return file; } @Override @@ -817,7 +810,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { return getRootFolder(owner.getId()); // Store the last element, since it requires special handling. String lastElement = pathElements.remove(pathElements.size() - 1); - FolderDTO cursor = getRootFolder(owner.getId()); + Folder cursor = getRootFolder(owner.getId()); // Traverse and verify the specified folder path. for (String pathElement : pathElements) { cursor = getFolder(cursor.getId(), pathElement); @@ -828,7 +821,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { // Use the lastElement to retrieve the actual resource. Object resource = null; try { - FileHeaderDTO file = getFile(cursor.getId(), lastElement); + FileHeader file = getFile(cursor.getId(), lastElement); if (ignoreDeleted && file.isDeleted()) throw new ObjectNotFoundException("Resource not found"); resource = file; @@ -854,14 +847,14 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { * found, with the exception message mentioning the precise * problem */ - private FileHeaderDTO getFile(Long folderId, String name) throws ObjectNotFoundException { + private FileHeader getFile(Long folderId, String name) throws ObjectNotFoundException { if (folderId == null) throw new ObjectNotFoundException("No parent folder specified"); if (StringUtils.isEmpty(name)) throw new ObjectNotFoundException("No file specified"); FileHeader file = dao.getFile(folderId, name); - return file.getDTO(); + return file; } /** @@ -875,14 +868,14 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { * found, with the exception message mentioning the precise * problem */ - private FolderDTO getFolder(Long parentId, String name) throws ObjectNotFoundException { + private Folder getFolder(Long parentId, String name) throws ObjectNotFoundException { if (parentId == null) throw new ObjectNotFoundException("No parent folder specified"); if (StringUtils.isEmpty(name)) throw new ObjectNotFoundException("No folder specified"); Folder folder = dao.getFolder(parentId, name); - return folder.getDTO(); + return folder; } private FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException { @@ -1460,7 +1453,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public Set getFolderPermissions(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException { + public Set getFolderPermissions(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (folderId == null) @@ -1470,14 +1463,14 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { if(!folder.hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the necessary permissions"); Set perms = folder.getPermissions(); - Set result = new LinkedHashSet(); + Set result = new LinkedHashSet(); for (Permission perm : perms) if (perm.getUser() != null && perm.getUser().getId().equals(folder.getOwner().getId())) - result.add(perm.getDTO()); + result.add(perm); for (Permission perm : perms) if (perm.getUser() != null && perm.getUser().getId().equals(folder.getOwner().getId())) { } else - result.add(perm.getDTO()); + result.add(perm); return result; } @@ -1492,13 +1485,13 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { * @throws ObjectNotFoundException * @throws InsufficientPermissionsException */ - private void setFolderPermissions(User user, Folder folder, Set permissions) throws ObjectNotFoundException, InsufficientPermissionsException { + private void setFolderPermissions(User user, Folder folder, Set permissions) throws ObjectNotFoundException, InsufficientPermissionsException { if (permissions != null && !permissions.isEmpty()) { User owner = folder.getOwner(); - PermissionDTO ownerPerm = null; - for (PermissionDTO dto : permissions) - if (dto.getUser() != null && dto.getUser().getId().equals(owner.getId())) { - ownerPerm = dto; + Permission ownerPerm = null; + for (Permission perm : permissions) + if (perm.getUser() != null && perm.getUser().getId().equals(owner.getId())) { + ownerPerm = perm; break; } if (ownerPerm == null || !ownerPerm.hasRead() || !ownerPerm.hasWrite() || !ownerPerm.hasModifyACL()) @@ -1507,10 +1500,10 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { for (Permission perm: folder.getPermissions()) dao.delete(perm); folder.getPermissions().clear(); - for (PermissionDTO dto : permissions) { + for (Permission p : permissions) { // Skip 'empty' permission entries. - if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue; - folder.addPermission(getPermission(dto)); + if (!p.getRead() && !p.getWrite() && !p.getModifyACL()) continue; + folder.addPermission(getPermission(p)); } dao.update(folder); for (FileHeader file : folder.getFiles()) { @@ -1524,18 +1517,18 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } } - private Permission getPermission(PermissionDTO dto) throws ObjectNotFoundException { + private Permission getPermission(Permission perm) throws ObjectNotFoundException { Permission res = new Permission(); - if (dto.getGroup() != null) - res.setGroup(dao.getEntityById(Group.class, dto.getGroup().getId())); - else if (dto.getUser() != null) - if (dto.getUser().getId() == null) - res.setUser(dao.getUser(dto.getUser().getUsername())); + if (perm.getGroup() != null) + res.setGroup(dao.getEntityById(Group.class, perm.getGroup().getId())); + else if (perm.getUser() != null) + if (perm.getUser().getId() == null) + res.setUser(dao.getUser(perm.getUser().getUsername())); else - res.setUser(dao.getEntityById(User.class, dto.getUser().getId())); - res.setRead(dto.hasRead()); - res.setWrite(dto.hasWrite()); - res.setModifyACL(dto.hasModifyACL()); + res.setUser(dao.getEntityById(User.class, perm.getUser().getId())); + res.setRead(perm.hasRead()); + res.setWrite(perm.hasWrite()); + res.setModifyACL(perm.hasModifyACL()); return res; } @@ -1627,7 +1620,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public Set getFilePermissions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException { + public Set getFilePermissions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (fileId == null) @@ -1637,14 +1630,14 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { if(!folder.hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the necessary permissions"); Set perms = folder.getPermissions(); - Set result = new LinkedHashSet(); + Set result = new LinkedHashSet(); for (Permission perm : perms) if (perm.getUser() != null && perm.getUser().getId().equals(folder.getOwner().getId())) - result.add(perm.getDTO()); + result.add(perm); for (Permission perm : perms) if (perm.getUser() != null && perm.getUser().getId().equals(folder.getOwner().getId())) { } else - result.add(perm.getDTO()); + result.add(perm); return result; } @@ -1659,13 +1652,13 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { * @throws InsufficientPermissionsException */ private void setFilePermissions(FileHeader file, - Set permissions) + Set permissions) throws ObjectNotFoundException, InsufficientPermissionsException { if (permissions != null && !permissions.isEmpty()) { - PermissionDTO ownerPerm = null; - for (PermissionDTO dto : permissions) - if (dto.getUser() != null && dto.getUser().getId().equals(file.getOwner().getId())) { - ownerPerm = dto; + Permission ownerPerm = null; + for (Permission perm : permissions) + if (perm.getUser() != null && perm.getUser().getId().equals(file.getOwner().getId())) { + ownerPerm = perm; break; } if (ownerPerm == null || !ownerPerm.hasRead() || !ownerPerm.hasWrite() || !ownerPerm.hasModifyACL()) @@ -1674,10 +1667,10 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { for (Permission perm: file.getPermissions()) dao.delete(perm); file.getPermissions().clear(); - for (PermissionDTO dto : permissions) { + for (Permission perm : permissions) { // Skip 'empty' permission entries. - if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue; - file.addPermission(getPermission(dto)); + if (!perm.getRead() && !perm.getWrite() && !perm.getModifyACL()) continue; + file.addPermission(getPermission(perm)); } dao.flush(); } @@ -2138,7 +2131,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FileHeaderDTO createFile(Long userId, Long folderId, String name, String mimeType, long fileSize, String filePath) + public FileHeader createFile(Long userId, Long folderId, String name, String mimeType, long fileSize, String filePath) throws DuplicateNameException, ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException { // Validate. @@ -2204,11 +2197,11 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { dao.flush(); indexFile(file.getId(), false); - return file.getDTO(); + return file; } @Override - public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, long fileSize, String filePath) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException { + public FileHeader updateFileContents(Long userId, Long fileId, String mimeType, long fileSize, String filePath) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException { if (userId == null) throw new ObjectNotFoundException("No user specified"); if (fileId == null) @@ -2241,7 +2234,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { touchParentFolders(parent, owner, new Date()); indexFile(fileId, false); - return file.getDTO(); + return file; } /** @@ -2449,7 +2442,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } @Override - public FileBodyDTO getFileVersion(Long userId, Long fileId, int version) + public FileBody getFileVersion(Long userId, Long fileId, int version) throws ObjectNotFoundException, InsufficientPermissionsException { if (userId == null) throw new ObjectNotFoundException("No user specified"); @@ -2462,7 +2455,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { if (!file.hasReadPermission(user) && !file.getFolder().hasReadPermission(user)) throw new InsufficientPermissionsException("You don't have the necessary permissions"); FileBody body = dao.getFileVersion(fileId, version); - return body.getDTO(); + return body; } @Override diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java b/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java index f6083b4..cc40540 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPIRemote.java @@ -24,10 +24,12 @@ import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; import gr.ebs.gss.client.exceptions.ObjectNotFoundException; import gr.ebs.gss.client.exceptions.QuotaExceededException; import gr.ebs.gss.server.domain.FileHeader; +import gr.ebs.gss.server.domain.Folder; +import gr.ebs.gss.server.domain.Group; +import gr.ebs.gss.server.domain.Permission; import gr.ebs.gss.server.domain.User; import gr.ebs.gss.server.domain.dto.FileHeaderDTO; import gr.ebs.gss.server.domain.dto.FolderDTO; -import gr.ebs.gss.server.domain.dto.GroupDTO; import gr.ebs.gss.server.domain.dto.PermissionDTO; import gr.ebs.gss.server.domain.dto.UserDTO; @@ -54,7 +56,7 @@ public interface ExternalAPIRemote { * @return Folder * @throws ObjectNotFoundException if no Folder or user was found */ - public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException; + public Folder getRootFolder(Long userId) throws ObjectNotFoundException; /** * Retrieve the folder with the specified ID. @@ -65,7 +67,7 @@ public interface ExternalAPIRemote { * @throws ObjectNotFoundException if the folder or the user was not found * @throws InsufficientPermissionsException if ther user does not have read permissions for folder */ - public FolderDTO getFolder(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; + public Folder getFolder(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; /** * Returns the user with the specified ID. @@ -92,7 +94,7 @@ public interface ExternalAPIRemote { * @return The Group object * @throws ObjectNotFoundException if the group cannot be found */ - public GroupDTO getGroup(Long groupId) throws ObjectNotFoundException; + public Group getGroup(Long groupId) throws ObjectNotFoundException; /** * Retrieve the list of groups for a particular user. @@ -101,7 +103,7 @@ public interface ExternalAPIRemote { * @return a List of Groups that belong to the specified User * @throws ObjectNotFoundException if the user was not found */ - public List getGroups(Long userId) throws ObjectNotFoundException; + public List getGroups(Long userId) throws ObjectNotFoundException; /** * Returns a list of files contained in the folder specified by its id. @@ -113,7 +115,7 @@ public interface ExternalAPIRemote { * @throws ObjectNotFoundException if the user or the folder cannot be found * @throws InsufficientPermissionsException */ - public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException, InsufficientPermissionsException; + public List getFiles(Long userId, Long folderId, boolean ignoreDeleted) throws ObjectNotFoundException, InsufficientPermissionsException; /** * Returns a list of users for the specified group @@ -149,7 +151,7 @@ public interface ExternalAPIRemote { * problem * @throws InsufficientPermissionsException */ - public FolderDTO createFolder(Long userId, Long parentId, String name) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException; + public Folder createFolder(Long userId, Long parentId, String name) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException; /** * Deletes the specified folder if the specified user has the appropriate @@ -203,9 +205,9 @@ public interface ExternalAPIRemote { * @throws DuplicateNameException if the specified name already exists in * the parent folder, as either a folder or file */ - public FolderDTO updateFolder(Long userId, Long folderId, String folderName, + public Folder updateFolder(Long userId, Long folderId, String folderName, Boolean readForAll, - Set permissions) + Set permissions) throws InsufficientPermissionsException, ObjectNotFoundException, DuplicateNameException; @@ -313,7 +315,7 @@ public interface ExternalAPIRemote { */ public void updateFile(Long userId, Long fileId, String name, String tagSet, Date modificationDate, Boolean versioned, Boolean readForAll, - Set permissions) + Set permissions) throws DuplicateNameException, ObjectNotFoundException, InsufficientPermissionsException; /** @@ -610,7 +612,7 @@ public interface ExternalAPIRemote { * @throws ObjectNotFoundException if the user or folder could not be found * @throws InsufficientPermissionsException */ - public Set getFolderPermissions(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; + public Set getFolderPermissions(Long userId, Long folderId) throws ObjectNotFoundException, InsufficientPermissionsException; /** * Retrieve file user and group permissions @@ -621,7 +623,7 @@ public interface ExternalAPIRemote { * @throws ObjectNotFoundException if the user or folder could not be found * @throws InsufficientPermissionsException */ - public Set getFilePermissions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException; + public Set getFilePermissions(Long userId, Long fileId) throws ObjectNotFoundException, InsufficientPermissionsException; /** * Returns a list of All Shared root folders of a user. @@ -630,7 +632,7 @@ public interface ExternalAPIRemote { * * @return the list of shared root folders * @throws ObjectNotFoundException if the user cannot be found */ - public List getSharedRootFolders(Long userId) throws ObjectNotFoundException; + public List getSharedRootFolders(Long userId) throws ObjectNotFoundException; /** * Returns a list of All Shared files of a user. diff --git a/src/gr/ebs/gss/server/rest/FilesHandler.java b/src/gr/ebs/gss/server/rest/FilesHandler.java index 608267f..a97d623 100644 --- a/src/gr/ebs/gss/server/rest/FilesHandler.java +++ b/src/gr/ebs/gss/server/rest/FilesHandler.java @@ -26,13 +26,13 @@ import gr.ebs.gss.client.exceptions.ObjectNotFoundException; import gr.ebs.gss.client.exceptions.QuotaExceededException; import gr.ebs.gss.client.exceptions.RpcException; import gr.ebs.gss.server.Login; +import gr.ebs.gss.server.domain.FileBody; +import gr.ebs.gss.server.domain.FileHeader; import gr.ebs.gss.server.domain.FileUploadStatus; +import gr.ebs.gss.server.domain.Folder; +import gr.ebs.gss.server.domain.Group; +import gr.ebs.gss.server.domain.Permission; import gr.ebs.gss.server.domain.User; -import gr.ebs.gss.server.domain.dto.FileBodyDTO; -import gr.ebs.gss.server.domain.dto.FileHeaderDTO; -import gr.ebs.gss.server.domain.dto.FolderDTO; -import gr.ebs.gss.server.domain.dto.GroupDTO; -import gr.ebs.gss.server.domain.dto.PermissionDTO; import gr.ebs.gss.server.ejb.ExternalAPI; import gr.ebs.gss.server.ejb.TransactionHelper; import gr.ebs.gss.server.webdav.Range; @@ -205,8 +205,8 @@ public class FilesHandler extends RequestHandler { User owner = getOwner(req); boolean exists = true; Object resource = null; - FileHeaderDTO file = null; - FolderDTO folder = null; + FileHeader file = null; + Folder folder = null; try { resource = getService().getResourceAtPath(owner.getId(), path, false); } catch (ObjectNotFoundException e) { @@ -223,10 +223,10 @@ public class FilesHandler extends RequestHandler { return; } - if (resource instanceof FolderDTO) - folder = (FolderDTO) resource; + if (resource instanceof Folder) + folder = (Folder) resource; else - file = (FileHeaderDTO) resource; // Note that file will be null, if (!exists). + file = (FileHeader) resource; // Note that file will be null, if (!exists). // Now it's time to perform the deferred authentication check. // Since regular signature checking was already performed, @@ -362,7 +362,7 @@ public class FilesHandler extends RequestHandler { // Fetch the version to retrieve, if specified. String verStr = req.getParameter(VERSION_PARAM); int version = 0; - FileBodyDTO oldBody = null; + FileBody oldBody = null; if (verStr != null && file != null) try { version = Integer.valueOf(verStr); @@ -402,10 +402,10 @@ public class FilesHandler extends RequestHandler { boolean expectJSON = false; if (file != null) { - contentType = version>0 ? oldBody.getMimeType() : file.getMimeType(); + contentType = version>0 ? oldBody.getMimeType() : file.getCurrentBody().getMimeType(); if (contentType == null) { contentType = context.getMimeType(file.getName()); - file.setMimeType(contentType); + file.getCurrentBody().setMimeType(contentType); } } else { // folder != null String accept = req.getHeader("Accept"); @@ -447,7 +447,7 @@ public class FilesHandler extends RequestHandler { return; } // Get content length. - contentLength = version>0 ? oldBody.getFileSize() : file.getFileSize(); + contentLength = version>0 ? oldBody.getFileSize() : file.getCurrentBody().getFileSize(); // Special case for zero length files, which would cause a // (silent) ISE when setting the output buffer size. if (contentLength == 0L) @@ -643,7 +643,7 @@ public class FilesHandler extends RequestHandler { * Return the filename of the specified file properly formatted for * including in the Content-Disposition header. */ - private String getDispositionFilename(FileHeaderDTO file) throws UnsupportedEncodingException { + private String getDispositionFilename(FileHeader file) throws UnsupportedEncodingException { return URLEncoder.encode(file.getName(),"UTF-8").replaceAll("\\+", "%20"); } @@ -676,7 +676,7 @@ public class FilesHandler extends RequestHandler { * @throws IOException if an I/O error occurs */ private void serveProgress(HttpServletRequest req, HttpServletResponse resp, - String parameter, User user, FileHeaderDTO file) throws IOException { + String parameter, User user, FileHeader file) throws IOException { String filename = file == null ? parameter : file.getName(); try { FileUploadStatus status = getService().getFileUploadStatus(user.getId(), filename); @@ -787,13 +787,13 @@ public class FilesHandler extends RequestHandler { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path); return; } - if (resource instanceof FolderDTO) { + if (resource instanceof Folder) { resp.sendError(HttpServletResponse.SC_CONFLICT); return; } try { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader file = (FileHeader) resource; final int oldVersion = Integer.parseInt(version); new TransactionHelper().tryExecute(new Callable() { @@ -837,7 +837,7 @@ public class FilesHandler extends RequestHandler { User owner = getOwner(request); boolean exists = true; Object resource = null; - FileHeaderDTO file = null; + FileHeader file = null; try { resource = getService().getResourceAtPath(owner.getId(), path, false); } catch (ObjectNotFoundException e) { @@ -848,8 +848,8 @@ public class FilesHandler extends RequestHandler { } if (exists) - if (resource instanceof FileHeaderDTO) { - file = (FileHeaderDTO) resource; + if (resource instanceof FileHeader) { + file = (FileHeader) resource; if (file.isDeleted()) { response.sendError(HttpServletResponse.SC_CONFLICT, file.getName() + " is in the trash"); return; @@ -871,11 +871,11 @@ public class FilesHandler extends RequestHandler { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path); return; } - if (!(parent instanceof FolderDTO)) { + if (!(parent instanceof Folder)) { response.sendError(HttpServletResponse.SC_CONFLICT); return; } - final FolderDTO folder = (FolderDTO) parent; + final Folder folderLocal = (Folder) parent; final String fileName = getLastElement(path); if (!isValidResourceName(fileName)) { @@ -970,25 +970,25 @@ public class FilesHandler extends RequestHandler { } catch (IOException ex) { throw new GSSIOException(ex, false); } - FileHeaderDTO fileDTO = null; + FileHeader fileLocal = null; final File upf = uploadedFile; - final FileHeaderDTO f = file; + final FileHeader f = file; final User u = user; if (file == null) - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileLocal = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { - return getService().createFile(u.getId(), folder.getId(), fileName, contentType, upf.getCanonicalFile().length(), upf.getAbsolutePath()); + public FileHeader call() throws Exception { + return getService().createFile(u.getId(), folderLocal.getId(), fileName, contentType, upf.getCanonicalFile().length(), upf.getAbsolutePath()); } }); else - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileLocal = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { + public FileHeader call() throws Exception { return getService().updateFileContents(u.getId(), f.getId(), contentType, upf.getCanonicalFile().length(), upf.getAbsolutePath()); } }); - updateAccounting(owner, new Date(), fileDTO.getFileSize()); + updateAccounting(owner, new Date(), fileLocal.getCurrentBody().getFileSize()); getService().removeFileUploadProgress(user.getId(), fileName); } } @@ -1099,21 +1099,21 @@ public class FilesHandler extends RequestHandler { try { final User dOwner = destOwner; final String dest = destination; - if (resource instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) resource; + if (resource instanceof Folder) { + final Folder folderLocal = (Folder) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().moveFolderToPath(user.getId(), dOwner.getId(), folder.getId(), dest); + getService().moveFolderToPath(user.getId(), dOwner.getId(), folderLocal.getId(), dest); return null; } }); } else { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader fileLocal = (FileHeader) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().moveFileToPath(user.getId(), dOwner.getId(), file.getId(), dest); + getService().moveFileToPath(user.getId(), dOwner.getId(), fileLocal.getId(), dest); return null; } }); @@ -1184,21 +1184,21 @@ public class FilesHandler extends RequestHandler { try { final User dOwner = destOwner; final String dest = destination; - if (resource instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) resource; + if (resource instanceof Folder) { + final Folder folderLocal = (Folder) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().copyFolderStructureToPath(user.getId(), dOwner.getId(), folder.getId(), dest); + getService().copyFolderStructureToPath(user.getId(), dOwner.getId(), folderLocal.getId(), dest); return null; } }); } else { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader fileLocal = (FileHeader) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().copyFileToPath(user.getId(), dOwner.getId(), file.getId(), dest); + getService().copyFileToPath(user.getId(), dOwner.getId(), fileLocal.getId(), dest); return null; } }); @@ -1303,21 +1303,21 @@ public class FilesHandler extends RequestHandler { } try { - if (resource instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) resource; + if (resource instanceof Folder) { + final Folder folderLocal = (Folder) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().moveFolderToTrash(user.getId(), folder.getId()); + getService().moveFolderToTrash(user.getId(), folderLocal.getId()); return null; } }); } else { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader fileLocal = (FileHeader) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().moveFileToTrash(user.getId(), file.getId()); + getService().moveFileToTrash(user.getId(), fileLocal.getId()); return null; } }); @@ -1356,21 +1356,21 @@ public class FilesHandler extends RequestHandler { } try { - if (resource instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) resource; + if (resource instanceof Folder) { + final Folder folderLocal = (Folder) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().removeFolderFromTrash(user.getId(), folder.getId()); + getService().removeFolderFromTrash(user.getId(), folderLocal.getId()); return null; } }); } else { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader fileLocal = (FileHeader) resource; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().removeFileFromTrash(user.getId(), file.getId()); + getService().removeFileFromTrash(user.getId(), fileLocal.getId()); return null; } }); @@ -1424,15 +1424,15 @@ public class FilesHandler extends RequestHandler { json = new JSONObject(input.toString()); if (logger.isDebugEnabled()) logger.debug("JSON update: " + json); - if (resource instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) resource; + if (resource instanceof Folder) { + final Folder folderLocal = (Folder) resource; String name = json.optString("name"); if (!isValidResourceName(name)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } JSONArray permissions = json.optJSONArray("permissions"); - Set perms = null; + Set perms = null; if (permissions != null) perms = parsePermissions(user, permissions); Boolean readForAll = null; @@ -1441,18 +1441,18 @@ public class FilesHandler extends RequestHandler { if (!name.isEmpty() || permissions != null || readForAll != null) { final String fName = name.isEmpty()? null: name; final Boolean freadForAll = readForAll; - final Set fPerms = perms; - FolderDTO folderUpdated = new TransactionHelper().tryExecute(new Callable() { + final Set fPerms = perms; + Folder folderUpdated = new TransactionHelper().tryExecute(new Callable() { @Override - public FolderDTO call() throws Exception { - return getService().updateFolder(user.getId(), folder.getId(), fName, freadForAll, fPerms); + public Folder call() throws Exception { + return getService().updateFolder(user.getId(), folderLocal.getId(), fName, freadForAll, fPerms); } }); resp.getWriter().println(getNewUrl(req, folderUpdated)); } } else { - final FileHeaderDTO file = (FileHeaderDTO) resource; + final FileHeader fileLocal = (FileHeader) resource; String name = null; if (json.opt("name") != null) name = json.optString("name"); @@ -1476,7 +1476,7 @@ public class FilesHandler extends RequestHandler { tags = t.toString(); } JSONArray permissions = json.optJSONArray("permissions"); - Set perms = null; + Set perms = null; if (permissions != null) perms = parsePermissions(user, permissions); Boolean readForAll = null; @@ -1490,11 +1490,11 @@ public class FilesHandler extends RequestHandler { final Date mDate = modificationDate != null? new Date(modificationDate): null; final Boolean fVersioned = versioned; final Boolean fReadForAll = readForAll; - final Set fPerms = perms; + final Set fPerms = perms; new TransactionHelper().tryExecute(new Callable() { @Override public Object call() throws Exception { - getService().updateFile(user.getId(), file.getId(), + getService().updateFile(user.getId(), fileLocal.getId(), fName, fTags, mDate, fVersioned, fReadForAll, fPerms); return null; @@ -1522,7 +1522,7 @@ public class FilesHandler extends RequestHandler { /** * Returns the new URL of an updated folder. */ - private String getNewUrl(HttpServletRequest req, FolderDTO folder) throws UnsupportedEncodingException { + private String getNewUrl(HttpServletRequest req, Folder folder) throws UnsupportedEncodingException { String parentUrl = URLDecoder.decode(getContextPath(req, true),"UTF-8"); String fpath = URLDecoder.decode(getRelativePath(req), "UTF-8"); if (parentUrl.indexOf(fpath) != -1) @@ -1535,7 +1535,7 @@ public class FilesHandler extends RequestHandler { /** * Helper method to convert a JSON array of permissions into a set of - * PermissionDTO objects. + * Permission objects. * * @param user the current user * @param permissions the JSON array to parse @@ -1545,14 +1545,14 @@ public class FilesHandler extends RequestHandler { * @throws ObjectNotFoundException if the user could not be found * @throws UnsupportedEncodingException */ - private Set parsePermissions(User user, JSONArray permissions) + private Set parsePermissions(User user, JSONArray permissions) throws JSONException, RpcException, ObjectNotFoundException, UnsupportedEncodingException { if (permissions == null) return null; - Set perms = new HashSet(); + Set perms = new HashSet(); for (int i = 0; i < permissions.length(); i++) { JSONObject j = permissions.getJSONObject(i); - PermissionDTO perm = new PermissionDTO(); + Permission perm = new Permission(); perm.setModifyACL(j.optBoolean("modifyACL")); perm.setRead(j.optBoolean("read")); perm.setWrite(j.optBoolean("write")); @@ -1561,7 +1561,7 @@ public class FilesHandler extends RequestHandler { User u = getService().findUser(permUser); if (u == null) throw new ObjectNotFoundException("User " + permUser + " not found"); - perm.setUser(u.getDTO()); + perm.setUser(u); } // 31/8/2009: Add optional groupUri which takes priority if it exists String permGroupUri = j.optString("groupUri"); @@ -1573,11 +1573,11 @@ public class FilesHandler extends RequestHandler { User u = getService().findUser(usr); if (u == null) throw new ObjectNotFoundException("User " + permUser + " not found"); - GroupDTO g = getService().getGroup(u.getId(), grp); + Group g = getService().getGroup(u.getId(), grp); perm.setGroup(g); } else if (!permGroup.isEmpty()) { - GroupDTO g = getService().getGroup(user.getId(), permGroup); + Group g = getService().getGroup(user.getId(), permGroup); perm.setGroup(g); } if (permUser.isEmpty() && permGroupUri.isEmpty() && permGroup.isEmpty()) @@ -1630,12 +1630,12 @@ public class FilesHandler extends RequestHandler { return; } try { - if (parent instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) parent; - FolderDTO newFolder = new TransactionHelper().tryExecute(new Callable() { + if (parent instanceof Folder) { + final Folder folderLocal = (Folder) parent; + Folder newFolder = new TransactionHelper().tryExecute(new Callable() { @Override - public FolderDTO call() throws Exception { - return getService().createFolder(user.getId(), folder.getId(), folderName); + public Folder call() throws Exception { + return getService().createFolder(user.getId(), folderLocal.getId(), folderName); } }); @@ -1688,7 +1688,7 @@ public class FilesHandler extends RequestHandler { User owner = getOwner(req); boolean exists = true; Object resource = null; - FileHeaderDTO file = null; + FileHeader fileLocal = null; try { resource = getService().getResourceAtPath(owner.getId(), path, false); } catch (ObjectNotFoundException e) { @@ -1699,8 +1699,8 @@ public class FilesHandler extends RequestHandler { } if (exists) - if (resource instanceof FileHeaderDTO) - file = (FileHeaderDTO) resource; + if (resource instanceof FileHeader) + fileLocal = (FileHeader) resource; else { resp.sendError(HttpServletResponse.SC_CONFLICT, path + " is a folder"); return; @@ -1736,13 +1736,13 @@ public class FilesHandler extends RequestHandler { resourceInputStream = req.getInputStream(); try { - FolderDTO folder = null; + Folder folderLocal = null; Object parent = getService().getResourceAtPath(owner.getId(), getParentPath(path), true); - if (!(parent instanceof FolderDTO)) { + if (!(parent instanceof Folder)) { resp.sendError(HttpServletResponse.SC_CONFLICT); return; } - folder = (FolderDTO) parent; + folderLocal = (Folder) parent; final String name = getLastElement(path); final String mimeType = context.getMimeType(name); File uploadedFile = null; @@ -1751,27 +1751,27 @@ public class FilesHandler extends RequestHandler { } catch (IOException ex) { throw new GSSIOException(ex, false); } - FileHeaderDTO fileDTO = null; + FileHeader fileTemp = null; final File uploadedf = uploadedFile; - final FolderDTO parentf = folder; - final FileHeaderDTO f = file; + final Folder parentf = folderLocal; + final FileHeader f = fileLocal; if (exists) - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileTemp = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { + public FileHeader call() throws Exception { return getService().updateFileContents(user.getId(), f.getId(), mimeType, uploadedf.getCanonicalFile().length(), uploadedf.getAbsolutePath()); } }); else - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileTemp = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { + public FileHeader call() throws Exception { return getService().createFile(user.getId(), parentf.getId(), name, mimeType, uploadedf.getCanonicalFile().length(), uploadedf.getAbsolutePath()); } }); - updateAccounting(owner, new Date(), fileDTO.getFileSize()); - getService().removeFileUploadProgress(user.getId(), fileDTO.getName()); + updateAccounting(owner, new Date(), fileTemp.getCurrentBody().getFileSize()); + getService().removeFileUploadProgress(user.getId(), fileTemp.getName()); } catch(ObjectNotFoundException e) { result = false; } catch (RpcException e) { @@ -1836,16 +1836,16 @@ public class FilesHandler extends RequestHandler { return; } - FolderDTO folder = null; - FileHeaderDTO file = null; - if (object instanceof FolderDTO) - folder = (FolderDTO) object; + Folder folderLocal = null; + FileHeader fileLocal = null; + if (object instanceof Folder) + folderLocal = (Folder) object; else - file = (FileHeaderDTO) object; + fileLocal = (FileHeader) object; - if (file != null) + if (fileLocal != null) try { - final FileHeaderDTO f = file; + final FileHeader f = fileLocal; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { @@ -1868,9 +1868,9 @@ public class FilesHandler extends RequestHandler { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } - else if (folder != null) + else if (folderLocal != null) try { - final FolderDTO fo = folder; + final Folder fo = folderLocal; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { @@ -1907,7 +1907,7 @@ public class FilesHandler extends RequestHandler { * @throws InsufficientPermissionsException if the user does not have * the necessary privileges to read the directory */ - private InputStream renderJson(User user, FolderDTO folder) throws IOException, + private InputStream renderJson(User user, Folder folder) throws IOException, ServletException, InsufficientPermissionsException { JSONObject json = new JSONObject(); try { @@ -1928,7 +1928,7 @@ public class FilesHandler extends RequestHandler { json.put("parent", j); } List subfolders = new ArrayList(); - for (FolderDTO f: folder.getSubfolders()) + for (Folder f: folder.getSubfolders()) if (!f.isDeleted()) { JSONObject j = new JSONObject(); j.put("name", f.getName()). @@ -1937,15 +1937,15 @@ public class FilesHandler extends RequestHandler { } json.put("folders", subfolders); List files = new ArrayList(); - List fileHeaders = getService().getFiles(user.getId(), folder.getId(), false); - for (FileHeaderDTO f: fileHeaders) { + List fileHeaders = getService().getFiles(user.getId(), folder.getId(), false); + for (FileHeader f: fileHeaders) { JSONObject j = new JSONObject(); j.put("name", f.getName()). put("owner", f.getOwner().getUsername()). put("deleted", f.isDeleted()). - put("version", f.getVersion()). - put("content", f.getMimeType()). - put("size", f.getFileSize()). + put("version", f.getCurrentBody().getVersion()). + put("content", f.getCurrentBody().getMimeType()). + put("size", f.getCurrentBody().getFileSize()). put("creationDate", f.getAuditInfo().getCreationDate().getTime()). put("path", f.getFolder().getPath()). put("uri", getApiRoot() + f.getURI()); @@ -1954,7 +1954,7 @@ public class FilesHandler extends RequestHandler { files.add(j); } json.put("files", files); - Set perms = getService().getFolderPermissions(user.getId(), folder.getId()); + Set perms = getService().getFolderPermissions(user.getId(), folder.getId()); json.put("permissions", renderJson(perms)); } catch (JSONException e) { throw new ServletException(e); @@ -1982,7 +1982,7 @@ public class FilesHandler extends RequestHandler { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - private String renderJsonMetadata(User user, FolderDTO folder) + private String renderJsonMetadata(User user, Folder folder) throws ServletException, InsufficientPermissionsException { // Check if the user has read permission. try { @@ -2026,7 +2026,7 @@ public class FilesHandler extends RequestHandler { * @throws InsufficientPermissionsException if the user does not have * the necessary privileges to read the directory */ - private String renderJson(User user, FileHeaderDTO file, FileBodyDTO oldBody) + private String renderJson(User user, FileHeader file, FileBody oldBody) throws ServletException, InsufficientPermissionsException { JSONObject json = new JSONObject(); try { @@ -2034,9 +2034,9 @@ public class FilesHandler extends RequestHandler { json.put("name", URLEncoder.encode(file.getName(),"UTF-8")). put("owner", file.getOwner().getUsername()). put("versioned", file.isVersioned()). - put("version", oldBody != null ? oldBody.getVersion() : file.getVersion()). + put("version", oldBody != null ? oldBody.getVersion() : file.getCurrentBody().getVersion()). put("readForAll", file.isReadForAll()). - put("tags", renderJson(file.getTags())). + put("tags", renderJson(file.getFileTagsAsStrings())). put("path", file.getFolder().getPath()). put("uri", getApiRoot() + file.getURI()). put("deleted", file.isDeleted()); @@ -2056,9 +2056,9 @@ public class FilesHandler extends RequestHandler { put("creationDate", file.getAuditInfo().getCreationDate().getTime()). put("modifiedBy", file.getAuditInfo().getModifiedBy().getUsername()). put("modificationDate", file.getAuditInfo().getModificationDate().getTime()). - put("content", file.getMimeType()). - put("size", file.getFileSize()); - Set perms = getService().getFilePermissions(user.getId(), file.getId()); + put("content", file.getCurrentBody().getMimeType()). + put("size", file.getCurrentBody().getFileSize()); + Set perms = getService().getFilePermissions(user.getId(), file.getId()); json.put("permissions", renderJson(perms)); } catch (JSONException e) { throw new ServletException(e); @@ -2082,15 +2082,15 @@ public class FilesHandler extends RequestHandler { * @throws JSONException * @throws UnsupportedEncodingException */ - private JSONArray renderJson(Set permissions) throws JSONException, UnsupportedEncodingException { + private JSONArray renderJson(Set permissions) throws JSONException, UnsupportedEncodingException { JSONArray perms = new JSONArray(); - for (PermissionDTO p: permissions) { + for (Permission p: permissions) { JSONObject permission = new JSONObject(); permission.put("read", p.hasRead()).put("write", p.hasWrite()).put("modifyACL", p.hasModifyACL()); if (p.getUser() != null) permission.put("user", p.getUser().getUsername()); if (p.getGroup() != null) { - GroupDTO group = p.getGroup(); + Group group = p.getGroup(); permission.put("groupUri", getApiRoot() + group.getOwner().getUsername() + PATH_GROUPS + "/" + URLEncoder.encode(group.getName(),"UTF-8")); permission.put("group", URLEncoder.encode(p.getGroup().getName(),"UTF-8")); } @@ -2198,7 +2198,7 @@ public class FilesHandler extends RequestHandler { * @throws IOException * @throws ServletException */ - private InputStream renderHtml(String contextPath, String path, FolderDTO folder, User user) + private InputStream renderHtml(String contextPath, String path, Folder folder, User user) throws IOException, ServletException { String name = folder.getName(); // Prepare a writer to a buffered area @@ -2264,7 +2264,7 @@ public class FilesHandler extends RequestHandler { boolean shade = false; Iterator iter = folder.getSubfolders().iterator(); while (iter.hasNext()) { - FolderDTO subf = (FolderDTO) iter.next(); + Folder subf = (Folder) iter.next(); if(subf.isReadForAll() && !subf.isDeleted()){ String resourceName = subf.getName(); if (resourceName.equalsIgnoreCase("WEB-INF") || resourceName.equalsIgnoreCase("META-INF")) @@ -2298,7 +2298,7 @@ public class FilesHandler extends RequestHandler { } } - List files; + List files; try { files = getService().getFiles(user.getId(), folder.getId(), true); } catch (ObjectNotFoundException e) { @@ -2308,7 +2308,7 @@ public class FilesHandler extends RequestHandler { } catch (RpcException e) { throw new ServletException(e.getMessage()); } - for (FileHeaderDTO file : files) + for (FileHeader file : files) //Display only file resources that are marked as public and are not deleted if(file.isReadForAll() && !file.isDeleted()){ String resourceName = file.getName(); @@ -2330,7 +2330,7 @@ public class FilesHandler extends RequestHandler { sb.append("\r\n"); sb.append(""); - sb.append(renderSize(file.getFileSize())); + sb.append(renderSize(file.getCurrentBody().getFileSize())); sb.append("\r\n"); sb.append(""); diff --git a/src/gr/ebs/gss/server/webdav/Webdav.java b/src/gr/ebs/gss/server/webdav/Webdav.java index 1b29beb..ea0aaab 100644 --- a/src/gr/ebs/gss/server/webdav/Webdav.java +++ b/src/gr/ebs/gss/server/webdav/Webdav.java @@ -25,8 +25,11 @@ import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; import gr.ebs.gss.client.exceptions.ObjectNotFoundException; import gr.ebs.gss.client.exceptions.QuotaExceededException; import gr.ebs.gss.client.exceptions.RpcException; +import gr.ebs.gss.server.domain.AuditInfo; +import gr.ebs.gss.server.domain.FileBody; +import gr.ebs.gss.server.domain.FileHeader; +import gr.ebs.gss.server.domain.Folder; import gr.ebs.gss.server.domain.User; -import gr.ebs.gss.server.domain.dto.AuditInfoDTO; import gr.ebs.gss.server.domain.dto.FileBodyDTO; import gr.ebs.gss.server.domain.dto.FileHeaderDTO; import gr.ebs.gss.server.domain.dto.FolderDTO; @@ -586,13 +589,13 @@ public class Webdav extends HttpServlet { return; } parseProperties(req, generatedXML, currentPath, type, properties, object); - if (object instanceof FolderDTO && depth > 0) { - FolderDTO folder = (FolderDTO) object; + if (object instanceof Folder && depth > 0) { + Folder folderLocal = (Folder) object; // Retrieve the subfolders. - List subfolders = folder.getSubfolders(); + List subfolders = folderLocal.getSubfolders(); Iterator iter = subfolders.iterator(); while (iter.hasNext()) { - FolderDTO f = (FolderDTO) iter.next(); + Folder f = (Folder) iter.next(); String newPath = currentPath; if (!newPath.endsWith("/")) newPath += "/"; @@ -600,9 +603,9 @@ public class Webdav extends HttpServlet { stackBelow.push(newPath); } // Retrieve the files. - List files; + List files; try { - files = getService().getFiles(user.getId(), folder.getId(), true); + files = getService().getFiles(user.getId(), folderLocal.getId(), true); } catch (ObjectNotFoundException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path); return; @@ -613,7 +616,7 @@ public class Webdav extends HttpServlet { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path); return; } - for (FileHeaderDTO file : files) { + for (FileHeader file : files) { String newPath = currentPath; if (!newPath.endsWith("/")) newPath += "/"; @@ -690,7 +693,7 @@ public class Webdav extends HttpServlet { String path = getRelativePath(req); boolean exists = true; Object resource = null; - FileHeaderDTO file = null; + FileHeader file = null; try { resource = getService().getResourceAtPath(user.getId(), path, true); } catch (ObjectNotFoundException e) { @@ -701,8 +704,8 @@ public class Webdav extends HttpServlet { } if (exists) - if (resource instanceof FileHeaderDTO) - file = (FileHeaderDTO) resource; + if (resource instanceof FileHeader) + file = (FileHeader) resource; else { resp.sendError(HttpServletResponse.SC_CONFLICT); return; @@ -739,11 +742,11 @@ public class Webdav extends HttpServlet { try { Object parent = getService().getResourceAtPath(user.getId(), getParentPath(path), true); - if (!(parent instanceof FolderDTO)) { + if (!(parent instanceof Folder)) { resp.sendError(HttpServletResponse.SC_CONFLICT); return; } - final FolderDTO folder = (FolderDTO) parent; + final Folder folderLocal = (Folder) parent; final String name = getLastElement(path); final String mimeType = getServletContext().getMimeType(name); File uploadedFile = null; @@ -753,24 +756,24 @@ public class Webdav extends HttpServlet { throw new GSSIOException(ex, false); } // FIXME: Add attributes - FileHeaderDTO fileDTO = null; - final FileHeaderDTO f = file; + FileHeader fileLocal = null; + final FileHeader f = file; final File uf = uploadedFile; if (exists) - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileLocal = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { + public FileHeader call() throws Exception { return getService().updateFileContents(user.getId(), f.getId(), mimeType, uf.length(), uf.getAbsolutePath()); } }); else - fileDTO = new TransactionHelper().tryExecute(new Callable() { + fileLocal = new TransactionHelper().tryExecute(new Callable() { @Override - public FileHeaderDTO call() throws Exception { - return getService().createFile(user.getId(), folder.getId(), name, mimeType, uf.length(), uf.getAbsolutePath()); + public FileHeader call() throws Exception { + return getService().createFile(user.getId(), folderLocal.getId(), name, mimeType, uf.length(), uf.getAbsolutePath()); } }); - updateAccounting(user, new Date(), fileDTO.getFileSize()); + updateAccounting(user, new Date(), fileLocal.getCurrentBody().getFileSize()); } catch (ObjectNotFoundException e) { result = false; } catch (InsufficientPermissionsException e) { @@ -1012,7 +1015,7 @@ public class Webdav extends HttpServlet { String lockTokenStr = req.getServletPath() + "-" + lock.type + "-" + lock.scope + "-" + req.getUserPrincipal() + "-" + lock.depth + "-" + lock.owner + "-" + lock.tokens + "-" + lock.expiresAt + "-" + System.currentTimeMillis() + "-" + secret; String lockToken = md5Encoder.encode(md5Helper.digest(lockTokenStr.getBytes())); - if (exists && object instanceof FolderDTO && lock.depth == INFINITY) + if (exists && object instanceof Folder && lock.depth == INFINITY) // Locking a collection (and all its member resources) lock.tokens.addElement(lockToken); else { @@ -1150,12 +1153,12 @@ public class Webdav extends HttpServlet { return; } try { - if (parent instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) parent; + if (parent instanceof Folder) { + final Folder folderLocal = (Folder) parent; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().createFolder(user.getId(), folder.getId(), getLastElement(path)); + getService().createFolder(user.getId(), folderLocal.getId(), getLastElement(path)); return null; } }); @@ -1322,24 +1325,24 @@ public class Webdav extends HttpServlet { if (path.toUpperCase().startsWith("/WEB-INF") || path.toUpperCase().startsWith("/META-INF")) return; - FolderDTO folder = null; - FileHeaderDTO file = null; - if (resource instanceof FolderDTO) - folder = (FolderDTO) resource; + Folder folderLocal = null; + FileHeader fileLocal = null; + if (resource instanceof Folder) + folderLocal = (Folder) resource; else - file = (FileHeaderDTO) resource; + fileLocal = (FileHeader) resource; // Retrieve the creation date. long creation = 0; - if (folder != null) - creation = folder.getAuditInfo().getCreationDate().getTime(); + if (folderLocal != null) + creation = folderLocal.getAuditInfo().getCreationDate().getTime(); else - creation = file.getAuditInfo().getCreationDate().getTime(); + creation = fileLocal.getAuditInfo().getCreationDate().getTime(); // Retrieve the modification date. long modification = 0; - if (folder != null) - modification = folder.getAuditInfo().getCreationDate().getTime(); + if (folderLocal != null) + modification = folderLocal.getAuditInfo().getCreationDate().getTime(); else - modification = file.getAuditInfo().getCreationDate().getTime(); + modification = fileLocal.getAuditInfo().getCreationDate().getTime(); generatedXML.writeElement(null, "D:response", XMLWriter.OPENING); String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK)); @@ -1352,7 +1355,7 @@ public class Webdav extends HttpServlet { href += path.substring(1); else href += path; - if (folder != null && !href.endsWith("/")) + if (folderLocal != null && !href.endsWith("/")) href += "/"; generatedXML.writeText(rewriteUrl(href)); @@ -1377,13 +1380,13 @@ public class Webdav extends HttpServlet { generatedXML.writeElement(null, "D:displayname", XMLWriter.OPENING); generatedXML.writeData(resourceName); generatedXML.writeElement(null, "D:displayname", XMLWriter.CLOSING); - if (file != null) { + if (fileLocal != null) { generatedXML.writeProperty(null, "D:getlastmodified", FastHttpDateFormat.formatDate(modification, null)); - generatedXML.writeProperty(null, "D:getcontentlength", String.valueOf(file.getFileSize())); - String contentType = file.getMimeType(); + generatedXML.writeProperty(null, "D:getcontentlength", String.valueOf(fileLocal.getCurrentBody().getFileSize())); + String contentType = fileLocal.getCurrentBody().getMimeType(); if (contentType != null) generatedXML.writeProperty(null, "D:getcontenttype", contentType); - generatedXML.writeProperty(null, "D:getetag", getETag(file, null)); + generatedXML.writeProperty(null, "D:getetag", getETag(fileLocal, null)); generatedXML.writeElement(null, "D:resourcetype", XMLWriter.NO_CONTENT); } else { generatedXML.writeElement(null, "D:resourcetype", XMLWriter.OPENING); @@ -1415,7 +1418,7 @@ public class Webdav extends HttpServlet { generatedXML.writeElement(null, "D:creationdate", XMLWriter.NO_CONTENT); generatedXML.writeElement(null, "D:displayname", XMLWriter.NO_CONTENT); - if (file != null) { + if (fileLocal != null) { generatedXML.writeElement(null, "D:getcontentlanguage", XMLWriter.NO_CONTENT); generatedXML.writeElement(null, "D:getcontentlength", XMLWriter.NO_CONTENT); generatedXML.writeElement(null, "D:getcontenttype", XMLWriter.NO_CONTENT); @@ -1456,35 +1459,35 @@ public class Webdav extends HttpServlet { generatedXML.writeData(resourceName); generatedXML.writeElement(null, "D:displayname", XMLWriter.CLOSING); } else if (property.equals("D:getcontentlanguage")) { - if (folder != null) + if (folderLocal != null) propertiesNotFound.addElement(property); else generatedXML.writeElement(null, "D:getcontentlanguage", XMLWriter.NO_CONTENT); } else if (property.equals("D:getcontentlength")) { - if (folder != null) + if (folderLocal != null) propertiesNotFound.addElement(property); else - generatedXML.writeProperty(null, "D:getcontentlength", String.valueOf(file.getFileSize())); + generatedXML.writeProperty(null, "D:getcontentlength", String.valueOf(fileLocal.getCurrentBody().getFileSize())); } else if (property.equals("D:getcontenttype")) { - if (folder != null) + if (folderLocal != null) propertiesNotFound.addElement(property); else // XXX Once we properly store the MIME type in the // file, // retrieve it from there. - generatedXML.writeProperty(null, "D:getcontenttype", getServletContext().getMimeType(file.getName())); + generatedXML.writeProperty(null, "D:getcontenttype", getServletContext().getMimeType(fileLocal.getName())); } else if (property.equals("D:getetag")) { - if (folder != null) + if (folderLocal != null) propertiesNotFound.addElement(property); else - generatedXML.writeProperty(null, "D:getetag", getETag(file, null)); + generatedXML.writeProperty(null, "D:getetag", getETag(fileLocal, null)); } else if (property.equals("D:getlastmodified")) { - if (folder != null) + if (folderLocal != null) propertiesNotFound.addElement(property); else generatedXML.writeProperty(null, "D:getlastmodified", FastHttpDateFormat.formatDate(modification, null)); } else if (property.equals("D:resourcetype")) { - if (folder != null) { + if (folderLocal != null) { generatedXML.writeElement(null, "D:resourcetype", XMLWriter.OPENING); generatedXML.writeElement(null, "D:collection", XMLWriter.NO_CONTENT); generatedXML.writeElement(null, "D:resourcetype", XMLWriter.CLOSING); @@ -1539,13 +1542,13 @@ public class Webdav extends HttpServlet { /** * Get the ETag associated with a file. * - * @param file the FileHeaderDTO object for this file + * @param file the FileHeader object for this file * @param oldBody the old version of the file, if requested * @return a string containing the ETag */ - protected String getETag(FileHeaderDTO file, FileBodyDTO oldBody) { + protected String getETag(FileHeader file, FileBody oldBody) { if (oldBody == null) - return "\"" + file.getFileSize() + "-" + file.getAuditInfo().getModificationDate().getTime() + "\""; + return "\"" + file.getCurrentBody().getFileSize() + "-" + file.getAuditInfo().getModificationDate().getTime() + "\""; return "\"" + oldBody.getFileSize() + "-" + oldBody.getAuditInfo().getModificationDate().getTime() + "\""; } @@ -1635,7 +1638,7 @@ public class Webdav extends HttpServlet { methodsAllowed.append(", PROPPATCH, COPY, MOVE, LOCK, UNLOCK"); methodsAllowed.append(", PROPFIND"); - if (!(object instanceof FolderDTO)) + if (!(object instanceof Folder)) methodsAllowed.append(", PUT"); return methodsAllowed; @@ -1755,11 +1758,11 @@ public class Webdav extends HttpServlet { User user = getUser(req); User owner = getOwner(req); - FileHeaderDTO oldResource = null; + FileHeader oldResource = null; try { Object obj = getService().getResourceAtPath(owner.getId(), path, true); - if (obj instanceof FileHeaderDTO) - oldResource = (FileHeaderDTO) obj; + if (obj instanceof FileHeader) + oldResource = (FileHeader) obj; } catch (ObjectNotFoundException e) { // Do nothing. } @@ -1818,8 +1821,8 @@ public class Webdav extends HttpServlet { User user = getUser(req); boolean exists = true; Object resource = null; - FileHeaderDTO file = null; - FolderDTO folder = null; + FileHeader file = null; + Folder folder = null; try { resource = getService().getResourceAtPath(user.getId(), path, true); } catch (ObjectNotFoundException e) { @@ -1834,10 +1837,10 @@ public class Webdav extends HttpServlet { return; } - if (resource instanceof FolderDTO) - folder = (FolderDTO) resource; + if (resource instanceof Folder) + folder = (Folder) resource; else - file = (FileHeaderDTO) resource; + file = (FileHeader) resource; // If the resource is not a collection, and the resource path // ends with "/" or "\", return NOT FOUND @@ -1857,10 +1860,10 @@ public class Webdav extends HttpServlet { // Find content type. String contentType = null; if (file != null) { - contentType = file.getMimeType(); + contentType = file.getCurrentBody().getMimeType(); if (contentType == null) { contentType = getServletContext().getMimeType(file.getName()); - file.setMimeType(contentType); + file.getCurrentBody().setMimeType(contentType); } } else contentType = "text/html;charset=UTF-8"; @@ -1878,7 +1881,7 @@ public class Webdav extends HttpServlet { // Last-Modified header resp.setHeader("Last-Modified", getLastModifiedHttp(file.getAuditInfo())); // Get content length - contentLength = file.getFileSize(); + contentLength = file.getCurrentBody().getFileSize(); // Special case for zero length files, which would cause a // (silent) ISE when setting the output buffer size if (contentLength == 0L) @@ -1999,7 +2002,7 @@ public class Webdav extends HttpServlet { * @param auditInfo the audit info for the specified resource * @return the last modified date in HTTP format */ - protected String getLastModifiedHttp(AuditInfoDTO auditInfo) { + protected String getLastModifiedHttp(AuditInfo auditInfo) { Date modifiedDate = auditInfo.getModificationDate(); if (modifiedDate == null) modifiedDate = auditInfo.getCreationDate(); @@ -2022,7 +2025,7 @@ public class Webdav extends HttpServlet { * @return Vector of ranges * @throws IOException */ - protected ArrayList parseRange(HttpServletRequest request, HttpServletResponse response, FileHeaderDTO file, FileBodyDTO oldBody) throws IOException { + protected ArrayList parseRange(HttpServletRequest request, HttpServletResponse response, FileHeader file, FileBody oldBody) throws IOException { // Checking If-Range String headerValue = request.getHeader("If-Range"); if (headerValue != null) { @@ -2051,7 +2054,7 @@ public class Webdav extends HttpServlet { return FULL; } - long fileLength = oldBody == null ? file.getFileSize() : oldBody.getFileSize(); + long fileLength = oldBody == null ? file.getCurrentBody().getFileSize() : oldBody.getFileSize(); if (fileLength == 0) return null; @@ -2136,7 +2139,7 @@ public class Webdav extends HttpServlet { * @throws IOException */ protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, - FileHeaderDTO file, FileBodyDTO oldBody) throws IOException { + FileHeader file, FileBody oldBody) throws IOException { // TODO : Checking the WebDAV If header return checkIfMatch(request, response, file, oldBody) && checkIfModifiedSince(request, response, file, oldBody) && @@ -2157,7 +2160,7 @@ public class Webdav extends HttpServlet { * @throws IOException */ private boolean checkIfMatch(HttpServletRequest request, HttpServletResponse response, - FileHeaderDTO file, FileBodyDTO oldBody) throws IOException { + FileHeader file, FileBody oldBody) throws IOException { String eTag = getETag(file, oldBody); String headerValue = request.getHeader("If-Match"); if (headerValue != null) @@ -2191,7 +2194,7 @@ public class Webdav extends HttpServlet { * processing is stopped */ private boolean checkIfModifiedSince(HttpServletRequest request, - HttpServletResponse response, FileHeaderDTO file, FileBodyDTO oldBody) { + HttpServletResponse response, FileHeader file, FileBody oldBody) { try { long headerValue = request.getDateHeader("If-Modified-Since"); long lastModified = oldBody == null ? @@ -2226,7 +2229,7 @@ public class Webdav extends HttpServlet { * @throws IOException */ private boolean checkIfNoneMatch(HttpServletRequest request, - HttpServletResponse response, FileHeaderDTO file, FileBodyDTO oldBody) + HttpServletResponse response, FileHeader file, FileBody oldBody) throws IOException { String eTag = getETag(file, oldBody); String headerValue = request.getHeader("If-None-Match"); @@ -2270,7 +2273,7 @@ public class Webdav extends HttpServlet { * @throws IOException */ private boolean checkIfUnmodifiedSince(HttpServletRequest request, - HttpServletResponse response, FileHeaderDTO file, FileBodyDTO oldBody) + HttpServletResponse response, FileHeader file, FileBody oldBody) throws IOException { try { long lastModified = oldBody == null ? @@ -2305,8 +2308,8 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, InputStream is, ServletOutputStream ostream, - HttpServletRequest req, FileBodyDTO oldBody) throws IOException, + protected void copy(FileHeader file, InputStream is, ServletOutputStream ostream, + HttpServletRequest req, FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { IOException exception = null; InputStream resourceInputStream = null; @@ -2374,8 +2377,8 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, InputStream is, PrintWriter writer, - HttpServletRequest req, FileBodyDTO oldBody) throws IOException, + protected void copy(FileHeader file, InputStream is, PrintWriter writer, + HttpServletRequest req, FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { IOException exception = null; @@ -2447,8 +2450,8 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, PrintWriter writer, Iterator ranges, - String contentType, HttpServletRequest req, FileBodyDTO oldBody) + protected void copy(FileHeader file, PrintWriter writer, Iterator ranges, + String contentType, HttpServletRequest req, FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { User user = getUser(req); IOException exception = null; @@ -2579,8 +2582,8 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, ServletOutputStream ostream, Range range, - HttpServletRequest req, FileBodyDTO oldBody) throws IOException, + protected void copy(FileHeader file, ServletOutputStream ostream, Range range, + HttpServletRequest req, FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { IOException exception = null; User user = getUser(req); @@ -2611,8 +2614,8 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, PrintWriter writer, Range range, - HttpServletRequest req, FileBodyDTO oldBody) throws IOException, + protected void copy(FileHeader file, PrintWriter writer, Range range, + HttpServletRequest req, FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { IOException exception = null; User user = getUser(req); @@ -2649,9 +2652,9 @@ public class Webdav extends HttpServlet { * @throws InsufficientPermissionsException * @throws ObjectNotFoundException */ - protected void copy(FileHeaderDTO file, ServletOutputStream ostream, + protected void copy(FileHeader file, ServletOutputStream ostream, Iterator ranges, String contentType, HttpServletRequest req, - FileBodyDTO oldBody) throws IOException, ObjectNotFoundException, + FileBody oldBody) throws IOException, ObjectNotFoundException, InsufficientPermissionsException, RpcException { IOException exception = null; User user = getUser(req); @@ -2693,7 +2696,7 @@ public class Webdav extends HttpServlet { * @throws IOException * @throws ServletException */ - private InputStream renderHtml(String contextPath, String path, FolderDTO folder, HttpServletRequest req) throws IOException, ServletException { + private InputStream renderHtml(String contextPath, String path, Folder folder, HttpServletRequest req) throws IOException, ServletException { String name = folder.getName(); // Prepare a writer to a buffered area ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -2758,7 +2761,7 @@ public class Webdav extends HttpServlet { boolean shade = false; Iterator iter = folder.getSubfolders().iterator(); while (iter.hasNext()) { - FolderDTO subf = (FolderDTO) iter.next(); + Folder subf = (Folder) iter.next(); String resourceName = subf.getName(); if (resourceName.equalsIgnoreCase("WEB-INF") || resourceName.equalsIgnoreCase("META-INF")) continue; @@ -2789,7 +2792,7 @@ public class Webdav extends HttpServlet { sb.append("\r\n"); } - List files; + List files; try { User user = getUser(req); files = getService().getFiles(user.getId(), folder.getId(), true); @@ -2800,8 +2803,8 @@ public class Webdav extends HttpServlet { } catch (RpcException e) { throw new ServletException(e.getMessage()); } - for (FileHeaderDTO file : files) { - String resourceName = file.getName(); + for (FileHeader fileLocal : files) { + String resourceName = fileLocal.getName(); if (resourceName.equalsIgnoreCase("WEB-INF") || resourceName.equalsIgnoreCase("META-INF")) continue; @@ -2820,11 +2823,11 @@ public class Webdav extends HttpServlet { sb.append("\r\n"); sb.append(""); - sb.append(renderSize(file.getFileSize())); + sb.append(renderSize(fileLocal.getCurrentBody().getFileSize())); sb.append("\r\n"); sb.append(""); - sb.append(getLastModifiedHttp(file.getAuditInfo())); + sb.append(getLastModifiedHttp(fileLocal.getAuditInfo())); sb.append("\r\n"); sb.append("\r\n"); @@ -3020,14 +3023,14 @@ public class Webdav extends HttpServlet { } catch (ObjectNotFoundException e) { } - if (object instanceof FolderDTO) { - final FolderDTO folder = (FolderDTO) object; + if (object instanceof Folder) { + final Folder folderLocal = (Folder) object; try { final String des = dest; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().copyFolder(user.getId(), folder.getId(), des); + getService().copyFolder(user.getId(), folderLocal.getId(), des); return null; } }); @@ -3053,16 +3056,16 @@ public class Webdav extends HttpServlet { if (!dest.endsWith("/")) newDest += "/"; // Recursively copy the subfolders. - Iterator iter = folder.getSubfolders().iterator(); + Iterator iter = folderLocal.getSubfolders().iterator(); while (iter.hasNext()) { - FolderDTO subf = (FolderDTO) iter.next(); + Folder subf = (Folder) iter.next(); String resourceName = subf.getName(); copyResource(errorList, newSource + resourceName, newDest + resourceName, req); } // Recursively copy the files. - List files; - files = getService().getFiles(user.getId(), folder.getId(), true); - for (FileHeaderDTO file : files) { + List files; + files = getService().getFiles(user.getId(), folderLocal.getId(), true); + for (FileHeader file : files) { String resourceName = file.getName(); copyResource(errorList, newSource + resourceName, newDest + resourceName, req); } @@ -3077,14 +3080,14 @@ public class Webdav extends HttpServlet { return false; } - } else if (object instanceof FileHeaderDTO) { - final FileHeaderDTO file = (FileHeaderDTO) object; + } else if (object instanceof FileHeader) { + final FileHeader fileLocal = (FileHeader) object; try { final String des = dest; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { - getService().copyFile(user.getId(), file.getId(), des); + getService().copyFile(user.getId(), fileLocal.getId(), des); return null; } }); @@ -3173,16 +3176,16 @@ public class Webdav extends HttpServlet { return false; } - FolderDTO folder = null; - FileHeaderDTO file = null; - if (object instanceof FolderDTO) - folder = (FolderDTO) object; + Folder folderLocal = null; + FileHeader fileLocal = null; + if (object instanceof Folder) + folderLocal = (Folder) object; else - file = (FileHeaderDTO) object; + fileLocal = (FileHeader) object; - if (file != null) + if (fileLocal != null) try { - final FileHeaderDTO f = file; + final FileHeader f = fileLocal; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { @@ -3205,11 +3208,11 @@ public class Webdav extends HttpServlet { resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR); return false; } - else if (folder != null) { + else if (folderLocal != null) { Hashtable errorList = new Hashtable(); - deleteCollection(req, folder, path, errorList); + deleteCollection(req, folderLocal, path, errorList); try { - final FolderDTO f = folder; + final Folder f = folderLocal; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { @@ -3245,7 +3248,7 @@ public class Webdav extends HttpServlet { * @param path Path to the collection to be deleted * @param errorList Contains the list of the errors which occurred */ - private void deleteCollection(HttpServletRequest req, FolderDTO folder, String path, Hashtable errorList) { + private void deleteCollection(HttpServletRequest req, Folder folder, String path, Hashtable errorList) { if (logger.isDebugEnabled()) logger.debug("Delete:" + path); @@ -3265,7 +3268,7 @@ public class Webdav extends HttpServlet { Iterator iter = folder.getSubfolders().iterator(); while (iter.hasNext()) { - FolderDTO subf = (FolderDTO) iter.next(); + Folder subf = (Folder) iter.next(); String childName = path; if (!childName.equals("/")) childName += "/"; @@ -3277,14 +3280,14 @@ public class Webdav extends HttpServlet { try { final User user = getUser(req); Object object = getService().getResourceAtPath(user.getId(), childName, true); - FolderDTO childFolder = null; - FileHeaderDTO childFile = null; - if (object instanceof FolderDTO) - childFolder = (FolderDTO) object; + Folder childFolder = null; + FileHeader childFile = null; + if (object instanceof Folder) + childFolder = (Folder) object; else - childFile = (FileHeaderDTO) object; + childFile = (FileHeader) object; if (childFolder != null) { - final FolderDTO cf = childFolder; + final Folder cf = childFolder; deleteCollection(req, childFolder, childName, errorList); new TransactionHelper().tryExecute(new Callable() { @Override @@ -3294,7 +3297,7 @@ public class Webdav extends HttpServlet { } }); } else if (childFile != null) { - final FileHeaderDTO cf = childFile; + final FileHeader cf = childFile; new TransactionHelper().tryExecute(new Callable() { @Override public Void call() throws Exception { @@ -3429,7 +3432,7 @@ public class Webdav extends HttpServlet { * processing is stopped */ public boolean checkIfModifiedSince(HttpServletRequest request, - HttpServletResponse response, FolderDTO folder) { + HttpServletResponse response, Folder folder) { try { long headerValue = request.getDateHeader("If-Modified-Since"); long lastModified = folder.getAuditInfo().getModificationDate().getTime();