mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
127589 jkaabimofrad: 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/BRANCHES/DEV/5.2.N/root@127681 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -263,4 +263,6 @@ public interface Nodes
|
|||||||
|
|
||||||
String PARAM_VERSION_MAJOR = "majorVersion"; // true if major, false if minor
|
String PARAM_VERSION_MAJOR = "majorVersion"; // true if major, false if minor
|
||||||
String PARAM_VERSION_COMMENT = "comment";
|
String PARAM_VERSION_COMMENT = "comment";
|
||||||
|
|
||||||
|
String PARAM_ISPRIMARY = "isPrimary";
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,8 @@ import org.alfresco.repo.content.ContentLimitViolationException;
|
|||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
|
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.node.getchildren.GetChildrenCannedQuery;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
@@ -334,7 +336,7 @@ public class NodesImpl implements Nodes
|
|||||||
|
|
||||||
// list children filtering (via where clause)
|
// list children filtering (via where clause)
|
||||||
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, PARAM_ISFILE, PARAM_NODETYPE}));
|
new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_ISFILE, PARAM_NODETYPE, PARAM_ISPRIMARY}));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validates that node exists.
|
* Validates that node exists.
|
||||||
@@ -1158,9 +1160,10 @@ public class NodesImpl implements Nodes
|
|||||||
|
|
||||||
final List<String> includeParam = parameters.getInclude();
|
final List<String> includeParam = parameters.getInclude();
|
||||||
|
|
||||||
|
// filters
|
||||||
Boolean includeFolders = null;
|
Boolean includeFolders = null;
|
||||||
Boolean includeFiles = null;
|
Boolean includeFiles = null;
|
||||||
|
Boolean isPrimary = null;
|
||||||
QName filterNodeTypeQName = null;
|
QName filterNodeTypeQName = null;
|
||||||
|
|
||||||
// note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
|
// note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
|
||||||
@@ -1174,6 +1177,8 @@ public class NodesImpl implements Nodes
|
|||||||
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);
|
||||||
|
|
||||||
|
isPrimary = propertyWalker.getProperty(PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
|
||||||
|
|
||||||
Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
|
Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
|
||||||
Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
|
Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
|
||||||
|
|
||||||
@@ -1234,6 +1239,13 @@ public class NodesImpl implements Nodes
|
|||||||
new Pair<>(ContentModel.PROP_NAME, true)));
|
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();
|
Paging paging = parameters.getPaging();
|
||||||
|
|
||||||
PagingRequest pagingRequest = Util.getPagingRequest(paging);
|
PagingRequest pagingRequest = Util.getPagingRequest(paging);
|
||||||
@@ -1279,7 +1291,7 @@ public class NodesImpl implements Nodes
|
|||||||
Set<QName> searchTypeQNames = pair.getFirst();
|
Set<QName> searchTypeQNames = pair.getFirst();
|
||||||
Set<QName> ignoreAspectQNames = pair.getSecond();
|
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);
|
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
||||||
|
@@ -63,7 +63,7 @@ public class AbstractNodeRelation implements InitializingBean
|
|||||||
// excluded namespaces (assoc types)
|
// excluded namespaces (assoc types)
|
||||||
protected static final List<String> EXCLUDED_NS = Arrays.asList(NamespaceService.SYSTEM_MODEL_1_0_URI);
|
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}));
|
new HashSet<>(Arrays.asList(new String[] {PARAM_ASSOC_TYPE}));
|
||||||
|
|
||||||
protected ServiceRegistry sr;
|
protected ServiceRegistry sr;
|
||||||
@@ -131,7 +131,7 @@ public class AbstractNodeRelation implements InitializingBean
|
|||||||
Query q = parameters.getQuery();
|
Query q = parameters.getQuery();
|
||||||
if (q != null)
|
if (q != null)
|
||||||
{
|
{
|
||||||
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS, null);
|
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(WHERE_PARAMS_ASSOC_TYPE, null);
|
||||||
QueryHelper.walk(q, propertyWalker);
|
QueryHelper.walk(q, propertyWalker);
|
||||||
|
|
||||||
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
|
||||||
|
@@ -18,18 +18,26 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api.nodes;
|
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.api.model.Node;
|
||||||
import org.alfresco.rest.framework.WebApiDescription;
|
import org.alfresco.rest.framework.WebApiDescription;
|
||||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
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.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QNamePattern;
|
import org.alfresco.service.namespace.QNamePattern;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node Parents
|
* Node Parents
|
||||||
@@ -39,6 +47,11 @@ import java.util.List;
|
|||||||
@RelationshipResource(name = "parents", entityResource = NodesEntityResource.class, title = "Node Parents")
|
@RelationshipResource(name = "parents", entityResource = NodesEntityResource.class, title = "Node Parents")
|
||||||
public class NodeParentsRelation extends AbstractNodeRelation implements RelationshipResourceAction.Read<Node>
|
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.
|
* List child node's parent(s) based on (parent ->) child associations.
|
||||||
* Returns primary parent & also secondary parents, if any.
|
* 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);
|
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;
|
List<ChildAssociationRef> childAssocRefs = null;
|
||||||
if (assocTypeQNameParam.equals(RegexQNamePattern.MATCH_ALL))
|
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);
|
childAssocRefs = nodeService.getParentAssocs(childNodeRef, assocTypeQNameParam, RegexQNamePattern.MATCH_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return listNodeChildAssocs(childAssocRefs, parameters, null, false);
|
return listNodeChildAssocs(childAssocRefs, parameters, isPrimary, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -526,7 +526,6 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
|||||||
|
|
||||||
response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200);
|
response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200);
|
||||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
assertEquals(2, nodes.size());
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Node node : nodes)
|
for (Node node : nodes)
|
||||||
{
|
{
|
||||||
@@ -546,7 +545,6 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
|||||||
|
|
||||||
response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200);
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200);
|
||||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
assertEquals(3, nodes.size());
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (Node node : nodes)
|
for (Node node : nodes)
|
||||||
{
|
{
|
||||||
@@ -573,7 +571,8 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
|||||||
}
|
}
|
||||||
assertEquals(3, i);
|
assertEquals(3, i);
|
||||||
|
|
||||||
// test basic list filter
|
// test list filter - assocType (/secondary-children & /parents)
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("where", "(assocType='"+ASSOC_TYPE_CM_CONTAINS+"')");
|
params.put("where", "(assocType='"+ASSOC_TYPE_CM_CONTAINS+"')");
|
||||||
|
|
||||||
@@ -585,7 +584,6 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
|||||||
|
|
||||||
response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200);
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200);
|
||||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
assertEquals(2, nodes.size());
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (Node node : nodes)
|
for (Node node : nodes)
|
||||||
{
|
{
|
||||||
@@ -624,10 +622,95 @@ public class NodeAssociationsApiTest extends AbstractBaseApiTest
|
|||||||
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
|
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
|
||||||
|
|
||||||
|
|
||||||
|
// test list filter - isPrimary (/children)
|
||||||
|
|
||||||
|
// note: see NodeApiTest for other filters related to /nodes/{parentId}/children filters
|
||||||
|
|
||||||
|
// note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names
|
||||||
|
response = getAll(getNodeChildrenUrl(f1Id), user1, paging, null, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(2, nodes.size());
|
||||||
|
List<String> nodeIds = Arrays.asList(new String[] { nodes.get(0).getId(), nodes.get(1).getId()} );
|
||||||
|
assertTrue(nodeIds.contains(o1Id));
|
||||||
|
assertTrue(nodeIds.contains(o2Id));
|
||||||
|
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(isPrimary=true)");
|
||||||
|
|
||||||
|
response = getAll(getNodeChildrenUrl(f1Id), user1, paging, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(1, nodes.size());
|
||||||
|
assertEquals(o1Id, nodes.get(0).getId());
|
||||||
|
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(isPrimary=false)");
|
||||||
|
|
||||||
|
// note: currently collapses same nodeIds (o2Id x 2) into one - makes sense in terms of File/Folder to avoid duplicate names
|
||||||
|
response = getAll(getNodeChildrenUrl(f1Id), user1, paging, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(1, nodes.size());
|
||||||
|
assertEquals(o2Id, nodes.get(0).getId());
|
||||||
|
|
||||||
|
|
||||||
|
// test list filter - isPrimary (/parents)
|
||||||
|
|
||||||
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, null, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(3, nodes.size());
|
||||||
|
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(isPrimary=true)");
|
||||||
|
|
||||||
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(1, nodes.size());
|
||||||
|
assertEquals(f2Id, nodes.get(0).getId());
|
||||||
|
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(isPrimary=false)");
|
||||||
|
|
||||||
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
i = 0;
|
||||||
|
for (Node node : nodes)
|
||||||
|
{
|
||||||
|
String nodeId = node.getId();
|
||||||
|
Association nodeAssoc = node.getAssociation();
|
||||||
|
if (nodeId.equals(f1Id))
|
||||||
|
{
|
||||||
|
if (nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_CONTAINS))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if ( nodeAssoc.getAssocType().equals(ASSOC_TYPE_CM_PREFERENCE_IMAGE))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
assertFalse(nodeAssoc.getIsPrimary());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(2, i);
|
||||||
|
|
||||||
|
// combined filter
|
||||||
|
params = new HashMap<>();
|
||||||
|
params.put("where", "(isPrimary=false and assocType='"+ASSOC_TYPE_CM_PREFERENCE_IMAGE+"')");
|
||||||
|
|
||||||
|
response = getAll(getNodeParentsUrl(o2Id), user1, paging, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(1, nodes.size());
|
||||||
|
assertEquals(f1Id, nodes.get(0).getId());
|
||||||
|
assertFalse(nodes.get(0).getAssociation().getIsPrimary());
|
||||||
|
assertEquals(ASSOC_TYPE_CM_PREFERENCE_IMAGE, nodes.get(0).getAssociation().getAssocType());
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
// remove one secondary child assoc
|
||||||
|
|
||||||
params = new HashMap<>(2);
|
params = new HashMap<>(2);
|
||||||
params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_CONTAINS);
|
params.put(PARAM_ASSOC_TYPE, ASSOC_TYPE_CM_CONTAINS);
|
||||||
|
|
||||||
// remove one secondary child assoc
|
|
||||||
delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, params, 204);
|
delete(getNodeSecondaryChildrenUrl(f1Id), user1, o2Id, params, 204);
|
||||||
|
|
||||||
response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200);
|
response = getAll(getNodeSecondaryChildrenUrl(f1Id), user1, paging, null, 200);
|
||||||
|
Reference in New Issue
Block a user