Backed out changeset ad848a720811
[pithos] / src / gr / ebs / gss / server / ejb / ExternalAPIBean.java
index 8beefa0..b76f67c 100644 (file)
@@ -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)
@@ -441,9 +447,21 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                folder.getAuditInfo().setModifiedBy(user);
                dao.update(folder);
                touchParentFolders(folder, user, new Date());
+               // Re-index the folder contents if it was modified.
+               if ((permissions != null && !permissions.isEmpty()) || readForAll != null) {
+            indexFolder(folder);
+        }
+
                return folder.getDTO();
        }
 
+    private void indexFolder(Folder folder) {
+        for (FileHeader fh : folder.getFiles())
+            indexFile(fh.getId(), false);
+        for (Folder f : folder.getSubfolders())
+            indexFolder(f);
+    }
+
        @Override
        public void createGroup(final Long userId, final String name) throws ObjectNotFoundException, DuplicateNameException {
                // Validate.
@@ -818,10 +836,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 +849,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 +896,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 {
@@ -2106,7 +2126,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                        for (Long id : fileIds) {
                                postFileToSolr(solr, id);
                 i++;
-                if (i % 100 == 0) {
+                if (i % 10 == 0) {
                     solr.commit();
                     logger.info("Sent commit to solr at file " + i);
                 }
@@ -2135,7 +2155,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                                postFileToSolr(solr, id);
                 i++;
                        }
-            if (i % 100 == 0) {
+            if (i % 10 == 0) {
                 solr.commit();
                 logger.info("Sent commit to solr at file " + i);
             }
@@ -2631,7 +2651,7 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
         * @throws ObjectNotFoundException 
         */
        
-       public List<UserLogin> getUserLogins(Long userId) throws ObjectNotFoundException{
+       public List<UserLogin> getLastUserLogins(Long userId) throws ObjectNotFoundException{
                List<UserLogin> userLoginResults = new ArrayList<UserLogin>();          
                userLoginResults = dao.getLoginsForUser(userId);        
                if(userLoginResults.size() == 0)