mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added getDirectoryListingDirect() and getDeleted() to AVMService
interface. These return respectively those nodes directly contained by a directory and the names of those nodes that have been deleted in a directory. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3383 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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<String, AVMNodeDescriptor> 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<String> 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.
|
||||
|
@@ -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 <code>path</code> is not found.
|
||||
* @throws AVMWrongTypeException If <code>path</code> contains a non-terminal
|
||||
* component that is not a directory, or if <code>path</code> is not pointing
|
||||
@@ -93,6 +93,20 @@ public interface AVMService
|
||||
*/
|
||||
public SortedMap<String, AVMNodeDescriptor> 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 <code>path</code> does not exist.
|
||||
* @throws AVMWrongTypeException If <code>path</code> contains any non-directory
|
||||
* elements.
|
||||
*/
|
||||
public SortedMap<String, AVMNodeDescriptor>
|
||||
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<String, AVMNodeDescriptor> 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 <code>path</code> does not exist.
|
||||
* @throws AVMWrongTypeException If <code>path</code> contains any elements
|
||||
* that are not directories.
|
||||
*/
|
||||
public List<String> getDeleted(int version, String path);
|
||||
|
||||
/**
|
||||
* Create a new File. Fails if the file already exists.
|
||||
* @param path The simple absolute path to the parent.
|
||||
|
@@ -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 <code>path</code> does not exist.
|
||||
* @throws AVMWrongTypeException If <code>path</code> contains any non-directory
|
||||
* elements.
|
||||
*/
|
||||
public SortedMap<String, AVMNodeDescriptor>
|
||||
getDirectoryListingDirect(final int version, final String path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null path.");
|
||||
}
|
||||
class TxnCallback implements RetryingTransactionCallback
|
||||
{
|
||||
public SortedMap<String, AVMNodeDescriptor> 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 <code>path</code> does not exist.
|
||||
* @throws AVMWrongTypeException If <code>path</code> contains any elements
|
||||
* that are not directories.
|
||||
*/
|
||||
public List<String> getDeleted(final int version, final String path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Null path.");
|
||||
}
|
||||
class TxnCallback implements RetryingTransactionCallback
|
||||
{
|
||||
public List<String> 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.
|
||||
|
@@ -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<String> 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<String, AVMNodeDescriptor> 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.
|
||||
*/
|
||||
|
@@ -110,7 +110,23 @@ interface AVMStore
|
||||
* @return A listing.
|
||||
*/
|
||||
public SortedMap<String, AVMNodeDescriptor> 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<String, AVMNodeDescriptor> 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<String> getDeleted(int version, String path);
|
||||
|
||||
/**
|
||||
* Get an output stream to a file.
|
||||
* @param path The path to the file.
|
||||
|
@@ -307,6 +307,33 @@ class AVMStoreImpl implements AVMStore, Serializable
|
||||
Lookup lPath = lookupDirectory(version, path, false);
|
||||
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
|
||||
Map<String, AVMNode> 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<String, AVMNodeDescriptor> getListingDirect(int version, String path)
|
||||
{
|
||||
Lookup lPath = lookupDirectory(version, path, false);
|
||||
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
|
||||
Map<String, AVMNode> 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<String, AVMNodeDescriptor>
|
||||
translateListing(Map<String, AVMNode> listing, Lookup lPath)
|
||||
{
|
||||
SortedMap<String, AVMNodeDescriptor> results = new TreeMap<String, AVMNodeDescriptor>();
|
||||
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<String> 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.
|
||||
|
@@ -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<String, AVMNode> 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<String, AVMNode> 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<String, AVMNodeDescriptor> getListing(AVMNodeDescriptor dir);
|
||||
|
||||
/**
|
||||
* Get the names of nodes deleted in this directory.
|
||||
* @return A List of names.
|
||||
*/
|
||||
public List<String> getDeletedNames();
|
||||
|
||||
/**
|
||||
* Set the directory, which must be in a layer, into a primary
|
||||
|
@@ -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<String, AVMNode> getListingDirect(Lookup lPath)
|
||||
{
|
||||
Map<String, AVMNode> listing = new HashMap<String, AVMNode>();
|
||||
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<String> getDeletedNames()
|
||||
{
|
||||
List<DeletedChild> deleted = getDeleted();
|
||||
List<String> listing = new ArrayList<String>();
|
||||
for (DeletedChild child : deleted)
|
||||
{
|
||||
listing.add(child.getName());
|
||||
}
|
||||
return listing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a child by name.
|
||||
* @param lPath The Lookup.
|
||||
|
@@ -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<String, AVMNode> getListing(Lookup lPath)
|
||||
{
|
||||
TreeMap<String, AVMNode> result = new TreeMap<String, AVMNode>();
|
||||
Map<String, AVMNode> result = new HashMap<String, AVMNode>();
|
||||
List<ChildEntry> 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<String, AVMNode> 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<String> getDeletedNames()
|
||||
{
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a child by name.
|
||||
* @param lPath The lookup path so far.
|
||||
|
Reference in New Issue
Block a user