mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-22 15:12:38 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
127588 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)
127088 jvonka: FileFolderService / GetChildrenCannedQuery - optional support for filtering by isPrimary child assoc (true/false)
- eg. as required by new V1 REST API
- RA-1053
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127680 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1073,6 +1073,9 @@
|
|||||||
</if>
|
</if>
|
||||||
where
|
where
|
||||||
assoc.parent_node_id = #{parentNodeId}
|
assoc.parent_node_id = #{parentNodeId}
|
||||||
|
<if test="isPrimary != null">
|
||||||
|
and assoc.is_primary = #{isPrimary}
|
||||||
|
</if>
|
||||||
<if test="childNodeTypeQNameIds != null">
|
<if test="childNodeTypeQNameIds != null">
|
||||||
and childNode.type_qname_id in
|
and childNode.type_qname_id in
|
||||||
<foreach item="item" index="index" collection="childNodeTypeQNameIds" open="(" separator="," close=")">
|
<foreach item="item" index="index" collection="childNodeTypeQNameIds" open="(" separator="," close=")">
|
||||||
@@ -1093,7 +1096,7 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- GetChildren - with no explicit sorting (or prop filtering) - note: still filtered by child type -->
|
<!-- GetChildren - with no explicit sorting (or prop filtering) - note: still filtered by child type (and optionally primary or secondary) -->
|
||||||
<select id="select_GetChildrenCannedQueryWithoutProps" parameterType="FilterSortNode" resultMap="result_NodeRef">
|
<select id="select_GetChildrenCannedQueryWithoutProps" parameterType="FilterSortNode" resultMap="result_NodeRef">
|
||||||
select
|
select
|
||||||
childNode.id as id,
|
childNode.id as id,
|
||||||
@@ -1110,6 +1113,9 @@
|
|||||||
</if>
|
</if>
|
||||||
where
|
where
|
||||||
assoc.parent_node_id = #{parentNodeId}
|
assoc.parent_node_id = #{parentNodeId}
|
||||||
|
<if test="isPrimary != null">
|
||||||
|
and assoc.is_primary = #{isPrimary}
|
||||||
|
</if>
|
||||||
<if test="childNodeTypeQNameIds != null">
|
<if test="childNodeTypeQNameIds != null">
|
||||||
and childNode.type_qname_id in
|
and childNode.type_qname_id in
|
||||||
<foreach item="item" index="index" collection="childNodeTypeQNameIds" open="(" separator="," close=")">
|
<foreach item="item" index="index" collection="childNodeTypeQNameIds" open="(" separator="," close=")">
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.alfresco.repo.copy.AbstractBaseCopyService;
|
|||||||
import org.alfresco.repo.model.filefolder.HiddenAspect.Visibility;
|
import org.alfresco.repo.model.filefolder.HiddenAspect.Visibility;
|
||||||
import org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceExtension;
|
import org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceExtension;
|
||||||
import org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceTrait;
|
import org.alfresco.repo.model.filefolder.traitextender.FileFolderServiceTrait;
|
||||||
|
import org.alfresco.repo.node.getchildren.FilterProp;
|
||||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||||
@@ -488,6 +489,13 @@ public class FileFolderServiceImpl extends AbstractBaseCopyService implements Fi
|
|||||||
return getPagingResults(pagingRequest, results);
|
return getPagingResults(pagingRequest, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, List<FilterProp> filterProps, PagingRequest pagingRequest)
|
||||||
|
{
|
||||||
|
CannedQueryResults<NodeRef> results = listImpl(rootNodeRef, null, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
|
||||||
|
return getPagingResults(pagingRequest, results);
|
||||||
|
}
|
||||||
|
|
||||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, boolean files, boolean folders)
|
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, boolean files, boolean folders)
|
||||||
{
|
{
|
||||||
Set<QName> searchTypeQNames = buildSearchTypesAndIgnoreAspects(files, folders, null).getFirst();
|
Set<QName> searchTypeQNames = buildSearchTypesAndIgnoreAspects(files, folders, null).getFirst();
|
||||||
@@ -512,13 +520,19 @@ public class FileFolderServiceImpl extends AbstractBaseCopyService implements Fi
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||||
|
{
|
||||||
|
return listImpl(contextNodeRef, pattern, searchTypeQNames, ignoreAspectQNames, sortProps, null, pagingRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames,
|
||||||
|
List<Pair<QName, Boolean>> sortProps, List<FilterProp> filterProps, PagingRequest pagingRequest)
|
||||||
{
|
{
|
||||||
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null);
|
||||||
|
|
||||||
// get canned query
|
// get canned query
|
||||||
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_FILEFOLDER_LIST);
|
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_FILEFOLDER_LIST);
|
||||||
|
|
||||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, pattern, Collections.singleton(ContentModel.ASSOC_CONTAINS), searchTypeQNames, ignoreAspectQNames, null, sortProps, pagingRequest);
|
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, pattern, Collections.singleton(ContentModel.ASSOC_CONTAINS), searchTypeQNames, ignoreAspectQNames, filterProps, sortProps, pagingRequest);
|
||||||
|
|
||||||
// execute canned query
|
// execute canned query
|
||||||
CannedQueryResults<NodeRef> results = cq.execute();
|
CannedQueryResults<NodeRef> results = cq.execute();
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ public class FilterSortNodeEntity
|
|||||||
private boolean auditableProps;
|
private boolean auditableProps;
|
||||||
private boolean nodeType;
|
private boolean nodeType;
|
||||||
|
|
||||||
|
private Boolean isPrimary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
@@ -246,4 +248,14 @@ public class FilterSortNodeEntity
|
|||||||
{
|
{
|
||||||
this.nodeType = nodeType;
|
this.nodeType = nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isPrimary()
|
||||||
|
{
|
||||||
|
return isPrimary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsPrimary(Boolean isPrimary)
|
||||||
|
{
|
||||||
|
this.isPrimary = isPrimary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +98,8 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeR
|
|||||||
public static final QName SORT_QNAME_NODE_TYPE = QName.createQName("", "TYPE");
|
public static final QName SORT_QNAME_NODE_TYPE = QName.createQName("", "TYPE");
|
||||||
public static final QName SORT_QNAME_NODE_IS_FOLDER = QName.createQName("", "IS_FOLDER"); // ALF-13968
|
public static final QName SORT_QNAME_NODE_IS_FOLDER = QName.createQName("", "IS_FOLDER"); // ALF-13968
|
||||||
|
|
||||||
|
public static final QName FILTER_QNAME_NODE_IS_PRIMARY = QName.createQName("", "IS_PRIMARY");
|
||||||
|
|
||||||
|
|
||||||
private NodeDAO nodeDAO;
|
private NodeDAO nodeDAO;
|
||||||
private QNameDAO qnameDAO;
|
private QNameDAO qnameDAO;
|
||||||
@@ -182,7 +184,10 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeR
|
|||||||
// Get filter details
|
// Get filter details
|
||||||
Set<QName> childNodeTypeQNames = paramBean.getChildTypeQNames();
|
Set<QName> childNodeTypeQNames = paramBean.getChildTypeQNames();
|
||||||
Set<QName> assocTypeQNames = paramBean.getAssocTypeQNames();
|
Set<QName> assocTypeQNames = paramBean.getAssocTypeQNames();
|
||||||
final List<FilterProp> filterProps = paramBean.getFilterProps();
|
|
||||||
|
final List<FilterProp> filterProps = new ArrayList<>(paramBean.getFilterProps().size());
|
||||||
|
filterProps.addAll(paramBean.getFilterProps()); // clone (to allow special handling for isPrimary)
|
||||||
|
|
||||||
String pattern = paramBean.getPattern();
|
String pattern = paramBean.getPattern();
|
||||||
|
|
||||||
// Get sort details
|
// Get sort details
|
||||||
@@ -190,6 +195,28 @@ public class GetChildrenCannedQuery extends AbstractCannedQueryPermissions<NodeR
|
|||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
final List<Pair<QName, SortOrder>> sortPairs = (List)sortDetails.getSortPairs();
|
final List<Pair<QName, SortOrder>> sortPairs = (List)sortDetails.getSortPairs();
|
||||||
|
|
||||||
|
if (filterProps.size() > 0)
|
||||||
|
{
|
||||||
|
// special handling of isPrimary filter (not counted as a filter/sort "property")
|
||||||
|
Boolean isPrimary = null;
|
||||||
|
int idx = 0;
|
||||||
|
for (FilterProp filter : filterProps)
|
||||||
|
{
|
||||||
|
if ((filter instanceof FilterPropBoolean) &&
|
||||||
|
((FilterPropBoolean)filter).getPropName().equals(FILTER_QNAME_NODE_IS_PRIMARY))
|
||||||
|
{
|
||||||
|
isPrimary = ((FilterPropBoolean)filter).getPropVal();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
if (isPrimary != null)
|
||||||
|
{
|
||||||
|
params.setIsPrimary(isPrimary);
|
||||||
|
filterProps.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set sort / filter params
|
// Set sort / filter params
|
||||||
// Note - need to keep the sort properties in their requested order
|
// Note - need to keep the sort properties in their requested order
|
||||||
List<QName> sortFilterProps = new ArrayList<QName>(filterProps.size() + sortPairs.size());
|
List<QName> sortFilterProps = new ArrayList<QName>(filterProps.size() + sortPairs.size());
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.util.Set;
|
|||||||
import org.alfresco.api.AlfrescoPublicApi;
|
import org.alfresco.api.AlfrescoPublicApi;
|
||||||
import org.alfresco.query.PagingRequest;
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.query.PagingResults;
|
import org.alfresco.query.PagingResults;
|
||||||
|
import org.alfresco.repo.node.getchildren.FilterProp;
|
||||||
import org.alfresco.service.Auditable;
|
import org.alfresco.service.Auditable;
|
||||||
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;
|
||||||
@@ -449,6 +450,19 @@ public interface FileFolderService
|
|||||||
@Auditable(parameters = {"rootNodeRef"})
|
@Auditable(parameters = {"rootNodeRef"})
|
||||||
public PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
public PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists page of immediate child objects of the given context node
|
||||||
|
* with specification of which types to list and optional filtering (exclusion of certain child file/folder subtypes) and sorting
|
||||||
|
* @param rootNodeRef NodeRef
|
||||||
|
* @param searchTypeQNames QNames of types to list
|
||||||
|
* @param ignoreAspectQNames Set<QName>
|
||||||
|
* @param sortProps List<Pair<QName, Boolean>>
|
||||||
|
* @param pagingRequest PagingRequest
|
||||||
|
* @return list of node refs, never null
|
||||||
|
*/
|
||||||
|
@Auditable(parameters = {"rootNodeRef"})
|
||||||
|
public PagingResults<FileInfo> list(NodeRef rootNodeRef, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, List<FilterProp> filterProps, PagingRequest pagingRequest);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to transform a list of {@link NodeRef} to a list of {@link FileInfo}
|
* Helper method to transform a list of {@link NodeRef} to a list of {@link FileInfo}
|
||||||
|
|||||||
@@ -457,6 +457,67 @@ public class GetChildrenCannedQueryTest extends TestCase
|
|||||||
assertEquals(0, results.getPage().size());
|
assertEquals(0, results.getPage().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPrimaryVsSecondary() throws Exception
|
||||||
|
{
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
|
||||||
|
NodeRef userHomeRef = repositoryHelper.getCompanyHome();
|
||||||
|
|
||||||
|
NodeRef parentNodeRef1 = createFolder(userHomeRef, "GetChildrenCannedQueryTest-PrimaryVsSecondary-"+TEST_RUN_ID, ContentModel.TYPE_FOLDER);
|
||||||
|
|
||||||
|
PagingResults<NodeRef> results = list(parentNodeRef1, -1, -1, 0, null, null, null);
|
||||||
|
assertEquals(0, results.getPage().size());
|
||||||
|
|
||||||
|
List<FilterProp> filterPropsPrimary = new ArrayList<>(1);
|
||||||
|
filterPropsPrimary.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, true));
|
||||||
|
|
||||||
|
List<FilterProp> filterPropsSecondary = new ArrayList<>(1);
|
||||||
|
filterPropsSecondary.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, false));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsPrimary, null);
|
||||||
|
assertEquals(0, results.getPage().size());
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsSecondary, null);
|
||||||
|
assertEquals(0, results.getPage().size());
|
||||||
|
|
||||||
|
NodeRef folder1Ref = createFolder(parentNodeRef1, FOLDER_1, ContentModel.TYPE_FOLDER);
|
||||||
|
NodeRef folder2Ref = createFolder(parentNodeRef1, FOLDER_2, ContentModel.TYPE_FOLDER);
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, null, null);
|
||||||
|
assertEquals(2, results.getPage().size());
|
||||||
|
assertTrue(results.getPage().contains(folder1Ref));
|
||||||
|
assertTrue(results.getPage().contains(folder2Ref));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsPrimary, null);
|
||||||
|
assertEquals(2, results.getPage().size());
|
||||||
|
assertTrue(results.getPage().contains(folder1Ref));
|
||||||
|
assertTrue(results.getPage().contains(folder2Ref));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsSecondary, null);
|
||||||
|
assertEquals(0, results.getPage().size());
|
||||||
|
|
||||||
|
NodeRef parentNodeRef2 = getOrCreateParentTestFolder("GetChildrenCannedQueryTest-2-"+TEST_RUN_ID);
|
||||||
|
|
||||||
|
NodeRef folder3Ref = createFolder(parentNodeRef2, FOLDER_3, ContentModel.TYPE_FOLDER);
|
||||||
|
|
||||||
|
nodeService.addChild(parentNodeRef1, folder3Ref, ContentModel.ASSOC_CONTAINS, QName.createQName("cm:2nd"));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, null, null);
|
||||||
|
assertEquals(3, results.getPage().size());
|
||||||
|
assertTrue(results.getPage().contains(folder1Ref));
|
||||||
|
assertTrue(results.getPage().contains(folder2Ref));
|
||||||
|
assertTrue(results.getPage().contains(folder3Ref));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsPrimary, null);
|
||||||
|
assertEquals(2, results.getPage().size());
|
||||||
|
assertTrue(results.getPage().contains(folder1Ref));
|
||||||
|
assertTrue(results.getPage().contains(folder2Ref));
|
||||||
|
|
||||||
|
results = list(parentNodeRef1, -1, -1, 0, null, filterPropsSecondary, null);
|
||||||
|
assertEquals(1, results.getPage().size());
|
||||||
|
assertTrue(results.getPage().contains(folder3Ref));
|
||||||
|
}
|
||||||
|
|
||||||
public void testPropertyStringFiltering() throws Exception
|
public void testPropertyStringFiltering() throws Exception
|
||||||
{
|
{
|
||||||
NodeRef parentNodeRef = getOrCreateParentTestFolder("GetChildrenCannedQueryTest-"+TEST_RUN_ID);
|
NodeRef parentNodeRef = getOrCreateParentTestFolder("GetChildrenCannedQueryTest-"+TEST_RUN_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user