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

121782 jvonka: FileFolder (Node) API - enable nodeType filtering (optionally without subTypes), eg.
   - where=(nodeType='my:specialtype')
   - where=(nodeType='cm:content' and subtypes=false)
   - TODO extra tests
   RA-741, RA-685, RA-634


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126417 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 10:50:48 +00:00
parent 3980848d1e
commit 7112f4f507

View File

@@ -235,6 +235,8 @@ public class NodesImpl implements Nodes
ContentModel.PROP_WORKING_COPY_OWNER); ContentModel.PROP_WORKING_COPY_OWNER);
private final static String PARAM_ISFOLDER = "isFolder"; private final static String PARAM_ISFOLDER = "isFolder";
private final static String PARAM_SUBTYPES = "subTypes";
private final static String PARAM_NAME = "name"; private final static String PARAM_NAME = "name";
private final static String PARAM_CREATEDAT = "createdAt"; private final static String PARAM_CREATEDAT = "createdAt";
private final static String PARAM_MODIFIEDAT = "modifiedAt"; private final static String PARAM_MODIFIEDAT = "modifiedAt";
@@ -263,7 +265,7 @@ public class NodesImpl implements Nodes
} }
private final static Set<String> LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES = private final static Set<String> LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES =
new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER})); new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_NODETYPE, PARAM_SUBTYPES}));
/* /*
* Note: assumes workspace://SpacesStore * Note: assumes workspace://SpacesStore
@@ -868,19 +870,35 @@ public class NodesImpl implements Nodes
boolean includeFolders = true; boolean includeFolders = true;
boolean includeFiles = true; boolean includeFiles = true;
QName filterNodeTypeQName = null;
boolean filterIncludeSubTypes = true;
Query q = parameters.getQuery(); Query q = parameters.getQuery();
if (q != null) if (q != null)
{ {
// TODO confirm list of filter props - what about custom props (+ across types/aspects) ? What about VF extension ? // filtering via "where" clause
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES, null); MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker); QueryHelper.walk(q, propertyWalker);
Boolean b = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class); Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
if (b != null) if (isFolder != null)
{ {
includeFiles = !b; includeFiles = !isFolder;
includeFolders = b; includeFolders = isFolder;
}
String nodeTypeStr = propertyWalker.getProperty(PARAM_NODETYPE, WhereClauseParser.EQUALS, String.class);
if ((nodeTypeStr != null) && (! nodeTypeStr.isEmpty()))
{
filterNodeTypeQName = createQName(nodeTypeStr);
}
// optionally used with nodeType filter (default is to include subTypes, if not specified as "subTypes=false")
Boolean subTypes = propertyWalker.getProperty(PARAM_SUBTYPES, WhereClauseParser.EQUALS, Boolean.class);
if (subTypes != null)
{
filterIncludeSubTypes = subTypes;
} }
} }
@@ -921,10 +939,14 @@ public class NodesImpl implements Nodes
PagingRequest pagingRequest = Util.getPagingRequest(paging); PagingRequest pagingRequest = Util.getPagingRequest(paging);
final PagingResults<FileInfo> pagingResults; final PagingResults<FileInfo> pagingResults;
if (includeFolders && includeFiles) if ((filterNodeTypeQName != null) || (includeFolders && includeFiles))
{ {
// note: this allows to include other types (eg. that derive from cm:cmobject) - not just folders & files if (filterNodeTypeQName == null)
Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(ignoreQNames); {
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(filterNodeTypeQName, filterIncludeSubTypes, ignoreQNames);
Set<QName> searchTypeQNames = pair.getFirst(); Set<QName> searchTypeQNames = pair.getFirst();
Set<QName> ignoreAspectQNames = pair.getSecond(); Set<QName> ignoreAspectQNames = pair.getSecond();
@@ -960,26 +982,32 @@ public class NodesImpl implements Nodes
return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst()); return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst());
} }
protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(Set<QName> ignoreQNameTypes) protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(QName filterNodeTypeQName, boolean filterIncludeSubTypes, Set<QName> ignoreQNameTypes)
{ {
Set<QName> searchTypeQNames = new HashSet<QName>(100); Set<QName> searchTypeQNames = new HashSet<QName>(100);
Set<QName> ignoreAspectQNames = null; Set<QName> ignoreAspectQNames = null;
// Build a list of cmobject types // Build a list of (sub-)types
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_CMOBJECT, true); if (filterIncludeSubTypes)
{
Collection<QName> qnames = dictionaryService.getSubTypes(filterNodeTypeQName, true);
searchTypeQNames.addAll(qnames); searchTypeQNames.addAll(qnames);
searchTypeQNames.add(ContentModel.TYPE_CMOBJECT); }
searchTypeQNames.add(filterNodeTypeQName);
// Remove 'system' folders // Remove 'system' folders
qnames = dictionaryService.getSubTypes(ContentModel.TYPE_SYSTEM_FOLDER, true); if (filterIncludeSubTypes)
{
Collection<QName> qnames = dictionaryService.getSubTypes(ContentModel.TYPE_SYSTEM_FOLDER, true);
searchTypeQNames.removeAll(qnames); searchTypeQNames.removeAll(qnames);
}
searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER); searchTypeQNames.remove(ContentModel.TYPE_SYSTEM_FOLDER);
if (ignoreQNameTypes != null) if (ignoreQNameTypes != null)
{ {
Set<QName> ignoreQNamesNotSearchTypes = new HashSet<QName>(ignoreQNameTypes); Set<QName> ignoreQNamesNotSearchTypes = new HashSet<QName>(ignoreQNameTypes);
ignoreQNamesNotSearchTypes.removeAll(searchTypeQNames); ignoreQNamesNotSearchTypes.removeAll(searchTypeQNames);
ignoreQNamesNotSearchTypes.remove(ContentModel.TYPE_SYSTEM_FOLDER); // note: not included in buildFolderTypes() ignoreQNamesNotSearchTypes.remove(ContentModel.TYPE_SYSTEM_FOLDER);
if (ignoreQNamesNotSearchTypes.size() > 0) if (ignoreQNamesNotSearchTypes.size() > 0)
{ {