From 3ff6c6620302e602f6c32750d456dac5cd44467c Mon Sep 17 00:00:00 2001 From: Alexandru Epure Date: Tue, 9 Aug 2016 14:17:31 +0000 Subject: [PATCH] Merged 5.2.N (5.2.1) to HEAD (5.2) 129199 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 129059 adavis: REPO-243 People Live Search - Use id (in fields and orderBy) rather than userName as it is an id that is returned in the Person entity - Added tests to test id can be used in fields and orderBy - Added 'wildcard' tests created by Alexandru-Eusebiu Epure git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129373 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/rest/api/Queries.java | 2 +- .../alfresco/rest/api/impl/QueriesImpl.java | 20 ++-- .../rest/api/tests/QueriesPeopleApiTest.java | 103 ++++++++++++++++-- 3 files changed, 104 insertions(+), 21 deletions(-) diff --git a/source/java/org/alfresco/rest/api/Queries.java b/source/java/org/alfresco/rest/api/Queries.java index d7459a25b3..6319bd99c1 100644 --- a/source/java/org/alfresco/rest/api/Queries.java +++ b/source/java/org/alfresco/rest/api/Queries.java @@ -57,7 +57,7 @@ public interface Queries static int MIN_TERM_LENGTH_NODES = 3; // People query - static String PARAM_USERNAME = ContentModel.PROP_USERNAME.getLocalName(); + static String PARAM_PERSON_ID = "id"; static String PARAM_FIRSTNAME = ContentModel.PROP_FIRSTNAME.getLocalName(); static String PARAM_LASTNAME = ContentModel.PROP_LASTNAME.getLocalName(); static int MIN_TERM_LENGTH_PEOPLE = 2; diff --git a/source/java/org/alfresco/rest/api/impl/QueriesImpl.java b/source/java/org/alfresco/rest/api/impl/QueriesImpl.java index bdb451b875..2a95def539 100644 --- a/source/java/org/alfresco/rest/api/impl/QueriesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/QueriesImpl.java @@ -94,7 +94,7 @@ public class QueriesImpl implements Queries, InitializingBean PARAM_MODIFIEDAT, ContentModel.PROP_MODIFIED); private final static Map PEOPLE_SORT_PARAMS_TO_QNAMES = sortParamsToQNames( - ContentModel.PROP_USERNAME, + PARAM_PERSON_ID, ContentModel.PROP_USERNAME, ContentModel.PROP_FIRSTNAME, ContentModel.PROP_LASTNAME); @@ -447,6 +447,15 @@ public class QueriesImpl implements Queries, InitializingBean T t = convert(nodeRef, includeParam); collection.add(t); } + + if (sort == POST_QUERY_SORT) + { + return listPage(collection, paging); + } + else + { + return CollectionWithPagingInfo.asPaged(paging, collection, queryResults.hasMore(), new Long(queryResults.getNumberFound()).intValue()); + } } finally { @@ -455,15 +464,6 @@ public class QueriesImpl implements Queries, InitializingBean queryResults.close(); } } - - if (sort == POST_QUERY_SORT) - { - return listPage(collection, paging); - } - else - { - return CollectionWithPagingInfo.asPaged(paging, collection, queryResults.hasMore(), new Long(queryResults.getNumberFound()).intValue()); - } } /** diff --git a/source/test-java/org/alfresco/rest/api/tests/QueriesPeopleApiTest.java b/source/test-java/org/alfresco/rest/api/tests/QueriesPeopleApiTest.java index 7792668fa1..6ca44ea58e 100644 --- a/source/test-java/org/alfresco/rest/api/tests/QueriesPeopleApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/QueriesPeopleApiTest.java @@ -27,7 +27,10 @@ package org.alfresco.rest.api.tests; import static org.alfresco.rest.api.Queries.PARAM_FIRSTNAME; import static org.alfresco.rest.api.Queries.PARAM_LASTNAME; +import static org.alfresco.rest.api.Queries.PARAM_PERSON_ID; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; @@ -67,7 +70,7 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest // deleting users is hard from from static methods. For the moment do it // in the first and last tests, but we have to get the TEST count right! // If we don't, a test fails or the users get left behind (not too bad). - private static int TEST_COUNT = 13; + private static int TEST_COUNT = 20; private static int testCounter = 0; // Test usernames @@ -246,20 +249,23 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest response = getAll(URL_QUERIES_LSP, paging, params, expectedStatus); - if (expectedPeople != null && expectedStatus == 200) + if (expectedStatus == 200) { people = Person.parsePeople(response.getJsonResponse()).getList(); - StringJoiner actual = new StringJoiner("\n"); - StringJoiner expected = new StringJoiner("\n"); - for (int i=0; i