From 9474498ca180309e0f6f09500394006b3aa02e23 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Thu, 16 Feb 2006 00:18:57 +0000 Subject: [PATCH] Fixed AR-207: Added older than and younger than support to ContentStore#getUrls git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2402 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../content/AbstractContentReadWriteTest.java | 7 ++++++ .../repo/content/AbstractContentStore.java | 6 +++++ .../alfresco/repo/content/ContentStore.java | 15 ++++++++++-- .../content/filestore/FileContentStore.java | 23 +++++++++++++++---- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/source/java/org/alfresco/repo/content/AbstractContentReadWriteTest.java b/source/java/org/alfresco/repo/content/AbstractContentReadWriteTest.java index ecb5f24704..6cacc15045 100644 --- a/source/java/org/alfresco/repo/content/AbstractContentReadWriteTest.java +++ b/source/java/org/alfresco/repo/content/AbstractContentReadWriteTest.java @@ -26,6 +26,7 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; +import java.util.Date; import java.util.Set; import javax.transaction.UserTransaction; @@ -531,6 +532,8 @@ public abstract class AbstractContentReadWriteTest extends TestCase Set contentUrls = store.getUrls(); String contentUrl = writer.getContentUrl(); assertTrue("Writer URL not listed by store", contentUrls.contains(contentUrl)); + + Date yesterday = new Date(System.currentTimeMillis() - 3600L * 1000L * 24L); // write some data writer.putContent("The quick brown fox..."); @@ -539,6 +542,10 @@ public abstract class AbstractContentReadWriteTest extends TestCase contentUrls = store.getUrls(); assertTrue("Writer URL not listed by store", contentUrls.contains(contentUrl)); + // check that the query for content created before this time yesterday doesn't return the URL + contentUrls = store.getUrls(null, yesterday); + assertFalse("URL was younger than required, but still shows up", contentUrls.contains(contentUrl)); + // delete the content boolean deleted = store.delete(contentUrl); if (deleted) diff --git a/source/java/org/alfresco/repo/content/AbstractContentStore.java b/source/java/org/alfresco/repo/content/AbstractContentStore.java index 6c46d3a115..8a5bdfc63b 100644 --- a/source/java/org/alfresco/repo/content/AbstractContentStore.java +++ b/source/java/org/alfresco/repo/content/AbstractContentStore.java @@ -18,6 +18,7 @@ package org.alfresco.repo.content; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.repository.ContentIOException; @@ -112,4 +113,9 @@ public abstract class AbstractContentStore implements ContentStore } return path; } + + public final Set getUrls() throws ContentIOException + { + return getUrls(null, null); + } } diff --git a/source/java/org/alfresco/repo/content/ContentStore.java b/source/java/org/alfresco/repo/content/ContentStore.java index e6e1fba7bd..27238061cf 100644 --- a/source/java/org/alfresco/repo/content/ContentStore.java +++ b/source/java/org/alfresco/repo/content/ContentStore.java @@ -16,6 +16,7 @@ */ package org.alfresco.repo.content; +import java.util.Date; import java.util.Set; import org.alfresco.service.cmr.repository.ContentIOException; @@ -108,13 +109,23 @@ public interface ContentStore public ContentWriter getWriter(ContentReader existingContentReader, String newContentUrl) throws ContentIOException; /** - * Get a set of all content in the store + * Get all URLs for the store, regardless of creation time. * + * @see #getUrls(Date, Date) + */ + public Set getUrls() throws ContentIOException; + + /** + * Get a set of all content URLs in the store. This indicates all content + * available for reads. + * + * @param createdAfter all URLs returned must have been created after this date. May be null. + * @param createdBefore all URLs returned must have been created before this date. May be null. * @return Returns a complete set of the unique URLs of all available content * in the store * @throws ContentIOException */ - public Set getUrls() throws ContentIOException; + public Set getUrls(Date createdAfter, Date createdBefore) throws ContentIOException; /** * Deletes the content at the given URL. diff --git a/source/java/org/alfresco/repo/content/filestore/FileContentStore.java b/source/java/org/alfresco/repo/content/filestore/FileContentStore.java index dcac15dd11..395759d69f 100644 --- a/source/java/org/alfresco/repo/content/filestore/FileContentStore.java +++ b/source/java/org/alfresco/repo/content/filestore/FileContentStore.java @@ -18,6 +18,7 @@ package org.alfresco.repo.content.filestore; import java.io.File; import java.io.IOException; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -268,11 +269,11 @@ public class FileContentStore extends AbstractContentStore } } - public Set getUrls() + public Set getUrls(Date createdAfter, Date createdBefore) { // recursively get all files within the root Set contentUrls = new HashSet(1000); - getUrls(rootDirectory, contentUrls); + getUrls(rootDirectory, contentUrls, createdAfter, createdBefore); // done if (logger.isDebugEnabled()) { @@ -286,9 +287,11 @@ public class FileContentStore extends AbstractContentStore /** * @param directory the current directory to get the files from * @param contentUrls the list of current content URLs to add to + * @param createdAfter only get URLs for content create after this date + * @param createdBefore only get URLs for content created before this date * @return Returns a list of all files within the given directory and all subdirectories */ - private void getUrls(File directory, Set contentUrls) + private void getUrls(File directory, Set contentUrls, Date createdAfter, Date createdBefore) { File[] files = directory.listFiles(); if (files == null) @@ -301,10 +304,22 @@ public class FileContentStore extends AbstractContentStore if (file.isDirectory()) { // we have a subdirectory - recurse - getUrls(file, contentUrls); + getUrls(file, contentUrls, createdAfter, createdBefore); } else { + // check the created date of the file + long lastModified = file.lastModified(); + if (createdAfter != null && lastModified < createdAfter.getTime()) + { + // file is too old + continue; + } + else if (createdBefore != null && lastModified > createdBefore.getTime()) + { + // file is too young + continue; + } // found a file - create the URL String contentUrl = makeContentUrl(file); contentUrls.add(contentUrl);