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

@@ -28,7 +28,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.net.SocketException;
import java.util.List;
import java.util.SortedMap;
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.RunAsWork;
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.AVMNodeDescriptor;
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.ContentReader;
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.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
@@ -246,7 +241,6 @@ public class AVMRemoteStore extends BaseRemoteStore
}
avmService.createFile(parts[0], parts[1], content);
avmService.createSnapshot(store, "AVMRemoteStore.createDocument()", path);
}
catch (AccessDeniedException ae)
{
@@ -316,7 +310,6 @@ public class AVMRemoteStore extends BaseRemoteStore
try
{
avmService.removeNode(avmPath);
avmService.createSnapshot(store, "AVMRemoteStore.deleteDocument()", path);
}
catch (AccessDeniedException ae)
{
@@ -343,7 +336,7 @@ public class AVMRemoteStore extends BaseRemoteStore
try
{
traverseNode(res.getWriter(), node, recurse);
traverseNode(res.getWriter(), node, null, recurse);
}
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)
* @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("*",".*");
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>()
try
{
@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
{
List<NodeRef> nodes = resultSet.getNodeRefs();
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");
}
}
}
finally
{
resultSet.close();
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
traverseNode(res.getWriter(), node, Pattern.compile(matcher), true);
}
catch (AccessDeniedException ae)
{
res.setStatus(Status.STATUS_UNAUTHORIZED);
}
finally
{
res.getWriter().close();
}
}
/**
@@ -444,4 +392,46 @@ public class AVMRemoteStore extends BaseRemoteStore
{
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);
}
}
}
}