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
This commit is contained in:
Derek Hulley
2006-02-16 00:18:57 +00:00
parent d57dda657d
commit 9474498ca1
4 changed files with 45 additions and 6 deletions

View File

@@ -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<String> 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)

View File

@@ -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<String> getUrls() throws ContentIOException
{
return getUrls(null, null);
}
}

View File

@@ -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<String> 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<String> getUrls() throws ContentIOException;
public Set<String> getUrls(Date createdAfter, Date createdBefore) throws ContentIOException;
/**
* Deletes the content at the given URL.

View File

@@ -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<String> getUrls()
public Set<String> getUrls(Date createdAfter, Date createdBefore)
{
// recursively get all files within the root
Set<String> contentUrls = new HashSet<String>(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<String> contentUrls)
private void getUrls(File directory, Set<String> 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);