mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-09 17:45:10 +00:00
Added utility method to get a path for an AVM node as quickly as possible. Switched history
viewing to use it. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4944 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
30007cca42
commit
c45bb470ba
@ -1004,6 +1004,7 @@
|
||||
<value>getContentDataForRead</value>
|
||||
<value>getAspects</value>
|
||||
<value>hasAspect</value>
|
||||
<value>getAPath</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
@ -18,6 +18,7 @@ import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
import org.alfresco.service.cmr.remote.AVMRemote;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* A loopback implementation of the AVMRemote interface?
|
||||
@ -487,4 +488,12 @@ public class AVMRemoteLocal implements AVMRemote
|
||||
{
|
||||
fService.revert(path, toRevertTo);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AVMRemote#getAPath(org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc)
|
||||
{
|
||||
return fService.getAPath(desc);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.alfresco.service.cmr.remote.AVMRemoteTransport;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Implementation of AVMRemoteTransport for the server side. It's
|
||||
@ -1008,4 +1009,13 @@ public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable
|
||||
fAuthService.validate(ticket);
|
||||
fAVMService.revert(path, toRevertTo);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AVMRemoteTransport#getAPath(java.lang.String, org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(String ticket, AVMNodeDescriptor desc)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
return fAVMService.getAPath(desc);
|
||||
}
|
||||
}
|
||||
|
@ -1254,6 +1254,22 @@ public class AVMRepository
|
||||
return paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single valid path for a node.
|
||||
* @param desc The node descriptor.
|
||||
* @return A version, path
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc)
|
||||
{
|
||||
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(desc.getId());
|
||||
if (node == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Could not find node: " + desc);
|
||||
}
|
||||
List<String> components = new ArrayList<String>();
|
||||
return recursiveGetAPath(node, components);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paths for a node reachable by HEAD.
|
||||
* @param desc The node descriptor.
|
||||
@ -1272,6 +1288,13 @@ public class AVMRepository
|
||||
return paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paths in a particular store in the head version for
|
||||
* a particular node.
|
||||
* @param desc The node descriptor.
|
||||
* @param store The name of the store.
|
||||
* @return All matching paths.
|
||||
*/
|
||||
public List<Pair<Integer, String>> getPathsInStoreHead(AVMNodeDescriptor desc, String store)
|
||||
{
|
||||
AVMStore st = getAVMStoreByName(store);
|
||||
@ -1325,6 +1348,43 @@ public class AVMRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the work of getting one path for a node.
|
||||
* @param node The node to get the path of.
|
||||
* @param components The storage for path components.
|
||||
* @return A path or null.
|
||||
*/
|
||||
private Pair<Integer, String> recursiveGetAPath(AVMNode node, List<String> components)
|
||||
{
|
||||
if (node.getIsRoot())
|
||||
{
|
||||
AVMStore store = AVMDAOs.Instance().fAVMStoreDAO.getByRoot(node);
|
||||
if (store != null)
|
||||
{
|
||||
return new Pair<Integer, String>(-1, makePath(components, store.getName()));
|
||||
}
|
||||
VersionRoot vr = AVMDAOs.Instance().fVersionRootDAO.getByRoot(node);
|
||||
if (vr != null)
|
||||
{
|
||||
return new Pair<Integer, String>(vr.getVersionID(), makePath(components, vr.getAvmStore().getName()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
List<ChildEntry> entries = AVMDAOs.Instance().fChildEntryDAO.getByChild(node);
|
||||
for (ChildEntry entry : entries)
|
||||
{
|
||||
String name = entry.getKey().getName();
|
||||
components.add(name);
|
||||
Pair<Integer, String> path = recursiveGetAPath(entry.getKey().getParent(), components);
|
||||
if (path != null)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
components.remove(components.size() - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the actual work.
|
||||
* @param node The current node.
|
||||
@ -1390,6 +1450,17 @@ public class AVMRepository
|
||||
*/
|
||||
private void addPath(List<String> components, int version, String storeName,
|
||||
List<Pair<Integer, String>> paths)
|
||||
{
|
||||
paths.add(new Pair<Integer, String>(version, makePath(components, storeName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for generating paths.
|
||||
* @param components The path components.
|
||||
* @param storeName The store that the path is in.
|
||||
* @return The path.
|
||||
*/
|
||||
private String makePath(List<String> components, String storeName)
|
||||
{
|
||||
StringBuilder pathBuilder = new StringBuilder();
|
||||
pathBuilder.append(storeName);
|
||||
@ -1397,17 +1468,16 @@ public class AVMRepository
|
||||
if (components.size() == 0)
|
||||
{
|
||||
pathBuilder.append("/");
|
||||
paths.add(new Pair<Integer, String>(version, pathBuilder.toString()));
|
||||
return;
|
||||
return pathBuilder.toString();
|
||||
}
|
||||
for (int i = components.size() - 1; i >= 0; i--)
|
||||
{
|
||||
pathBuilder.append("/");
|
||||
pathBuilder.append(components.get(i));
|
||||
}
|
||||
paths.add(new Pair<Integer, String>(version, pathBuilder.toString()));
|
||||
return pathBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get information about layering of a path.
|
||||
* @param version The version to look under.
|
||||
|
@ -716,6 +716,18 @@ public class AVMServiceImpl implements AVMService
|
||||
return fAVMRepository.getPaths(desc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.avm.AVMService#getAPath(org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc)
|
||||
{
|
||||
if (desc == null)
|
||||
{
|
||||
throw new AVMBadArgumentException("Descriptor is null.");
|
||||
}
|
||||
return fAVMRepository.getAPath(desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all paths that a given node has that are in the head version.
|
||||
* @param desc The node descriptor to get paths for.
|
||||
|
@ -295,6 +295,7 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
{
|
||||
System.out.println(path.getFirst() + " " + path.getSecond());
|
||||
}
|
||||
assertNotNull(fService.getAPath(fService.lookup(-1, "main:/a/b/c/foo")));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
import org.alfresco.service.cmr.remote.AVMRemote;
|
||||
import org.alfresco.service.cmr.remote.AVMRemoteTransport;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Client side wrapper for AVMRemoteTransport.
|
||||
@ -491,4 +492,12 @@ public class AVMRemoteImpl implements AVMRemote
|
||||
{
|
||||
fTransport.revert(ClientTicketHolder.GetTicket(), path, toRevertTo);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.AVMRemote#getAPath(org.alfresco.service.cmr.avm.AVMNodeDescriptor)
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc)
|
||||
{
|
||||
return fTransport.getAPath(ClientTicketHolder.GetTicket(), desc);
|
||||
}
|
||||
}
|
||||
|
@ -778,6 +778,13 @@ public interface AVMService
|
||||
public List<Pair<Integer, String>> getPaths(AVMNodeDescriptor desc);
|
||||
|
||||
|
||||
/**
|
||||
* Get a single valid path to a given node.
|
||||
* @param desc The node descriptor to get a path for.
|
||||
* @return AVMNotFoundException
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc);
|
||||
|
||||
/**
|
||||
* Get all paths that a given node has that are in the
|
||||
* <strong><code>HEAD</code></strong> version (<strong><code> -1 </code></strong>).
|
||||
|
@ -32,6 +32,7 @@ import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Remote interface for AVM.
|
||||
@ -452,5 +453,13 @@ public interface AVMRemote
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
* @throws AVMNotFoundException
|
||||
*/
|
||||
public void revert(String path, AVMNodeDescriptor toRevertTo);
|
||||
public void revert(String path, AVMNodeDescriptor toRevertTo);
|
||||
|
||||
/**
|
||||
* Get a version and path of a node.
|
||||
* @param desc The descriptor for the node to which we want a path.
|
||||
* @return version and path.
|
||||
* @throws AVMNotFoundException
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(AVMNodeDescriptor desc);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
import org.alfresco.service.cmr.avm.LayeringDescriptor;
|
||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* This is the actual remote interface that is wrapped by
|
||||
@ -470,5 +471,13 @@ public interface AVMRemoteTransport
|
||||
* @param toRevertTo The descriptor of the version to revert to.
|
||||
* @throws AVMNotFoundException
|
||||
*/
|
||||
public void revert(String ticket, String path, AVMNodeDescriptor toRevertTo);
|
||||
public void revert(String ticket, String path, AVMNodeDescriptor toRevertTo);
|
||||
|
||||
/**
|
||||
* Get a version and path for a node.
|
||||
* @param ticket The authentication ticket.
|
||||
* @param desc The node descriptor for the node we want to get a path to.
|
||||
* @return version and path.
|
||||
*/
|
||||
public Pair<Integer, String> getAPath(String ticket, AVMNodeDescriptor desc);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user