mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)
127094 jvonka: Node Associations - child assocs - isPrimary filter (for /parents and /children) - RA-1053 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127589 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -256,4 +256,6 @@ public interface Nodes
|
||||
|
||||
String PARAM_VERSION_MAJOR = "majorVersion"; // true if major, false if minor
|
||||
String PARAM_VERSION_COMMENT = "comment";
|
||||
|
||||
String PARAM_ISPRIMARY = "isPrimary";
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ import org.alfresco.repo.content.ContentLimitViolationException;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
|
||||
import org.alfresco.repo.node.getchildren.FilterProp;
|
||||
import org.alfresco.repo.node.getchildren.FilterPropBoolean;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -327,7 +329,7 @@ public class NodesImpl implements Nodes
|
||||
|
||||
// list children filtering (via where clause)
|
||||
private final static Set<String> LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES =
|
||||
new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_ISFILE, PARAM_NODETYPE}));
|
||||
new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_ISFILE, PARAM_NODETYPE, PARAM_ISPRIMARY}));
|
||||
|
||||
/*
|
||||
* Validates that node exists.
|
||||
@@ -1151,9 +1153,10 @@ public class NodesImpl implements Nodes
|
||||
|
||||
final List<String> includeParam = parameters.getInclude();
|
||||
|
||||
// filters
|
||||
Boolean includeFolders = null;
|
||||
Boolean includeFiles = null;
|
||||
|
||||
Boolean isPrimary = null;
|
||||
QName filterNodeTypeQName = null;
|
||||
|
||||
// note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
|
||||
@@ -1167,6 +1170,8 @@ public class NodesImpl implements Nodes
|
||||
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES, null);
|
||||
QueryHelper.walk(q, propertyWalker);
|
||||
|
||||
isPrimary = propertyWalker.getProperty(PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
|
||||
|
||||
Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
|
||||
Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
|
||||
|
||||
@@ -1227,6 +1232,13 @@ public class NodesImpl implements Nodes
|
||||
new Pair<>(ContentModel.PROP_NAME, true)));
|
||||
}
|
||||
|
||||
List<FilterProp> filterProps = null;
|
||||
if (isPrimary != null)
|
||||
{
|
||||
filterProps = new ArrayList<>(1);
|
||||
filterProps.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, isPrimary));
|
||||
}
|
||||
|
||||
Paging paging = parameters.getPaging();
|
||||
|
||||
PagingRequest pagingRequest = Util.getPagingRequest(paging);
|
||||
@@ -1272,7 +1284,7 @@ public class NodesImpl implements Nodes
|
||||
Set<QName> searchTypeQNames = pair.getFirst();
|
||||
Set<QName> ignoreAspectQNames = pair.getSecond();
|
||||
|
||||
pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
|
||||
pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
|
||||
|
||||
|
||||
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
||||
|
@@ -63,7 +63,7 @@ public class AbstractNodeRelation implements InitializingBean
|
||||
// excluded namespaces (assoc types)
|
||||
protected static final List<String> EXCLUDED_NS = Arrays.asList(NamespaceService.SYSTEM_MODEL_1_0_URI);
|
||||
|
||||
private final static Set<String> WHERE_PARAMS =
|
||||
private final static Set<String> WHERE_PARAMS_ASSOC_TYPE =
|
||||
new HashSet<>(Arrays.asList(new String[] {PARAM_ASSOC_TYPE}));
|
||||
|
||||
protected ServiceRegistry sr;
|
||||
@@ -131,7 +131,7 @@ public class AbstractNodeRelation implements InitializingBean
|
||||
Query q = parameters.getQuery();
|
||||
if (q != null)
|
||||
{
|
||||
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS, null);
|
||||
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_ASSOC_TYPE, null);
|
||||
QueryHelper.walk(q, propertyWalker);
|
||||
|
||||
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
||||
|
@@ -18,18 +18,26 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.nodes;
|
||||
|
||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.Query;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QNamePattern;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Node Parents
|
||||
@@ -39,6 +47,11 @@ import java.util.List;
|
||||
@RelationshipResource(name = "parents", entityResource = NodesEntityResource.class, title = "Node Parents")
|
||||
public class NodeParentsRelation extends AbstractNodeRelation implements RelationshipResourceAction.Read<Node>
|
||||
{
|
||||
public final static String PARAM_IS_PRIMARY = Nodes.PARAM_ISPRIMARY;
|
||||
|
||||
private final static Set<String> WHERE_PARAMS_PARENTS =
|
||||
new HashSet<>(Arrays.asList(new String[] {PARAM_ASSOC_TYPE, PARAM_IS_PRIMARY}));
|
||||
|
||||
/**
|
||||
* List child node's parent(s) based on (parent ->) child associations.
|
||||
* Returns primary parent & also secondary parents, if any.
|
||||
@@ -51,7 +64,24 @@ public class NodeParentsRelation extends AbstractNodeRelation implements Relatio
|
||||
{
|
||||
NodeRef childNodeRef = nodes.validateOrLookupNode(childNodeId, null);
|
||||
|
||||
QNamePattern assocTypeQNameParam = getAssocTypeFromWhereElseAll(parameters);
|
||||
QNamePattern assocTypeQNameParam = RegexQNamePattern.MATCH_ALL;
|
||||
|
||||
Boolean isPrimary = null;
|
||||
|
||||
Query q = parameters.getQuery();
|
||||
if (q != null)
|
||||
{
|
||||
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_PARENTS, null);
|
||||
QueryHelper.walk(q, propertyWalker);
|
||||
|
||||
isPrimary = propertyWalker.getProperty(PARAM_IS_PRIMARY, WhereClauseParser.EQUALS, Boolean.class);
|
||||
|
||||
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
||||
if (assocTypeQNameStr != null)
|
||||
{
|
||||
assocTypeQNameParam = getAssocType(assocTypeQNameStr);
|
||||
}
|
||||
}
|
||||
|
||||
List<ChildAssociationRef> childAssocRefs = null;
|
||||
if (assocTypeQNameParam.equals(RegexQNamePattern.MATCH_ALL))
|
||||
@@ -63,6 +93,6 @@ public class NodeParentsRelation extends AbstractNodeRelation implements Relatio
|
||||
childAssocRefs = nodeService.getParentAssocs(childNodeRef, assocTypeQNameParam, RegexQNamePattern.MATCH_ALL);
|
||||
}
|
||||
|
||||
return listNodeChildAssocs(childAssocRefs, parameters, null, false);
|
||||
return listNodeChildAssocs(childAssocRefs, parameters, isPrimary, false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user