mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-9086 "RINF 52: Lucene Removal: Fix FileFolderService search methods"
- changed wildcard character to '*' git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29567 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -479,33 +479,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
|
||||||
// {
|
|
||||||
// Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
|
||||||
//
|
|
||||||
// // get canned query
|
|
||||||
// GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_FILEFOLDER_LIST);
|
|
||||||
//
|
|
||||||
// GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, null, pattern, null, sortProps, pagingRequest);
|
|
||||||
//
|
|
||||||
// // execute canned query
|
|
||||||
// CannedQueryResults<NodeRef> results = cq.execute();
|
|
||||||
//
|
|
||||||
// if (start != null)
|
|
||||||
// {
|
|
||||||
// int cnt = results.getPagedResultCount();
|
|
||||||
// int skipCount = pagingRequest.getSkipCount();
|
|
||||||
// int maxItems = pagingRequest.getMaxItems();
|
|
||||||
// boolean hasMoreItems = results.hasMoreItems();
|
|
||||||
// Pair<Integer, Integer> totalCount = (pagingRequest.getRequestTotalCountMax() > 0 ? results.getTotalResultCount() : null);
|
|
||||||
// int pageNum = (skipCount / maxItems) + 1;
|
|
||||||
//
|
|
||||||
// logger.debug("List: "+cnt+" items in "+(System.currentTimeMillis()-start)+" msecs [pageNum="+pageNum+",skip="+skipCount+",max="+maxItems+",hasMorePages="+hasMoreItems+",totalCount="+totalCount+",parentNodeRef="+contextNodeRef+"]");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return results;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public List<FileInfo> listFiles(NodeRef contextNodeRef)
|
public List<FileInfo> listFiles(NodeRef contextNodeRef)
|
||||||
{
|
{
|
||||||
// execute the query
|
// execute the query
|
||||||
|
@@ -1147,7 +1147,7 @@ public class FileFolderServiceImplTest extends TestCase
|
|||||||
|
|
||||||
// test 1
|
// test 1
|
||||||
PagingRequest pagingRequest = new PagingRequest(100, null);
|
PagingRequest pagingRequest = new PagingRequest(100, null);
|
||||||
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0%", null, null, pagingRequest);
|
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0*", null, null, pagingRequest);
|
||||||
|
|
||||||
assertNotNull(pagingResults);
|
assertNotNull(pagingResults);
|
||||||
assertFalse(pagingResults.hasMoreItems());
|
assertFalse(pagingResults.hasMoreItems());
|
||||||
@@ -1161,7 +1161,7 @@ public class FileFolderServiceImplTest extends TestCase
|
|||||||
checkFileList(files, 2, 3, expectedNames);
|
checkFileList(files, 2, 3, expectedNames);
|
||||||
|
|
||||||
// test 2
|
// test 2
|
||||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L1%", null, null, pagingRequest);
|
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L1*", null, null, pagingRequest);
|
||||||
|
|
||||||
assertNotNull(pagingResults);
|
assertNotNull(pagingResults);
|
||||||
assertFalse(pagingResults.hasMoreItems());
|
assertFalse(pagingResults.hasMoreItems());
|
||||||
@@ -1175,7 +1175,7 @@ public class FileFolderServiceImplTest extends TestCase
|
|||||||
checkFileList(files, 0, 0, expectedNames);
|
checkFileList(files, 0, 0, expectedNames);
|
||||||
|
|
||||||
// test 3
|
// test 3
|
||||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0%File%", null, null, pagingRequest);
|
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0*File*", null, null, pagingRequest);
|
||||||
|
|
||||||
assertNotNull(pagingResults);
|
assertNotNull(pagingResults);
|
||||||
assertFalse(pagingResults.hasMoreItems());
|
assertFalse(pagingResults.hasMoreItems());
|
||||||
|
@@ -74,9 +74,36 @@ public class FilterSortNodeEntity
|
|||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String escape(String s, char escapeChar)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int idx = -1;
|
||||||
|
int offset = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
idx = s.indexOf(escapeChar, offset);
|
||||||
|
if(idx != -1)
|
||||||
|
{
|
||||||
|
sb.append(s.substring(offset, idx));
|
||||||
|
sb.append("\\");
|
||||||
|
sb.append(escapeChar);
|
||||||
|
offset = idx + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(idx != -1);
|
||||||
|
sb.append(s.substring(offset));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void setPattern(String pattern)
|
public void setPattern(String pattern)
|
||||||
{
|
{
|
||||||
this.pattern = pattern;
|
if(pattern != null)
|
||||||
|
{
|
||||||
|
// escape the '%' character with '\' (standard SQL escape character)
|
||||||
|
pattern = escape(pattern, '%');
|
||||||
|
// replace the wildcard character '*' with the one used in database queries i.e. '%'
|
||||||
|
this.pattern = pattern.replace('*', '%');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getNamePropertyQNameId()
|
public Long getNamePropertyQNameId()
|
||||||
|
@@ -116,6 +116,7 @@ public class GetChildrenCannedQueryFactory extends AbstractCannedQueryFactory<No
|
|||||||
* Note: if both filtering and sorting is required then the combined total of unique QName properties should be the 0 to 3.
|
* Note: if both filtering and sorting is required then the combined total of unique QName properties should be the 0 to 3.
|
||||||
*
|
*
|
||||||
* @param parentRef parent node ref
|
* @param parentRef parent node ref
|
||||||
|
* @param pattern the pattern to use to filter children (wildcard character is '*')
|
||||||
* @param childTypeQNames type qnames of children nodes (pre-filter)
|
* @param childTypeQNames type qnames of children nodes (pre-filter)
|
||||||
* @param filterProps filter properties
|
* @param filterProps filter properties
|
||||||
* @param sortProps sort property pairs (QName and Boolean - true if ascending)
|
* @param sortProps sort property pairs (QName and Boolean - true if ascending)
|
||||||
|
@@ -22,7 +22,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
|
@@ -545,45 +545,79 @@ public class GetChildrenCannedQueryTest extends TestCase
|
|||||||
NodeRef nodeRef2 = createContent(parentNodeRef, "page.component-1-4.user~admin~dashboard.xml", ContentModel.TYPE_CONTENT);
|
NodeRef nodeRef2 = createContent(parentNodeRef, "page.component-1-4.user~admin~dashboard.xml", ContentModel.TYPE_CONTENT);
|
||||||
NodeRef nodeRef3 = createContent(parentNodeRef, "page.xml", ContentModel.TYPE_CONTENT);
|
NodeRef nodeRef3 = createContent(parentNodeRef, "page.xml", ContentModel.TYPE_CONTENT);
|
||||||
NodeRef nodeRef4 = createContent(parentNodeRef, "page.component-1-4.user~admin~panel.xml", ContentModel.TYPE_CONTENT);
|
NodeRef nodeRef4 = createContent(parentNodeRef, "page.component-1-4.user~admin~panel.xml", ContentModel.TYPE_CONTENT);
|
||||||
|
NodeRef nodeRef5 = createContent(parentNodeRef, "page.component-1-4.user~admin~%dashboard.xml", ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
AuthenticationUtil.popAuthentication();
|
AuthenticationUtil.popAuthentication();
|
||||||
|
|
||||||
String pattern = "page.%.user~admin~dashboard.xml";
|
String pattern = "page.*.user~admin~%dashboard.xml";
|
||||||
PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
assertFalse(results.hasMoreItems());
|
assertFalse(results.hasMoreItems());
|
||||||
|
|
||||||
int totalCnt = results.getPage().size();
|
int totalCnt = results.getPage().size();
|
||||||
|
assertTrue(totalCnt == 1);
|
||||||
|
assertEquals(nodeRef5, results.getPage().get(0));
|
||||||
|
|
||||||
|
pattern = "page.*.user~admin~dashboard.xml";
|
||||||
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
|
assertFalse(results.hasMoreItems());
|
||||||
|
|
||||||
|
totalCnt = results.getPage().size();
|
||||||
assertTrue(totalCnt == 2);
|
assertTrue(totalCnt == 2);
|
||||||
assertEquals(nodeRef1, results.getPage().get(0));
|
assertEquals(nodeRef1, results.getPage().get(0));
|
||||||
assertEquals(nodeRef2, results.getPage().get(1));
|
assertEquals(nodeRef2, results.getPage().get(1));
|
||||||
|
|
||||||
pattern = "%";
|
pattern = "*";
|
||||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
assertFalse(results.hasMoreItems());
|
assertFalse(results.hasMoreItems());
|
||||||
totalCnt = results.getPage().size();
|
totalCnt = results.getPage().size();
|
||||||
assertTrue(totalCnt == 4);
|
assertTrue(totalCnt == 5);
|
||||||
assertEquals(nodeRef1, results.getPage().get(0));
|
assertEquals(nodeRef1, results.getPage().get(0));
|
||||||
assertEquals(nodeRef2, results.getPage().get(1));
|
assertEquals(nodeRef2, results.getPage().get(1));
|
||||||
assertEquals(nodeRef3, results.getPage().get(2));
|
assertEquals(nodeRef3, results.getPage().get(2));
|
||||||
assertEquals(nodeRef4, results.getPage().get(3));
|
assertEquals(nodeRef4, results.getPage().get(3));
|
||||||
|
assertEquals(nodeRef5, results.getPage().get(4));
|
||||||
|
|
||||||
pattern = "foo%bar";
|
pattern = "foo*bar";
|
||||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
assertFalse(results.hasMoreItems());
|
assertFalse(results.hasMoreItems());
|
||||||
totalCnt = results.getPage().size();
|
totalCnt = results.getPage().size();
|
||||||
assertTrue(totalCnt == 0);
|
assertEquals("", 0, totalCnt);
|
||||||
|
|
||||||
pattern = "page.%.admin~dashboard.xml";
|
pattern = "page.*.admin~dashboard.xml";
|
||||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
assertFalse(results.hasMoreItems());
|
assertFalse(results.hasMoreItems());
|
||||||
totalCnt = results.getPage().size();
|
totalCnt = results.getPage().size();
|
||||||
assertTrue(totalCnt == 0);
|
assertEquals("", 0, totalCnt);
|
||||||
|
|
||||||
|
pattern = "page.*.user~admin~*.xml";
|
||||||
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
|
assertFalse(results.hasMoreItems());
|
||||||
|
totalCnt = results.getPage().size();
|
||||||
|
assertEquals("", 4, totalCnt);
|
||||||
|
|
||||||
|
pattern = "page.*.user~admin~%*.xml";
|
||||||
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
|
assertFalse(results.hasMoreItems());
|
||||||
|
totalCnt = results.getPage().size();
|
||||||
|
assertEquals("", 1, totalCnt);
|
||||||
|
|
||||||
|
pattern = "page.*.user~admin~%dashboard.xml";
|
||||||
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
|
assertFalse(results.hasMoreItems());
|
||||||
|
totalCnt = results.getPage().size();
|
||||||
|
assertEquals("", 1, totalCnt);
|
||||||
|
|
||||||
|
pattern = "page.component-1-4.user~admin~%dashboard.xml";
|
||||||
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
|
assertFalse(results.hasMoreItems());
|
||||||
|
totalCnt = results.getPage().size();
|
||||||
|
assertEquals("", 1, totalCnt);
|
||||||
|
|
||||||
pattern = "page.%.user~admin~%.xml";
|
pattern = "page.%.user~admin~%.xml";
|
||||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||||
assertFalse(results.hasMoreItems());
|
assertFalse(results.hasMoreItems());
|
||||||
totalCnt = results.getPage().size();
|
totalCnt = results.getPage().size();
|
||||||
assertTrue(totalCnt == 3);
|
assertEquals("", 0, totalCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test helper method - optional filtering/sorting
|
// test helper method - optional filtering/sorting
|
||||||
|
@@ -73,7 +73,7 @@ public interface FileFolderService
|
|||||||
* Lists page of immediate child files and/or folders of the given context node
|
* Lists page of immediate child files and/or folders of the given context node
|
||||||
* with pattern matching and optional filtering (exclusion of certain child file/folder subtypes) and sorting
|
* with pattern matching and optional filtering (exclusion of certain child file/folder subtypes) and sorting
|
||||||
*
|
*
|
||||||
* Pattern uses '%' as a wildcard
|
* Pattern uses '*' as a wildcard
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user