From: Dimitris Routsis Date: Thu, 16 Dec 2010 16:37:44 +0000 (+0200) Subject: Merge with 9e62eed712763292a41becaefd1a1c239fc4f0c6 X-Git-Tag: pithos/v0.7.8~323^2~14^2~98 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/984b269d939c0294f65bd1c7bcb463ac42878e54?hp=05ec5f8a7580c872c5a2b07b1a78cf46a7269eec Merge ... 9e62eed712763292a41becaefd1a1c239fc4f0c6 --- diff --git a/jboss/deploy/gssdb-ds.xml b/jboss/deploy/gssdb-ds.xml index b331df1..9968ada 100644 --- a/jboss/deploy/gssdb-ds.xml +++ b/jboss/deploy/gssdb-ds.xml @@ -7,6 +7,6 @@ org.postgresql.Driver gss gss - select username from gss_user where id=0 + select 1 diff --git a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java index 8beefa0..cc4481f 100644 --- a/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java +++ b/src/gr/ebs/gss/server/ejb/ExternalAPIBean.java @@ -153,6 +153,12 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { } } + private Long getRootFolderId(Long userId) throws ObjectNotFoundException { + if (userId == null) + throw new ObjectNotFoundException("No user specified"); + return dao.getRootFolderId(userId); + } + @Override public FolderDTO getRootFolder(Long userId) throws ObjectNotFoundException { if (userId == null) @@ -818,10 +824,12 @@ 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 = null; + Long rootFolderId = getRootFolderId(owner.getId()); // Traverse and verify the specified folder path. for (String pathElement : pathElements) { - cursor = getFolder(cursor.getId(), pathElement); + cursor = getFolder(cursor==null ? rootFolderId : cursor.getId(), pathElement); if (cursor.isDeleted()) throw new ObjectNotFoundException("Folder " + cursor.getPath() + " not found"); } @@ -829,14 +837,14 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote { // Use the lastElement to retrieve the actual resource. Object resource = null; try { - FileHeaderDTO file = getFile(cursor.getId(), lastElement); + FileHeaderDTO file = getFile(cursor==null ? rootFolderId : cursor.getId(), lastElement); if (ignoreDeleted && file.isDeleted()) throw new ObjectNotFoundException("Resource not found"); resource = file; } catch (ObjectNotFoundException e) { // Perhaps the requested resource is not a file, so // check for folders as well. - FolderDTO folder = getFolder(cursor.getId(), lastElement); + FolderDTO folder = getFolder(cursor==null ? rootFolderId : cursor.getId(), lastElement).getDTO(); if (ignoreDeleted && folder.isDeleted()) throw new ObjectNotFoundException("Resource not found"); resource = folder; @@ -876,14 +884,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 { diff --git a/src/gr/ebs/gss/server/ejb/GSSDAO.java b/src/gr/ebs/gss/server/ejb/GSSDAO.java index 6ab41c2..d5107a5 100644 --- a/src/gr/ebs/gss/server/ejb/GSSDAO.java +++ b/src/gr/ebs/gss/server/ejb/GSSDAO.java @@ -95,6 +95,16 @@ public interface GSSDAO { public List getGroups(Long userId) throws ObjectNotFoundException; /** + * Retrieves the root folder id for the specified user. The caller must ensure + * that the userId exists. + * + * @param userId + * @return Long The id + * @throws ObjectNotFoundException if no Folder was found + */ + public Long getRootFolderId(final Long userId) throws ObjectNotFoundException; + + /** * Retrieves the root folder for the specified user. The caller must ensure * that the userId exists. * diff --git a/src/gr/ebs/gss/server/ejb/GSSDAOBean.java b/src/gr/ebs/gss/server/ejb/GSSDAOBean.java index 1153041..4dc6660 100644 --- a/src/gr/ebs/gss/server/ejb/GSSDAOBean.java +++ b/src/gr/ebs/gss/server/ejb/GSSDAOBean.java @@ -65,6 +65,20 @@ public class GSSDAOBean implements GSSDAO { private EntityManager manager; @Override + public Long getRootFolderId(final Long userId) throws ObjectNotFoundException { + try { + if (userId == null) + throw new ObjectNotFoundException("No user specified"); + return (Long) manager .createQuery("select f.id from Folder f " + + "where f.owner.id=:ownerId and f.parent is null") + .setParameter("ownerId", userId) + .getSingleResult(); + } catch (final NoResultException e) { + throw new ObjectNotFoundException("Root folder not found for user with id=" + userId); + } + } + + @Override public Folder getRootFolder(final Long userId) throws ObjectNotFoundException { try { if (userId == null)