From 0b1accf9f9d0cf7db918cf09bb4e1c8cbf99009f Mon Sep 17 00:00:00 2001 From: Britt Park Date: Fri, 29 Sep 2006 16:12:26 +0000 Subject: [PATCH] Added variants to getPaths, which get all HEAD paths for a node or all HEAD paths for a node in a given store. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3977 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/avm/AVMRepository.java | 104 +++++++++++++++++- .../org/alfresco/repo/avm/AVMServiceImpl.java | 28 +++++ .../org/alfresco/repo/avm/AVMServiceTest.java | 12 ++ .../alfresco/service/cmr/avm/AVMService.java | 15 +++ 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 13684fa579..24f05bbe99 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -932,12 +932,58 @@ public class AVMRepository public List> getPaths(AVMNodeDescriptor desc) { AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(desc.getId()); + if (node == null) + { + throw new AVMNotFoundException("Not found: " + desc.getPath()); + } List> paths = new ArrayList>(); List components = new ArrayList(); recursiveGetPaths(node, components, paths); return paths; } + /** + * Get all paths for a node reachable by HEAD. + * @param desc The node descriptor. + * @return A List of all the version, path Pairs that match. + */ + public List> getHeadPaths(AVMNodeDescriptor desc) + { + AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(desc.getId()); + if (node == null) + { + throw new AVMNotFoundException("Not found: " + desc.getPath()); + } + List> paths = new ArrayList>(); + List components = new ArrayList(); + recursiveGetHeadPaths(node, components, paths); + return paths; + } + + public List> getPathsInStoreHead(AVMNodeDescriptor desc, String store) + { + AVMStore st = getAVMStoreByName(store); + if (st == null) + { + throw new AVMNotFoundException("Store not found: " + store); + } + AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(desc.getId()); + if (node == null) + { + throw new AVMNotFoundException("Not found: " + desc.getPath()); + } + List> paths = new ArrayList>(); + List components = new ArrayList(); + recursiveGetPathsInStoreHead(node, components, paths, st.getRoot(), store); + return paths; + } + + /** + * Do the actual work. + * @param node The current node. + * @param components The currently accumulated path components. + * @param paths The list to put full paths in. + */ private void recursiveGetPaths(AVMNode node, List components, List> paths) { @@ -966,7 +1012,63 @@ public class AVMRepository components.remove(components.size() - 1); } } - + + /** + * Do the actual work. + * @param node The current node. + * @param components The currently accumulated path components. + * @param paths The list to put full paths in. + */ + private void recursiveGetHeadPaths(AVMNode node, List components, + List> paths) + { + if (node.getIsRoot()) + { + AVMStore store = AVMContext.fgInstance.fAVMStoreDAO.getByRoot(node); + if (store != null) + { + addPath(components, -1, store.getName(), paths); + return; + } + return; + } + List entries = AVMContext.fgInstance.fChildEntryDAO.getByChild(node); + for (ChildEntry entry : entries) + { + String name = entry.getName(); + components.add(name); + AVMNode parent = entry.getParent(); + recursiveGetHeadPaths(parent, components, paths); + components.remove(components.size() - 1); + } + } + + /** + * Do the actual work. + * @param node The current node. + * @param components The currently accumulated path components. + * @param paths The list to put full paths in. + */ + private void recursiveGetPathsInStoreHead(AVMNode node, List components, + List> paths, DirectoryNode root, + String storeName) + { + if (node.equals(root)) + { + addPath(components, -1, storeName, paths); + return; + } + List entries = AVMContext.fgInstance.fChildEntryDAO.getByChild(node); + for (ChildEntry entry : entries) + { + String name = entry.getName(); + components.add(name); + AVMNode parent = entry.getParent(); + recursiveGetHeadPaths(parent, components, paths); + components.remove(components.size() - 1); + } + } + /** * Add a path to the list. * @param components The path name components. diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index dafc8a2b32..960344be25 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -582,6 +582,34 @@ public class AVMServiceImpl implements AVMService return fAVMRepository.getPaths(desc); } + /** + * Get all paths that a given node has that are in the head version. + * @param desc The node descriptor to get paths for. + * @return A List of version, path Pairs. + */ + public List> getHeadPaths(AVMNodeDescriptor desc) + { + if (desc == null) + { + throw new AVMBadArgumentException("Descriptor is null."); + } + return fAVMRepository.getHeadPaths(desc); + } + + /** + * Get all paths to a node starting at the HEAD version of a store. + * @param desc The node descriptor. + * @param store The store. + * @return A List of all paths meeting the criteria. + */ + public List> getPathsInStoreHead(AVMNodeDescriptor desc, String store) + { + if (desc == null || store == null) + { + throw new AVMBadArgumentException("Illegal null argument."); + } + return fAVMRepository.getPathsInStoreHead(desc, store); + } /** * Purge an AVMStore. Permanently delete everything that diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index fa82bf45e5..72e3bde170 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -81,6 +81,18 @@ public class AVMServiceTest extends AVMServiceTestBase { System.out.println(path.getFirst() + " " + path.getSecond()); } + paths = fService.getHeadPaths(fService.lookup(-1, "main:/a/b/c/foo")); + System.out.println("------------------------------"); + for (Pair path : paths) + { + System.out.println(path.getFirst() + " " + path.getSecond()); + } + paths = fService.getPathsInStoreHead(fService.lookup(-1, "main:/a/b/c/foo"), "main"); + System.out.println("------------------------------"); + for (Pair path : paths) + { + System.out.println(path.getFirst() + " " + path.getSecond()); + } } catch (Exception e) { diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index 2d0eac10fa..16fea67d4d 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -415,6 +415,21 @@ public interface AVMService */ public List> getPaths(AVMNodeDescriptor desc); + /** + * Get all paths that a given node has that are in the head version. + * @param desc The node descriptor to get paths for. + * @return A List of version, path Pairs. + */ + public List> getHeadPaths(AVMNodeDescriptor desc); + + /** + * Get all paths to a node starting at the HEAD version of a store. + * @param desc The node descriptor. + * @param store The store. + * @return A List of all paths meeting the criteria. + */ + public List> getPathsInStoreHead(AVMNodeDescriptor desc, String store); + /** * Get the indirection path for a node in a layered context. * @param version The version number to get.