mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -26,6 +26,7 @@ import java.io.OutputStream;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.transaction.UserTransaction;
|
import javax.transaction.UserTransaction;
|
||||||
@@ -531,6 +532,8 @@ public abstract class AbstractContentReadWriteTest extends TestCase
|
|||||||
Set<String> contentUrls = store.getUrls();
|
Set<String> contentUrls = store.getUrls();
|
||||||
String contentUrl = writer.getContentUrl();
|
String contentUrl = writer.getContentUrl();
|
||||||
assertTrue("Writer URL not listed by store", contentUrls.contains(contentUrl));
|
assertTrue("Writer URL not listed by store", contentUrls.contains(contentUrl));
|
||||||
|
|
||||||
|
Date yesterday = new Date(System.currentTimeMillis() - 3600L * 1000L * 24L);
|
||||||
|
|
||||||
// write some data
|
// write some data
|
||||||
writer.putContent("The quick brown fox...");
|
writer.putContent("The quick brown fox...");
|
||||||
@@ -539,6 +542,10 @@ public abstract class AbstractContentReadWriteTest extends TestCase
|
|||||||
contentUrls = store.getUrls();
|
contentUrls = store.getUrls();
|
||||||
assertTrue("Writer URL not listed by store", contentUrls.contains(contentUrl));
|
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
|
// delete the content
|
||||||
boolean deleted = store.delete(contentUrl);
|
boolean deleted = store.delete(contentUrl);
|
||||||
if (deleted)
|
if (deleted)
|
||||||
|
@@ -18,6 +18,7 @@ package org.alfresco.repo.content;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
@@ -112,4 +113,9 @@ public abstract class AbstractContentStore implements ContentStore
|
|||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Set<String> getUrls() throws ContentIOException
|
||||||
|
{
|
||||||
|
return getUrls(null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content;
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
@@ -108,13 +109,23 @@ public interface ContentStore
|
|||||||
public ContentWriter getWriter(ContentReader existingContentReader, String newContentUrl) throws ContentIOException;
|
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
|
* @return Returns a complete set of the unique URLs of all available content
|
||||||
* in the store
|
* in the store
|
||||||
* @throws ContentIOException
|
* @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.
|
* Deletes the content at the given URL.
|
||||||
|
@@ -18,6 +18,7 @@ package org.alfresco.repo.content.filestore;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
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
|
// recursively get all files within the root
|
||||||
Set<String> contentUrls = new HashSet<String>(1000);
|
Set<String> contentUrls = new HashSet<String>(1000);
|
||||||
getUrls(rootDirectory, contentUrls);
|
getUrls(rootDirectory, contentUrls, createdAfter, createdBefore);
|
||||||
// done
|
// done
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -286,9 +287,11 @@ public class FileContentStore extends AbstractContentStore
|
|||||||
/**
|
/**
|
||||||
* @param directory the current directory to get the files from
|
* @param directory the current directory to get the files from
|
||||||
* @param contentUrls the list of current content URLs to add to
|
* @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
|
* @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();
|
File[] files = directory.listFiles();
|
||||||
if (files == null)
|
if (files == null)
|
||||||
@@ -301,10 +304,22 @@ public class FileContentStore extends AbstractContentStore
|
|||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
{
|
{
|
||||||
// we have a subdirectory - recurse
|
// we have a subdirectory - recurse
|
||||||
getUrls(file, contentUrls);
|
getUrls(file, contentUrls, createdAfter, createdBefore);
|
||||||
}
|
}
|
||||||
else
|
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
|
// found a file - create the URL
|
||||||
String contentUrl = makeContentUrl(file);
|
String contentUrl = makeContentUrl(file);
|
||||||
contentUrls.add(contentUrl);
|
contentUrls.add(contentUrl);
|
||||||
|
Reference in New Issue
Block a user