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:
@@ -944,6 +944,10 @@
|
||||
<if test="prop1qnameId != null and prop2qnameId != null and prop3qnameId != null">
|
||||
left join alf_node_properties prop3 on (prop3.node_id = childNode.id and prop3.qname_id = #{prop3qnameId})
|
||||
</if>
|
||||
<if test="pattern != null">
|
||||
join alf_node_properties prop4 on (prop4.node_id = childNode.id)
|
||||
join alf_qname qname on (prop4.qname_id = qname.id and qname.id = #{namePropertyQNameId})
|
||||
</if>
|
||||
where
|
||||
assoc.parent_node_id = #{parentNodeId}
|
||||
<if test="childNodeTypeQNameIds != null">
|
||||
@@ -952,6 +956,9 @@
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="pattern != null">
|
||||
and prop4.string_value like #{pattern}
|
||||
</if>
|
||||
<if test="prop1qnameId == null and auditableProps == false">
|
||||
<include refid="alfresco.node.select_ChildAssoc_OrderBy"/>
|
||||
</if>
|
||||
@@ -968,6 +975,10 @@
|
||||
alf_child_assoc assoc
|
||||
join alf_node childNode on (childNode.id = assoc.child_node_id)
|
||||
join alf_store childStore on (childStore.id = childNode.store_id)
|
||||
<if test="pattern != null">
|
||||
join alf_node_properties prop4 on (prop4.node_id = childNode.id)
|
||||
join alf_qname qname on (prop4.qname_id = qname.id and qname.id = #{namePropertyQNameId})
|
||||
</if>
|
||||
where
|
||||
assoc.parent_node_id = #{parentNodeId}
|
||||
<if test="childNodeTypeQNameIds != null">
|
||||
@@ -976,6 +987,9 @@
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="pattern != null">
|
||||
and prop4.string_value like #{pattern}
|
||||
</if>
|
||||
<include refid="alfresco.node.select_ChildAssoc_OrderBy"/>
|
||||
</select>
|
||||
|
||||
|
@@ -259,7 +259,7 @@ public class CalendarServiceImpl implements CalendarService
|
||||
// Run the canned query
|
||||
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
|
||||
container, types, null, sort, paging);
|
||||
container, null, types, null, sort, paging);
|
||||
|
||||
// Execute the canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
|
@@ -641,7 +641,7 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol
|
||||
PagingRequest pageRequest = new PagingRequest(skipOffset, maxItems, queryExecutionId);
|
||||
pageRequest.setRequestTotalCountMax(requestTotalCountMax);
|
||||
|
||||
PagingResults<FileInfo> pageOfNodeInfos = this.fileFolderService.list(this.nodeRef, files, folders, ignoreTypeQNames, sortProps, pageRequest);
|
||||
PagingResults<FileInfo> pageOfNodeInfos = this.fileFolderService.list(this.nodeRef, files, folders, null, ignoreTypeQNames, sortProps, pageRequest);
|
||||
|
||||
List<FileInfo> nodeInfos = pageOfNodeInfos.getPage();
|
||||
|
||||
|
@@ -43,6 +43,7 @@ import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
|
||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||
import org.alfresco.repo.security.permissions.PermissionCheckedCollection.PermissionCheckedCollectionMixin;
|
||||
import org.alfresco.repo.security.permissions.PermissionCheckedValue.PermissionCheckedValueMixin;
|
||||
import org.alfresco.service.Auditable;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
@@ -348,19 +349,8 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
return results;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.model.FileFolderService#list(org.alfresco.service.cmr.repository.NodeRef, boolean, boolean, java.util.Set, org.alfresco.service.cmr.model.PagingSortRequest)
|
||||
*/
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, Set<QName> ignoreQNameTypes, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
private PagingResults<FileInfo> getPagingResults(PagingRequest pagingRequest, final CannedQueryResults<NodeRef> results)
|
||||
{
|
||||
ParameterCheck.mandatory("contextNodeRef", contextNodeRef);
|
||||
ParameterCheck.mandatory("pagingRequest", pagingRequest);
|
||||
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, ignoreQNameTypes);
|
||||
|
||||
// execute query
|
||||
final CannedQueryResults<NodeRef> results = listImpl(contextNodeRef, searchTypeQNames, sortProps, pagingRequest);
|
||||
|
||||
List<NodeRef> nodeRefs = null;
|
||||
if (results.getPageCount() > 0)
|
||||
{
|
||||
@@ -414,6 +404,42 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
};
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.model.FileFolderService#list(org.alfresco.service.cmr.repository.NodeRef, boolean, boolean, java.util.Set, org.alfresco.service.cmr.model.PagingSortRequest)
|
||||
*/
|
||||
@Auditable(parameters = {"contextNodeRef", "files", "folders", "ignoreTypeQNames", "sortProps", "pagingRequest"})
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef,
|
||||
boolean files,
|
||||
boolean folders,
|
||||
Set<QName> ignoreTypeQNames,
|
||||
List<Pair<QName, Boolean>> sortProps,
|
||||
PagingRequest pagingRequest)
|
||||
{
|
||||
ParameterCheck.mandatory("contextNodeRef", contextNodeRef);
|
||||
ParameterCheck.mandatory("pagingRequest", pagingRequest);
|
||||
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, ignoreTypeQNames);
|
||||
|
||||
// execute query
|
||||
final CannedQueryResults<NodeRef> results = listImpl(contextNodeRef, null, searchTypeQNames, sortProps, pagingRequest);
|
||||
return getPagingResults(pagingRequest, results);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.model.FileFolderService#list(org.alfresco.service.cmr.repository.NodeRef, boolean, boolean, String, java.util.Set, org.alfresco.service.cmr.model.PagingSortRequest)
|
||||
*/
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef, boolean files, boolean folders, String pattern, Set<QName> ignoreQNameTypes, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
{
|
||||
ParameterCheck.mandatory("contextNodeRef", contextNodeRef);
|
||||
ParameterCheck.mandatory("pagingRequest", pagingRequest);
|
||||
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, ignoreQNameTypes);
|
||||
|
||||
// execute query
|
||||
final CannedQueryResults<NodeRef> results = listImpl(contextNodeRef, pattern, searchTypeQNames, sortProps, pagingRequest);
|
||||
return getPagingResults(pagingRequest, results);
|
||||
}
|
||||
|
||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, boolean files, boolean folders)
|
||||
{
|
||||
Set<QName> searchTypeQNames = buildTypes(files, folders, null);
|
||||
@@ -422,18 +448,18 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
|
||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, Set<QName> searchTypeQNames)
|
||||
{
|
||||
return listImpl(contextNodeRef, searchTypeQNames, null, new PagingRequest(defaultListMaxResults, null));
|
||||
return listImpl(contextNodeRef, null, searchTypeQNames, null, new PagingRequest(defaultListMaxResults, null));
|
||||
}
|
||||
|
||||
// note: similar to getChildAssocs(contextNodeRef, searchTypeQNames) but enables paging features, including max items, sorting etc (with permissions per-applied)
|
||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, Set<QName> searchTypeQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, Set<QName> searchTypeQNames, 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, searchTypeQNames, null, sortProps, pagingRequest);
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, pattern, searchTypeQNames, null, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
@@ -453,6 +479,33 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
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)
|
||||
{
|
||||
// execute the query
|
||||
|
@@ -218,7 +218,7 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
// sanity checks only (see also GetChildrenCannedQueryTest)
|
||||
|
||||
PagingRequest pagingRequest = new PagingRequest(100, null);
|
||||
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, null, null, pagingRequest);
|
||||
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, null, null, null, pagingRequest);
|
||||
|
||||
assertNotNull(pagingResults);
|
||||
assertFalse(pagingResults.hasMoreItems());
|
||||
@@ -235,7 +235,7 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
|
||||
// empty list if skip count greater than number of results (ALF-7884)
|
||||
pagingRequest = new PagingRequest(1000, 3, null);
|
||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, null, null, pagingRequest);
|
||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, null, null, null, pagingRequest);
|
||||
|
||||
assertNotNull(pagingResults);
|
||||
assertFalse(pagingResults.hasMoreItems());
|
||||
@@ -899,9 +899,17 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
*/
|
||||
public void testGetType() throws Exception
|
||||
{
|
||||
I18NUtil.setContentLocale(Locale.CANADA);
|
||||
FileFolderServiceType type = fileFolderService.getType(ContentModel.TYPE_FOLDER);
|
||||
assertEquals("Type incorrect for folder", FileFolderServiceType.FOLDER, type);
|
||||
Locale savedLocale = I18NUtil.getContentLocaleOrNull();
|
||||
try
|
||||
{
|
||||
I18NUtil.setContentLocale(Locale.CANADA);
|
||||
FileFolderServiceType type = fileFolderService.getType(ContentModel.TYPE_FOLDER);
|
||||
assertEquals("Type incorrect for folder", FileFolderServiceType.FOLDER, type);
|
||||
}
|
||||
finally
|
||||
{
|
||||
I18NUtil.setContentLocale(savedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
public void testETHREEOH_3088_MoveIntoSelf() throws Exception
|
||||
@@ -1130,4 +1138,55 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
modifiedTooHigh,
|
||||
nodeService.getProperty(workingRootNodeRef, ContentModel.PROP_MODIFIED));
|
||||
}
|
||||
|
||||
public void testPatterns()
|
||||
{
|
||||
// sanity checks only (see also GetChildrenCannedQueryTest)
|
||||
|
||||
I18NUtil.setContentLocale(Locale.CANADA);
|
||||
|
||||
// test 1
|
||||
PagingRequest pagingRequest = new PagingRequest(100, null);
|
||||
PagingResults<FileInfo> pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0%", null, null, pagingRequest);
|
||||
|
||||
assertNotNull(pagingResults);
|
||||
assertFalse(pagingResults.hasMoreItems());
|
||||
assertNull(pagingResults.getTotalResultCount());
|
||||
|
||||
List<FileInfo> files = pagingResults.getPage();
|
||||
|
||||
// check
|
||||
String[] expectedNames = new String[]
|
||||
{ NAME_L0_FILE_A, NAME_L0_FILE_B, NAME_L0_FOLDER_A, NAME_L0_FOLDER_B, NAME_L0_FOLDER_C };
|
||||
checkFileList(files, 2, 3, expectedNames);
|
||||
|
||||
// test 2
|
||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L1%", null, null, pagingRequest);
|
||||
|
||||
assertNotNull(pagingResults);
|
||||
assertFalse(pagingResults.hasMoreItems());
|
||||
assertNull(pagingResults.getTotalResultCount());
|
||||
|
||||
files = pagingResults.getPage();
|
||||
|
||||
// check
|
||||
expectedNames = new String[]
|
||||
{ };
|
||||
checkFileList(files, 0, 0, expectedNames);
|
||||
|
||||
// test 3
|
||||
pagingResults = fileFolderService.list(workingRootNodeRef, true, true, "L0%File%", null, null, pagingRequest);
|
||||
|
||||
assertNotNull(pagingResults);
|
||||
assertFalse(pagingResults.hasMoreItems());
|
||||
assertNull(pagingResults.getTotalResultCount());
|
||||
|
||||
files = pagingResults.getPage();
|
||||
|
||||
// check
|
||||
expectedNames = new String[]
|
||||
{ NAME_L0_FILE_A, NAME_L0_FILE_B };
|
||||
checkFileList(files, 2, 0, expectedNames);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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,7 +131,7 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -1214,7 +1214,7 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
}
|
||||
}
|
||||
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, childTypeQNames, filterProps, sortProps, pagingRequest);
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, null, childTypeQNames, filterProps, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
final CannedQueryResults<NodeRef> results = cq.execute();
|
||||
|
@@ -892,7 +892,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
|
||||
final String cQBeanName = "siteGetChildrenCannedQueryFactory";
|
||||
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(cQBeanName);
|
||||
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(getSiteRoot(), searchTypeQNames,
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(getSiteRoot(), null, searchTypeQNames,
|
||||
filterProps, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
|
@@ -69,6 +69,23 @@ public interface FileFolderService
|
||||
List<Pair<QName, Boolean>> sortProps,
|
||||
PagingRequest pagingRequest);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Pattern uses '%' as a wildcard
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Auditable(parameters = {"contextNodeRef", "files", "folders", "ignoreTypeQNames", "sortProps", "pagingRequest"})
|
||||
public PagingResults<FileInfo> list(NodeRef contextNodeRef,
|
||||
boolean files,
|
||||
boolean folders,
|
||||
String pattern,
|
||||
Set<QName> ignoreTypeQNames,
|
||||
List<Pair<QName, Boolean>> sortProps,
|
||||
PagingRequest pagingRequest);
|
||||
|
||||
/**
|
||||
* Lists all immediate child files of the given context node
|
||||
*
|
||||
|
Reference in New Issue
Block a user