Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

124819 jvonka: RA-896 - List Node Children filtering - additional fixes & tests, when filtering by isFile &/or isFolder


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126589 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:43:06 +00:00
parent 846f24ed47
commit 4fb66c3f2f
2 changed files with 87 additions and 45 deletions

View File

@@ -1128,8 +1128,6 @@ public class NodesImpl implements Nodes
filterNodeTypeQName = pair.getFirst();
filterIncludeSubTypes = pair.getSecond();
}
}
List<SortColumn> sortCols = parameters.getSorting();
@@ -1165,30 +1163,49 @@ public class NodesImpl implements Nodes
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final PagingResults<FileInfo> pagingResults;
if (((includeFiles == null) && (includeFolders == null)) ||
(filterNodeTypeQName != null) ||
(Boolean.FALSE.equals(includeFiles) && Boolean.FALSE.equals(includeFolders)))
{
// either no filtering or some filtering (but not just files or folders)
// notes (see also earlier validation checks):
// - node type filtering is mutually exclusive from isFile/isFolder, can optionally also include sub-types
// - isFile & isFolder cannot both be true
// - (isFile=false) means any other types/sub-types (other than files)
// - (isFolder=false) means any other types/sub-types (other than folders)
// - (isFile=false and isFolder=false) means any types/sub-types (other than files or folders)
if (filterNodeTypeQName == null)
{
if (Boolean.FALSE.equals(includeFiles) && Boolean.FALSE.equals(includeFolders))
{
includeFiles = false;
includeFolders = false;
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
if (includeFiles != null)
{
if ((! includeFiles) && (includeFolders == null))
{
// isFile=false
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
}
if (includeFolders != null)
{
if ((! includeFolders) && (includeFiles == null))
{
// isFolder=false
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
}
}
Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(filterNodeTypeQName, filterIncludeSubTypes, ignoreQNames, includeFiles, includeFolders);
Set<QName> searchTypeQNames = pair.getFirst();
Set<QName> ignoreAspectQNames = pair.getSecond();
pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
}
else
{
// files or folders only
includeFiles = (includeFiles != null ? includeFiles : false);
includeFolders = (includeFolders != null ? includeFolders : false);
pagingResults = fileFolderService.list(parentNodeRef, includeFiles, includeFolders, ignoreQNames, sortProps, pagingRequest);
}
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
@@ -1246,9 +1263,11 @@ public class NodesImpl implements Nodes
protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(QName nodeTypeQName, boolean includeSubTypes, Set<QName> ignoreQNameTypes, Boolean includeFiles, Boolean includeFolders)
{
Set<QName> searchTypeQNames = new HashSet<QName>(100);
Set<QName> searchTypeQNames = new HashSet<>(100);
Set<QName> ignoreAspectQNames = null;
if (nodeTypeQName != null)
{
// Build a list of (sub-)types
if (includeSubTypes)
{
@@ -1264,16 +1283,12 @@ public class NodesImpl implements Nodes
searchTypeQNames.removeAll(qnames);
}
searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER);
}
if (includeFiles != null)
{
if (includeFiles)
{
if (! dictionaryService.isSubClass(ContentModel.TYPE_CONTENT, nodeTypeQName))
{
throw new InvalidArgumentException("Cannot filter for isFile since not sub-type of: "+nodeTypeQName);
}
if (includeSubTypes)
{
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CONTENT, true);
@@ -1293,17 +1308,20 @@ public class NodesImpl implements Nodes
{
if (includeFolders)
{
if (! dictionaryService.isSubClass(ContentModel.TYPE_FOLDER, nodeTypeQName))
{
throw new InvalidArgumentException("Cannot filter for isFolder since not sub-type of: "+nodeTypeQName);
}
if (includeSubTypes)
{
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_FOLDER, true);
searchTypeQNames.addAll(qnames);
}
searchTypeQNames.add(ContentModel.TYPE_FOLDER);
// Remove 'system' folders
if (includeSubTypes)
{
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_SYSTEM_FOLDER, true);
searchTypeQNames.removeAll(qnames);
}
searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER);
}
else
{
@@ -1315,7 +1333,7 @@ public class NodesImpl implements Nodes
if (ignoreQNameTypes != null)
{
Set<QName> ignoreQNamesNotSearchTypes = new HashSet<QName>(ignoreQNameTypes);
Set<QName> ignoreQNamesNotSearchTypes = new HashSet<>(ignoreQNameTypes);
ignoreQNamesNotSearchTypes.removeAll(searchTypeQNames);
ignoreQNamesNotSearchTypes.remove(ContentModel.TYPE_SYSTEM_FOLDER);
@@ -1332,7 +1350,7 @@ public class NodesImpl implements Nodes
private Set<QName> getAspectsToIgnore(Set<QName> ignoreQNames)
{
Set<QName> ignoreQNameAspects = new HashSet<QName>(ignoreQNames.size());
Set<QName> ignoreQNameAspects = new HashSet<>(ignoreQNames.size());
for (QName qname : ignoreQNames)
{
if (dictionaryService.getAspect(qname) != null)

View File

@@ -1737,6 +1737,14 @@ public class NodeApiTest extends AbstractBaseApiTest
folderAndFileIds.addAll(folderIds);
folderAndFileIds.addAll(fileIds);
List<String> notFileIds = new ArrayList<>(folderCnt+objCnt);
notFileIds.addAll(folderIds);
notFileIds.addAll(objIds);
List<String> notFolderIds = new ArrayList<>(fileCnt+objCnt);
notFolderIds.addAll(fileIds);
notFolderIds.addAll(objIds);
Paging paging = getPaging(0, Integer.MAX_VALUE);
// no filtering
@@ -1814,6 +1822,22 @@ public class NodeApiTest extends AbstractBaseApiTest
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, objIds);
// filtering, via where clause - not files
params = new HashMap<>();
params.put("where", "(isFile=false)");
response = getAll(myChildrenUrl, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, notFileIds);
// filtering, via where clause - not folders
params = new HashMap<>();
params.put("where", "(isFolder=false)");
response = getAll(myChildrenUrl, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, notFolderIds);
// -ve - node cannot be both a file and a folder
params = new HashMap<>();
params.put("where", "(isFile=true AND isFolder=true)");