Remote AVM Store no longer uses Lucene to find documents by qname path (was unreliable as cannot guarentee that a store snapshot has been performed after every doc operation - such as an FTP session to upload a new component def).

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11212 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-10-06 14:26:34 +00:00
parent 26e9314155
commit a1a59aee27
4 changed files with 57 additions and 64 deletions

View File

@@ -3,5 +3,6 @@
<description>Remote service mirroring the Store interface - to an AVM store</description> <description>Remote service mirroring the Store interface - to an AVM store</description>
<url>/remotestore/{method}/{path}</url> <url>/remotestore/{method}/{path}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction>
<format default="">argument</format> <format default="">argument</format>
</webscript> </webscript>

View File

@@ -4,5 +4,6 @@
<url>/remotestore/{method}</url> <url>/remotestore/{method}</url>
<url>/remotestore/{method}/{path}</url> <url>/remotestore/{method}/{path}</url>
<authentication>none</authentication> <authentication>none</authentication>
<transaction>required</transaction>
<format default="">argument</format> <format default="">argument</format>
</webscript> </webscript>

View File

@@ -3,5 +3,6 @@
<description>Remote service mirroring the Store interface - to an AVM store</description> <description>Remote service mirroring the Store interface - to an AVM store</description>
<url>/remotestore/{method}/{path}</url> <url>/remotestore/{method}/{path}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction>
<format default="">argument</format> <format default="">argument</format>
</webscript> </webscript>

View File

@@ -28,7 +28,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Writer; import java.io.Writer;
import java.net.SocketException; import java.net.SocketException;
import java.util.List;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -37,7 +36,6 @@ import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.web.scripts.RepoStore;
import org.alfresco.service.cmr.avm.AVMExistsException; import org.alfresco.service.cmr.avm.AVMExistsException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException; import org.alfresco.service.cmr.avm.AVMNotFoundException;
@@ -45,9 +43,6 @@ import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.web.scripts.Status; import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException; import org.alfresco.web.scripts.WebScriptException;
@@ -246,7 +241,6 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
avmService.createFile(parts[0], parts[1], content); avmService.createFile(parts[0], parts[1], content);
avmService.createSnapshot(store, "AVMRemoteStore.createDocument()", path);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -316,7 +310,6 @@ public class AVMRemoteStore extends BaseRemoteStore
try try
{ {
avmService.removeNode(avmPath); avmService.removeNode(avmPath);
avmService.createSnapshot(store, "AVMRemoteStore.deleteDocument()", path);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -343,7 +336,7 @@ public class AVMRemoteStore extends BaseRemoteStore
try try
{ {
traverseNode(res.getWriter(), node, recurse); traverseNode(res.getWriter(), node, null, recurse);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -355,25 +348,6 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
} }
private void traverseNode(Writer out, AVMNodeDescriptor node, boolean recurse)
throws IOException
{
int cropPoint = this.store.length() + this.rootPath.length() + 3;
SortedMap<String, AVMNodeDescriptor> listing = this.avmService.getDirectoryListing(node);
for (AVMNodeDescriptor n : listing.values())
{
if (n.isFile())
{
out.write(n.getPath().substring(cropPoint));
out.write("\n");
}
else if (recurse && n.isDirectory())
{
traverseNode(out, n, recurse);
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.web.scripts.bean.BaseRemoteStore#listDocuments(org.alfresco.web.scripts.WebScriptResponse, java.lang.String, java.lang.String) * @see org.alfresco.repo.web.scripts.bean.BaseRemoteStore#listDocuments(org.alfresco.web.scripts.WebScriptResponse, java.lang.String, java.lang.String)
*/ */
@@ -394,45 +368,19 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
String matcher = pattern.replace(".","\\.").replace("*",".*"); String matcher = pattern.replace(".","\\.").replace("*",".*");
final Pattern pat = Pattern.compile(matcher);
String encPath = RepoStore.encodePathISO9075(path);
final StringBuilder query = new StringBuilder(128);
query.append("+PATH:\"/").append(this.rootPath)
.append(encPath.length() != 0 ? ('/' + encPath) : "")
.append("//*\" +QNAME:")
.append(pattern);
final Writer out = res.getWriter();
final StoreRef avmStore = new StoreRef(StoreRef.PROTOCOL_AVM + StoreRef.URI_FILLER + this.store);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
@SuppressWarnings("synthetic-access")
public Object doWork() throws Exception
{
int cropPoint = store.length() + rootPath.length() + 3;
ResultSet resultSet = searchService.query(avmStore, SearchService.LANGUAGE_LUCENE, query.toString());
try try
{ {
List<NodeRef> nodes = resultSet.getNodeRefs(); traverseNode(res.getWriter(), node, Pattern.compile(matcher), true);
for (NodeRef nodeRef : nodes)
{
String path = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
String name = path.substring(path.lastIndexOf('/') + 1);
if (pat.matcher(name).matches())
{
out.write(path.substring(cropPoint));
out.write("\n");
}
} }
catch (AccessDeniedException ae)
{
res.setStatus(Status.STATUS_UNAUTHORIZED);
} }
finally finally
{ {
resultSet.close(); res.getWriter().close();
} }
return null;
}
}, AuthenticationUtil.getSystemUserName());
} }
/** /**
@@ -444,4 +392,46 @@ public class AVMRemoteStore extends BaseRemoteStore
{ {
return this.store + ":/" + this.rootPath + (path != null ? ("/" + path) : ""); return this.store + ":/" + this.rootPath + (path != null ? ("/" + path) : "");
} }
/**
* Traverse a Node and recursively output the file paths it contains.
*
* @param out Writer for output - relative paths separated by newline characters
* @param node The AVM Node to traverse
* @param pattern Optional Pattern to match filenames against
* @param recurse True to recurse sub-directories
*
* @throws IOException
*/
private void traverseNode(Writer out, AVMNodeDescriptor node, Pattern pattern, boolean recurse)
throws IOException
{
int cropPoint = this.store.length() + this.rootPath.length() + 3;
SortedMap<String, AVMNodeDescriptor> listing = this.avmService.getDirectoryListing(node);
for (AVMNodeDescriptor n : listing.values())
{
if (n.isFile())
{
String path = n.getPath();
if (pattern != null)
{
String name = path.substring(path.lastIndexOf('/') + 1);
if (pattern.matcher(name).matches())
{
out.write(path.substring(cropPoint));
out.write("\n");
}
}
else
{
out.write(path.substring(cropPoint));
out.write("\n");
}
}
else if (recurse && n.isDirectory())
{
traverseNode(out, n, pattern, recurse);
}
}
}
} }