diff --git a/source/java/org/alfresco/rest/api/People.java b/source/java/org/alfresco/rest/api/People.java index bae375bfec..901a81ad9f 100644 --- a/source/java/org/alfresco/rest/api/People.java +++ b/source/java/org/alfresco/rest/api/People.java @@ -37,7 +37,7 @@ public interface People String PARAM_FIRST_NAME = "firstName"; String PARAM_LAST_NAME = "lastName"; - String PARAM_USER_NAME = "userName"; + String PARAM_ID = "id"; String validatePerson(String personId); String validatePerson(String personId, boolean validateIsCurrentUser); diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index 1d0252d781..b8d46875db 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -94,7 +94,7 @@ public class PeopleImpl implements People Map aMap = new HashMap<>(3); aMap.put(PARAM_FIRST_NAME, ContentModel.PROP_FIRSTNAME); aMap.put(PARAM_LAST_NAME, ContentModel.PROP_LASTNAME); - aMap.put(PARAM_USER_NAME, ContentModel.PROP_USERNAME); + aMap.put(PARAM_ID, ContentModel.PROP_USERNAME); sort_params_to_qnames = Collections.unmodifiableMap(aMap); } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java index da2e0b0e06..0fbc0b65c3 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -70,6 +70,7 @@ public class TestPeople extends EnterpriseTestApi private String account3Admin; private String account4Admin; private Person personAlice; + private Person personAliceD; private Person personBen; @Before @@ -715,10 +716,8 @@ public class TestPeople extends EnterpriseTestApi } } - private PublicApiClient.ListResponse listPeople(final PublicApiClient.Paging paging, String sortColumn, boolean asc) throws Exception + private PublicApiClient.ListResponse listPeople(final PublicApiClient.Paging paging, String sortColumn, boolean asc, int statusCode) throws Exception { - final PublicApiClient.People peopleProxy = publicApiClient.people(); - // sort params final Map params = new HashMap<>(); if (sortColumn != null) @@ -726,12 +725,19 @@ public class TestPeople extends EnterpriseTestApi params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC")); } - return peopleProxy.getPeople(createParams(paging, params)); + HttpResponse response = people.getAll("people", null, null, null, createParams(paging, params), "Failed to get people", statusCode); + JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list"); + if (jsonList == null) + { + return null; + } + + return Person.parsePeople(response.getJsonResponse()); } /** * Tests the capability to sort and paginate the list of people orderBy = - * firstName ASC skip = 1, count = 2 + * firstName ASC skip = 1, count = 3 * * @throws Exception */ @@ -742,15 +748,16 @@ public class TestPeople extends EnterpriseTestApi // paging int skipCount = 1; - int maxItems = 2; - int totalResults = 4; + int maxItems = 3; + int totalResults = 5; PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); // orderBy=firstName ASC - PublicApiClient.ListResponse resp = listPeople(paging, "firstName", true); + PublicApiClient.ListResponse resp = listPeople(paging, "firstName", true, 200); List expectedList = new LinkedList<>(); expectedList.add(personAlice); + expectedList.add(personAliceD); expectedList.add(personBen); checkList(expectedList, paging.getExpectedPaging(), resp); @@ -758,7 +765,7 @@ public class TestPeople extends EnterpriseTestApi /** * Tests the capability to sort and paginate the list of people orderBy = - * firstName DESC skip = 1, count = 2 + * firstName DESC skip = 1, count = 3 * * @throws Exception */ @@ -769,23 +776,24 @@ public class TestPeople extends EnterpriseTestApi // paging int skipCount = 1; - int maxItems = 2; - int totalResults = 4; + int maxItems = 3; + int totalResults = 5; PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); // orderBy=firstName DESC - PublicApiClient.ListResponse resp = listPeople(paging, "firstName", false); + PublicApiClient.ListResponse resp = listPeople(paging, "firstName", false, 200); List expectedList = new LinkedList<>(); expectedList.add((Person) personBen); expectedList.add((Person) personAlice); + expectedList.add((Person) personAliceD); checkList(expectedList, paging.getExpectedPaging(), resp); } /** - * Tests the capability to sort and paginate the list of people verifies - * default sorting, skip = 1, count = 2 + * Tests the capability paginate the list of people verifies default + * sorting, skip = 1, count = 3 * * @throws Exception */ @@ -796,15 +804,120 @@ public class TestPeople extends EnterpriseTestApi // paging int skipCount = 1; - int maxItems = 2; - int totalResults = 4; + int maxItems = 3; + int totalResults = 5; PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); - // orderBy=firstName DESC - PublicApiClient.ListResponse resp = listPeople(paging, null, false); + PublicApiClient.ListResponse resp = listPeople(paging, null, false, 200); List expectedList = new LinkedList<>(); expectedList.add((Person) personAlice); + expectedList.add((Person) personAliceD); + expectedList.add((Person) personBen); + + checkList(expectedList, paging.getExpectedPaging(), resp); + } + + /** + * Tests the capability to sort and paginate the list of people orderBy = + * username DESC skip = 1, count = 3 + * + * @throws Exception + */ + @Test + public void testPagingAndSortingByIdDesc() throws Exception + { + initializeContextForGetPeople(); + + // paging + int skipCount = 1; + int maxItems = 3; + int totalResults = 5; + PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); + + // orderBy=userName DESC + PublicApiClient.ListResponse resp = listPeople(paging, "id", false, 200); + + List expectedList = new LinkedList<>(); + expectedList.add((Person) personBen); + expectedList.add((Person) personAliceD); + expectedList.add((Person) personAlice); + + checkList(expectedList, paging.getExpectedPaging(), resp); + } + + /** + * Tests the capability to sort and paginate the list of people orderBy = + * invalid sort key ASC skip = 1, count = 3 + * + * @throws Exception + */ + @Test + public void testPagingAndSortingByInvalidSortKey() throws Exception + { + initializeContextForGetPeople(); + + // paging + int skipCount = 1; + int maxItems = 3; + int totalResults = 5; + PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); + + // orderBy=invalidSortKey ASC + listPeople(paging, "invalidSortKey", true, 400); + } + + /** + * Tests the capability to sort and paginate the list of people orderBy = + * lastName ASC skip = 2, count = 3 + * + * @throws Exception + */ + @Test + public void testPagingAndSortingByLastName() throws Exception + { + initializeContextForGetPeople(); + + // paging + int skipCount = 2; + int maxItems = 3; + int totalResults = 5; + PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); + + // orderBy=lastName ASC + PublicApiClient.ListResponse resp = listPeople(paging, "lastName", true, 200); + + List expectedList = new LinkedList<>(); + expectedList.add((Person) personBen); + expectedList.add((Person) personAliceD); + expectedList.add((Person) personAlice); + + checkList(expectedList, paging.getExpectedPaging(), resp); + } + + /** + * Tests the capability to sort and paginate the list of people orderBy = + * both firstName and lastName ASC skip = 1, count = 3 + * + * @throws Exception + */ + @Test + public void testPagingAndSortingByFirstNameAndLastName() throws Exception + { + initializeContextForGetPeople(); + + // paging + int skipCount = 1; + int maxItems = 3; + int totalResults = 5; + PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults); + + // orderBy=firstName,lastName ASC + PublicApiClient.ListResponse resp = listPeople(paging, "firstName,lastName", true, 200); + + List expectedList = new LinkedList<>(); + expectedList.add((Person) personAliceD); + expectedList.add((Person) personAlice); expectedList.add((Person) personBen); checkList(expectedList, paging.getExpectedPaging(), resp); @@ -823,11 +936,22 @@ public class TestPeople extends EnterpriseTestApi personAlice.setEnabled(true); people.create(personAlice); + publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin")); + personAliceD = new Person(); + personAliceD.setUserName("aliced@" + account4.getId()); + personAliceD.setId("aliced@" + account4.getId()); + personAliceD.setFirstName("Alice"); + personAliceD.setLastName("Davis"); + personAliceD.setEmail("alison.davis@example.com"); + personAliceD.setPassword("password"); + personAliceD.setEnabled(true); + people.create(personAliceD); + personBen = new Person(); personBen.setUserName("ben@" + account4.getId()); personBen.setId("ben@" + account4.getId()); personBen.setFirstName("Ben"); - personBen.setLastName("Smythe"); + personBen.setLastName("Carson"); personBen.setEmail("ben.smythe@example.com"); personBen.setPassword("password"); personBen.setEnabled(true); diff --git a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java index eb56d86574..70bf75bd8d 100644 --- a/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java +++ b/source/test-java/org/alfresco/rest/api/tests/client/PublicApiClient.java @@ -25,7 +25,6 @@ */ package org.alfresco.rest.api.tests.client; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.IOException; @@ -49,7 +48,26 @@ import org.alfresco.rest.api.tests.TestPeople; import org.alfresco.rest.api.tests.TestSites; import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload; import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder; -import org.alfresco.rest.api.tests.client.data.*; +import org.alfresco.rest.api.tests.client.data.Activities; +import org.alfresco.rest.api.tests.client.data.Activity; +import org.alfresco.rest.api.tests.client.data.CMISNode; +import org.alfresco.rest.api.tests.client.data.Comment; +import org.alfresco.rest.api.tests.client.data.ContentData; +import org.alfresco.rest.api.tests.client.data.Favourite; +import org.alfresco.rest.api.tests.client.data.FavouriteSite; +import org.alfresco.rest.api.tests.client.data.FolderNode; +import org.alfresco.rest.api.tests.client.data.JSONAble; +import org.alfresco.rest.api.tests.client.data.MemberOfSite; +import org.alfresco.rest.api.tests.client.data.NodeRating; +import org.alfresco.rest.api.tests.client.data.Person; +import org.alfresco.rest.api.tests.client.data.PersonNetwork; +import org.alfresco.rest.api.tests.client.data.Preference; +import org.alfresco.rest.api.tests.client.data.Site; +import org.alfresco.rest.api.tests.client.data.SiteContainer; +import org.alfresco.rest.api.tests.client.data.SiteImpl; +import org.alfresco.rest.api.tests.client.data.SiteMember; +import org.alfresco.rest.api.tests.client.data.SiteMembershipRequest; +import org.alfresco.rest.api.tests.client.data.Tag; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.chemistry.opencmis.client.api.Document; import org.apache.chemistry.opencmis.client.api.FileableCmisObject; @@ -640,28 +658,26 @@ public class PublicApiClient public class AbstractProxy { - public HttpResponse getAll(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage) throws PublicApiException - { - try - { - HttpResponse response = get("public", entityCollectionName, entityId, relationCollectionName, relationId, params); + public HttpResponse getAll(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage) + throws PublicApiException + { + return getAll(entityCollectionName, entityId, relationCollectionName, relationId, params, errorMessage, HttpServletResponse.SC_OK); + } - if (HttpServletResponse.SC_OK != response.getStatusCode()) - { - String msg = errorMessage + ": \n" + - " Response: " + response; - throw new PublicApiException(msg, response); - } - else - { - return response; - } - } - catch(IOException e) - { - throw new PublicApiException(e); - } - } + public HttpResponse getAll(String entityCollectionName, String entityId, String relationCollectionName, String relationId, Map params, String errorMessage, + int expectedStatus) throws PublicApiException + { + try + { + HttpResponse response = get("public", entityCollectionName, entityId, relationCollectionName, relationId, params); + checkStatus(errorMessage, expectedStatus, response); + return response; + } + catch (IOException e) + { + throw new PublicApiException(e); + } + } public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage) throws PublicApiException {