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"
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29546 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -46,6 +46,8 @@ public class FilterSortNodeEntity
|
||||
private Long prop2qnameId;
|
||||
private Long prop3qnameId;
|
||||
private List<Long> childNodeTypeQNameIds;
|
||||
private String pattern;
|
||||
private Long namePropertyQNameId;
|
||||
private boolean auditableProps;
|
||||
private boolean nodeType;
|
||||
|
||||
@@ -67,7 +69,27 @@ public class FilterSortNodeEntity
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public NodePropertyEntity getProp1()
|
||||
public String getPattern()
|
||||
{
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setPattern(String pattern)
|
||||
{
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public Long getNamePropertyQNameId()
|
||||
{
|
||||
return namePropertyQNameId;
|
||||
}
|
||||
|
||||
public void setNamePropertyQNameId(Long namePropertyQNameId)
|
||||
{
|
||||
this.namePropertyQNameId = namePropertyQNameId;
|
||||
}
|
||||
|
||||
public NodePropertyEntity getProp1()
|
||||
{
|
||||
return prop1;
|
||||
}
|
||||
|
@@ -153,6 +153,7 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeR
|
||||
// Get filter details
|
||||
Set<QName> childNodeTypeQNames = paramBean.getChildTypeQNames();
|
||||
final List<FilterProp> filterProps = paramBean.getFilterProps();
|
||||
String pattern = paramBean.getPattern();
|
||||
|
||||
// Get sort details
|
||||
CannedQuerySortDetails sortDetails = parameters.getSortDetails();
|
||||
@@ -190,6 +191,19 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeR
|
||||
}
|
||||
}
|
||||
|
||||
if (pattern != null)
|
||||
{
|
||||
// TODO, check that we should be tied to the content model in this way. Perhaps a configurable property
|
||||
// name against which compare the pattern?
|
||||
Pair<Long, QName> nameQName = qnameDAO.getQName(ContentModel.PROP_NAME);
|
||||
if(nameQName == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to determine qname id of name property");
|
||||
}
|
||||
params.setNamePropertyQNameId(nameQName.getFirst());
|
||||
params.setPattern(pattern);
|
||||
}
|
||||
|
||||
final List<NodeRef> result;
|
||||
|
||||
if (filterSortPropCnt > 0)
|
||||
|
@@ -123,7 +123,7 @@ public class GetChildrenCannedQueryFactory extends AbstractCannedQueryFactory<No
|
||||
*
|
||||
* @return an implementation that will execute the query
|
||||
*/
|
||||
public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, Set<QName> childTypeQNames, List<FilterProp> filterProps, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, String pattern, Set<QName> childTypeQNames, List<FilterProp> filterProps, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
{
|
||||
ParameterCheck.mandatory("parentRef", parentRef);
|
||||
ParameterCheck.mandatory("pagingRequest", pagingRequest);
|
||||
@@ -131,8 +131,8 @@ public class GetChildrenCannedQueryFactory extends AbstractCannedQueryFactory<No
|
||||
int requestTotalCountMax = pagingRequest.getRequestTotalCountMax();
|
||||
|
||||
// specific query params - context (parent) and inclusive filters (child types, property values)
|
||||
GetChildrenCannedQueryParams paramBean = new GetChildrenCannedQueryParams(tenantService.getName(parentRef), childTypeQNames, filterProps);
|
||||
|
||||
GetChildrenCannedQueryParams paramBean = new GetChildrenCannedQueryParams(tenantService.getName(parentRef), childTypeQNames, filterProps, pattern);
|
||||
|
||||
// page details
|
||||
CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT);
|
||||
|
||||
@@ -165,9 +165,9 @@ public class GetChildrenCannedQueryFactory extends AbstractCannedQueryFactory<No
|
||||
*
|
||||
* @return an implementation that will execute the query
|
||||
*/
|
||||
public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, Set<QName> childTypeQNames, PagingRequest pagingRequest)
|
||||
public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, String pattern,Set<QName> childTypeQNames, PagingRequest pagingRequest)
|
||||
{
|
||||
return getCannedQuery(parentRef, childTypeQNames, null, null, pagingRequest);
|
||||
return getCannedQuery(parentRef, pattern, childTypeQNames, null, null, pagingRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
@@ -37,13 +38,18 @@ public class GetChildrenCannedQueryParams
|
||||
|
||||
private Set<QName> childTypeQNames = Collections.emptySet();
|
||||
private List<FilterProp> filterProps = Collections.emptyList();
|
||||
private String pattern = null;
|
||||
|
||||
public GetChildrenCannedQueryParams(NodeRef parentRef, Set<QName> childTypeQNames, List<FilterProp> filterProps)
|
||||
public GetChildrenCannedQueryParams(NodeRef parentRef, Set<QName> childTypeQNames, List<FilterProp> filterProps, String pattern)
|
||||
{
|
||||
this.parentRef = parentRef;
|
||||
|
||||
|
||||
if (childTypeQNames != null) { this.childTypeQNames = childTypeQNames; }
|
||||
if (filterProps != null) { this.filterProps = filterProps; }
|
||||
if (pattern != null)
|
||||
{
|
||||
this.pattern = pattern;
|
||||
}
|
||||
}
|
||||
|
||||
public NodeRef getParentRef()
|
||||
@@ -60,4 +66,9 @@ public class GetChildrenCannedQueryParams
|
||||
{
|
||||
return filterProps;
|
||||
}
|
||||
|
||||
public String getPattern()
|
||||
{
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
|
@@ -141,7 +141,7 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
getChildrenCannedQueryFactory.setMethodSecurity((MethodSecurityBean<NodeRef>)ctx.getBean("FileFolderService_security_list"));
|
||||
|
||||
getChildrenCannedQueryFactory.afterPropertiesSet();
|
||||
|
||||
|
||||
if (! setupTestData)
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
@@ -177,7 +177,7 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
loadContent(testParentFolder, "quick.xml", "ZZ title" +TEST_RUN, "BB description", canRead, permMisses);
|
||||
|
||||
setupTestData = true;
|
||||
|
||||
|
||||
// double-check permissions - see testPermissions
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
|
||||
@@ -529,6 +529,87 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testPatterns() throws Exception
|
||||
{
|
||||
AuthenticationUtil.pushAuthentication();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
NodeRef parentNodeRef = nodeService.createNode(
|
||||
repositoryHelper.getCompanyHome(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()),
|
||||
ContentModel.TYPE_FOLDER, null).getChildRef();
|
||||
|
||||
// set up some nodes to test patterns
|
||||
NodeRef nodeRef1 = createContent(parentNodeRef, "page.component-1-2.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 nodeRef4 = createContent(parentNodeRef, "page.component-1-4.user~admin~panel.xml", ContentModel.TYPE_CONTENT);
|
||||
|
||||
AuthenticationUtil.popAuthentication();
|
||||
|
||||
String pattern = "page.%.user~admin~dashboard.xml";
|
||||
PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||
assertFalse(results.hasMoreItems());
|
||||
|
||||
int totalCnt = results.getPage().size();
|
||||
assertTrue(totalCnt == 2);
|
||||
assertEquals(nodeRef1, results.getPage().get(0));
|
||||
assertEquals(nodeRef2, results.getPage().get(1));
|
||||
|
||||
pattern = "%";
|
||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||
assertFalse(results.hasMoreItems());
|
||||
totalCnt = results.getPage().size();
|
||||
assertTrue(totalCnt == 4);
|
||||
assertEquals(nodeRef1, results.getPage().get(0));
|
||||
assertEquals(nodeRef2, results.getPage().get(1));
|
||||
assertEquals(nodeRef3, results.getPage().get(2));
|
||||
assertEquals(nodeRef4, results.getPage().get(3));
|
||||
|
||||
pattern = "foo%bar";
|
||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||
assertFalse(results.hasMoreItems());
|
||||
totalCnt = results.getPage().size();
|
||||
assertTrue(totalCnt == 0);
|
||||
|
||||
pattern = "page.%.admin~dashboard.xml";
|
||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||
assertFalse(results.hasMoreItems());
|
||||
totalCnt = results.getPage().size();
|
||||
assertTrue(totalCnt == 0);
|
||||
|
||||
pattern = "page.%.user~admin~%.xml";
|
||||
results = list(parentNodeRef, -1, -1, 0, pattern, null);
|
||||
assertFalse(results.hasMoreItems());
|
||||
totalCnt = results.getPage().size();
|
||||
assertTrue(totalCnt == 3);
|
||||
}
|
||||
|
||||
// test helper method - optional filtering/sorting
|
||||
private PagingResults<NodeRef> list(NodeRef parentNodeRef, final int skipCount, final int maxItems, final int requestTotalCountMax, String pattern, List<Pair<QName, Boolean>> sortProps)
|
||||
{
|
||||
PagingRequest pagingRequest = new PagingRequest(skipCount, maxItems, null);
|
||||
pagingRequest.setRequestTotalCountMax(requestTotalCountMax);
|
||||
|
||||
// get canned query
|
||||
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject("getChildrenCannedQueryFactory");
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(parentNodeRef, pattern, null, null, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
|
||||
List<NodeRef> nodeRefs = results.getPages().get(0);
|
||||
|
||||
Integer totalCount = null;
|
||||
if (requestTotalCountMax > 0)
|
||||
{
|
||||
totalCount = results.getTotalResultCount().getFirst();
|
||||
}
|
||||
|
||||
return new PagingNodeRefResultsImpl(nodeRefs, results.hasMoreItems(), totalCount, false);
|
||||
}
|
||||
|
||||
private void filterByTypeAndCheck(NodeRef parentNodeRef, Set<QName> childTypeQNames, Set<QName> antiChildTypeQNames)
|
||||
{
|
||||
// belts-and-braces
|
||||
@@ -752,7 +833,7 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
|
||||
// get canned query
|
||||
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject("getChildrenCannedQueryFactory");
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(parentNodeRef, childTypeQNames, filterProps, sortProps, pagingRequest);
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(parentNodeRef, null, childTypeQNames, filterProps, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
@@ -824,7 +905,7 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
properties).getChildRef();
|
||||
}
|
||||
|
||||
private void createContent(NodeRef parentNodeRef, String fileName, QName contentType) throws IOException
|
||||
private NodeRef createContent(NodeRef parentNodeRef, String fileName, QName contentType) throws IOException
|
||||
{
|
||||
Map<QName,Serializable> properties = new HashMap<QName,Serializable>();
|
||||
properties.put(ContentModel.PROP_NAME, fileName);
|
||||
@@ -846,6 +927,8 @@ public class GetChildrenCannedQueryTest extends TestCase
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(mimetypeService.guessMimetype(fileName));
|
||||
writer.putContent("my text content");
|
||||
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
private void loadContent(NodeRef parentNodeRef, String inFileName, String title, String description, boolean readAllowed, Set<NodeRef> results) throws IOException
|
||||
|
Reference in New Issue
Block a user