diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 3df4c4f7bd..9e60afe32e 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -559,6 +559,20 @@ class AVMRepository return store.getListing(version, pathParts[1]); } + /** + * Get the list of nodes directly contained in a directory. + * @param version The version to look under. + * @param path The path to the directory to list. + * @return A Map of names to descriptors. + */ + public SortedMap getListingDirect(int version, String path) + { + fLookupCount.set(1); + String [] pathParts = SplitPath(path); + AVMStore store = getAVMStoreByName(pathParts[0]); + return store.getListingDirect(version, pathParts[1]); + } + /** * Get a directory listing from a directory node descriptor. * @param dir The directory node descriptor. @@ -577,6 +591,20 @@ class AVMRepository return dirNode.getListing(dir); } + /** + * Get the names of deleted nodes in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A List of names. + */ + public List getDeleted(int version, String path) + { + fLookupCount.set(1); + String [] pathParts = SplitPath(path); + AVMStore store = getAVMStoreByName(pathParts[0]); + return store.getDeleted(version, pathParts[1]); + } + /** * Get descriptors of all AVMStores. * @return A list of all descriptors. diff --git a/source/java/org/alfresco/repo/avm/AVMService.java b/source/java/org/alfresco/repo/avm/AVMService.java index d8b0706efd..54c06f6801 100644 --- a/source/java/org/alfresco/repo/avm/AVMService.java +++ b/source/java/org/alfresco/repo/avm/AVMService.java @@ -85,7 +85,7 @@ public interface AVMService * Get a listing of a Folder by name. * @param version The version id to look in. * @param path The simple absolute path to the file node. - * @return A List of FolderEntrys. + * @return A Map of names to descriptors. * @throws AVMNotFoundException If path is not found. * @throws AVMWrongTypeException If path contains a non-terminal * component that is not a directory, or if path is not pointing @@ -93,6 +93,20 @@ public interface AVMService */ public SortedMap getDirectoryListing(int version, String path); + /** + * Get the listing of nodes contained directly in a directory. This is the + * same as getDirectoryListing for PlainDirectories, but returns only those that + * are directly contained in a layered directory. + * @param version The version to look up. + * @param path The full path to get listing for. + * @return A Map of names to descriptors. + * @throws AVMNotFoundException If path does not exist. + * @throws AVMWrongTypeException If path contains any non-directory + * elements. + */ + public SortedMap + getDirectoryListingDirect(int version, String path); + /** * Get a directory listing from a node descriptor. * @param dir The directory node descriptor. @@ -103,6 +117,17 @@ public interface AVMService */ public SortedMap getDirectoryListing(AVMNodeDescriptor dir); + /** + * Get the names of nodes that have been deleted in a directory. + * @param version The version to look under. + * @param path The path of the directory. + * @return A List of names. + * @throws AVMNotFoundException If path does not exist. + * @throws AVMWrongTypeException If path contains any elements + * that are not directories. + */ + public List getDeleted(int version, String path); + /** * Create a new File. Fails if the file already exists. * @param path The simple absolute path to the parent. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 03523d4231..429bd7b4ec 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -245,6 +245,38 @@ class AVMServiceImpl implements AVMService return doit.listing; } + /** + * Get the listing of nodes contained directly in a directory. This is the + * same as getDirectoryListing for PlainDirectories, but returns only those that + * are directly contained in a layered directory. + * @param version The version to look up. + * @param path The full path to get listing for. + * @return A Map of names to descriptors. + * @throws AVMNotFoundException If path does not exist. + * @throws AVMWrongTypeException If path contains any non-directory + * elements. + */ + public SortedMap + getDirectoryListingDirect(final int version, final String path) + { + if (path == null) + { + throw new AVMBadArgumentException("Null path."); + } + class TxnCallback implements RetryingTransactionCallback + { + public SortedMap listing; + + public void perform() + { + listing = fAVMRepository.getListingDirect(version, path); + } + } + TxnCallback doit = new TxnCallback(); + fTransaction.perform(doit, false); + return doit.listing; + } + /** * Get a directory listing from a node descriptor. * @param dir The directory node descriptor. @@ -270,6 +302,35 @@ class AVMServiceImpl implements AVMService return doit.listing; } + /** + * Get the names of nodes that have been deleted in a directory. + * @param version The version to look under. + * @param path The path of the directory. + * @return A List of names. + * @throws AVMNotFoundException If path does not exist. + * @throws AVMWrongTypeException If path contains any elements + * that are not directories. + */ + public List getDeleted(final int version, final String path) + { + if (path == null) + { + throw new AVMBadArgumentException("Null path."); + } + class TxnCallback implements RetryingTransactionCallback + { + public List listing; + + public void perform() + { + listing = fAVMRepository.getDeleted(version, path); + } + } + TxnCallback doit = new TxnCallback(); + fTransaction.perform(doit, false); + return doit.listing; + } + /** * Create a new file. The file must not exist. * @param path The path to the containing directory. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 51e302318c..0b51f8e630 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -39,6 +39,68 @@ import org.alfresco.service.namespace.QName; */ public class AVMServiceTest extends AVMServiceTestBase { + /** + * Test getting deleted names. + */ + public void testGetDeleted() + { + try + { + setupBasicTree(); + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + List deleted = fService.getDeleted(-1, "main:/layer/b/c"); + assertEquals(0, deleted.size()); + fService.removeNode("main:/a/b/c", "foo"); + fService.createSnapshot("main"); + deleted = fService.getDeleted(-1, "main:/a/b/c"); + assertEquals(0, deleted.size()); + fService.removeNode("main:/layer/b/c", "bar"); + fService.createSnapshot("main"); + deleted = fService.getDeleted(-1, "main:/layer/b/c"); + assertEquals(1, deleted.size()); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Test directly contained listing. + */ + public void testListingDirect() + { + try + { + setupBasicTree(); + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + Map listing = + fService.getDirectoryListingDirect(-1, + "main:/layer"); + assertEquals(0, listing.size()); + fService.createFile("main:/layer/b/c", "sigmoid").close(); + fService.createSnapshot("main"); + listing = fService.getDirectoryListingDirect(-1, "main:/layer"); + assertEquals(1, listing.size()); + fService.createFile("main:/layer", "lepton"); + fService.createSnapshot("main"); + listing = fService.getDirectoryListingDirect(-1, "main:/layer"); + assertEquals(2, listing.size()); + listing = fService.getDirectoryListingDirect(-1, "main:/layer/b/c"); + assertEquals(1, listing.size()); + listing = fService.getDirectoryListingDirect(-1, "main:/a/b/c"); + assertEquals(2, listing.size()); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + /** * Test layering info. */ diff --git a/source/java/org/alfresco/repo/avm/AVMStore.java b/source/java/org/alfresco/repo/avm/AVMStore.java index 5f8fa32614..0daf524ddb 100644 --- a/source/java/org/alfresco/repo/avm/AVMStore.java +++ b/source/java/org/alfresco/repo/avm/AVMStore.java @@ -110,7 +110,23 @@ interface AVMStore * @return A listing. */ public SortedMap getListing(int version, String path); + + /** + * Get the list of nodes directly contained in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A Map of names to descriptors. + */ + public SortedMap getListingDirect(int version, String path); + /** + * Get the names of the deleted nodes in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A List of names. + */ + public List getDeleted(int version, String path); + /** * Get an output stream to a file. * @param path The path to the file. diff --git a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java index 74dc5f44b2..160d371ada 100644 --- a/source/java/org/alfresco/repo/avm/AVMStoreImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMStoreImpl.java @@ -307,6 +307,33 @@ class AVMStoreImpl implements AVMStore, Serializable Lookup lPath = lookupDirectory(version, path, false); DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); Map listing = dir.getListing(lPath); + return translateListing(listing, lPath); + } + + /** + * Get the list of nodes directly contained in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A Map of names to descriptors. + */ + public SortedMap getListingDirect(int version, String path) + { + Lookup lPath = lookupDirectory(version, path, false); + DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); + Map listing = dir.getListingDirect(lPath); + return translateListing(listing, lPath); + } + + /** + * Helper to convert an internal representation of a directory listing + * to an external representation. + * @param listing The internal listing, a Map of names to nodes. + * @param lPath The Lookup for the directory. + * @return A Map of names to descriptors. + */ + private SortedMap + translateListing(Map listing, Lookup lPath) + { SortedMap results = new TreeMap(); for (String name : listing.keySet()) { @@ -317,6 +344,19 @@ class AVMStoreImpl implements AVMStore, Serializable return results; } + /** + * Get the names of the deleted nodes in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A List of names. + */ + public List getDeleted(int version, String path) + { + Lookup lPath = lookupDirectory(version, path, false); + DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); + return dir.getDeletedNames(); + } + /** * Get an output stream to a file. * @param path The path to the file. diff --git a/source/java/org/alfresco/repo/avm/DirectoryNode.java b/source/java/org/alfresco/repo/avm/DirectoryNode.java index 567b69e345..3d618940d1 100644 --- a/source/java/org/alfresco/repo/avm/DirectoryNode.java +++ b/source/java/org/alfresco/repo/avm/DirectoryNode.java @@ -16,6 +16,7 @@ */ package org.alfresco.repo.avm; +import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -68,6 +69,13 @@ interface DirectoryNode extends AVMNode * @return A SortedMap of names to DirectoryEntries. */ public Map getListing(Lookup lPath); + + /** + * Get a listing of the nodes directly contained by a directory. + * @param lPath The Lookup to this directory. + * @return A Map of names to nodes. + */ + public Map getListingDirect(Lookup lPath); /** * Get a listing from a directory specified by an AVMNodeDescriptor. @@ -75,6 +83,12 @@ interface DirectoryNode extends AVMNode * @return A Map of names to node descriptors */ public SortedMap getListing(AVMNodeDescriptor dir); + + /** + * Get the names of nodes deleted in this directory. + * @return A List of names. + */ + public List getDeletedNames(); /** * Set the directory, which must be in a layer, into a primary diff --git a/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java b/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java index 10f018299d..fd5ba0c945 100644 --- a/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/LayeredDirectoryNodeImpl.java @@ -17,6 +17,7 @@ package org.alfresco.repo.avm; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -349,6 +350,21 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec return listing; } + /** + * Get a listing of the nodes directly contained by a directory. + * @param lPath The Lookup to this directory. + * @return A Map of names to nodes. + */ + public Map getListingDirect(Lookup lPath) + { + Map listing = new HashMap(); + for (ChildEntry entry : AVMContext.fgInstance.fChildEntryDAO.getByParent(this)) + { + listing.put(entry.getName(), entry.getChild()); + } + return listing; + } + /** * Get a listing from a directory node descriptor. * @param dir The directory node descriptor. @@ -401,6 +417,21 @@ class LayeredDirectoryNodeImpl extends DirectoryNodeImpl implements LayeredDirec return baseListing; } + /** + * Get the names of nodes deleted in this directory. + * @return A List of names. + */ + public List getDeletedNames() + { + List deleted = getDeleted(); + List listing = new ArrayList(); + for (DeletedChild child : deleted) + { + listing.add(child.getName()); + } + return listing; + } + /** * Lookup a child by name. * @param lPath The Lookup. diff --git a/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java b/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java index dcc72937fb..e13634576f 100644 --- a/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java +++ b/source/java/org/alfresco/repo/avm/PlainDirectoryNodeImpl.java @@ -17,6 +17,8 @@ package org.alfresco.repo.avm; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -90,7 +92,7 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory @SuppressWarnings("unchecked") public Map getListing(Lookup lPath) { - TreeMap result = new TreeMap(); + Map result = new HashMap(); List children = AVMContext.fgInstance.fChildEntryDAO.getByParent(this); for (ChildEntry child : children) { @@ -99,6 +101,16 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory return result; } + /** + * Get a listing of the nodes directly contained by a directory. + * @param lPath The Lookup to this directory. + * @return A Map of names to nodes. + */ + public Map getListingDirect(Lookup lPath) + { + return getListing(lPath); + } + /** * Get a listing of from a directory node descriptor. * @param dir The directory node descriptor. @@ -120,6 +132,15 @@ class PlainDirectoryNodeImpl extends DirectoryNodeImpl implements PlainDirectory return result; } + /** + * Get the names of nodes deleted in this directory. + * @return A List of names. + */ + public List getDeletedNames() + { + return new ArrayList(); + } + /** * Lookup a child by name. * @param lPath The lookup path so far.