Merge after backout of changeset 017ec8d2e32f
[pithos] / src / gr / ebs / gss / server / ejb / ExternalAPIBean.java
index 60b7101..d81de62 100644 (file)
@@ -820,23 +820,26 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                // Store the last element, since it requires special handling.
                String lastElement = pathElements.remove(pathElements.size() - 1);
                
-       //      Folder cursor = null;
+               Folder cursor = null;
                Long rootFolderId = getRootFolderId(owner.getId());
-        Long cursorId = rootFolderId;
-        if (pathElements.size() > 0)
-            cursorId = dao.getFolderIdFromPath(rootFolderId, pathElements);
+               // Traverse and verify the specified folder path.
+               for (String pathElement : pathElements) {
+                       cursor = getFolder(cursor==null ? rootFolderId : cursor.getId(), pathElement);
+                       if (cursor.isDeleted())
+                               throw new ObjectNotFoundException("Folder " + cursor.getPath() + " not found");
+               }
 
                // Use the lastElement to retrieve the actual resource.
                Object resource = null;
                try {
-                       FileHeader file = getFile(cursorId, lastElement);
+                       FileHeader 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.
-                       Folder folder = getFolder(cursorId, lastElement);
+                       Folder folder = getFolder(cursor==null ? rootFolderId : cursor.getId(), lastElement).getDTO();
                        if (ignoreDeleted && folder.isDeleted())
                                throw new ObjectNotFoundException("Resource not found");
                        resource = folder;