From ff2fc3a9cb960bdbbc3c05e6451ea5204cf796a6 Mon Sep 17 00:00:00 2001 From: Andrei Rebegea Date: Wed, 14 Jun 2017 16:51:30 +0000 Subject: [PATCH] Merged 5.2.N (5.2.2) to HEAD (5.2) 133709 cturlica: REPO-1301: Retrieve a group - first commit git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137320 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- source/java/org/alfresco/rest/api/Groups.java | 17 +++++- .../rest/api/groups/GroupsEntityResource.java | 10 ++- .../alfresco/rest/api/impl/GroupsImpl.java | 10 +++ .../alfresco/rest/api/tests/GroupsTest.java | 61 +++++++++++++++++-- .../api/tests/client/PublicApiClient.java | 44 ++++++++++++- 5 files changed, 134 insertions(+), 8 deletions(-) diff --git a/source/java/org/alfresco/rest/api/Groups.java b/source/java/org/alfresco/rest/api/Groups.java index 96360ae70b..c864b1d64e 100644 --- a/source/java/org/alfresco/rest/api/Groups.java +++ b/source/java/org/alfresco/rest/api/Groups.java @@ -27,6 +27,7 @@ package org.alfresco.rest.api; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.GroupMember; +import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -46,13 +47,25 @@ public interface Groups String PARAM_MEMBER_TYPE_GROUP = "GROUP"; String PARAM_MEMBER_TYPE_PERSON = "PERSON"; + /** + * Get a group by it's id. + * + * @param groupId the identifier of a group. + * @param parameters the {@link Parameters} object to get the parameters passed into the request + * including: + * - include param (parentIds, zones) + * @return a {@code org.alfresco.rest.api.model.Group} object + * @throws EntityNotFoundException + */ + Group getGroup(String groupId, Parameters parameters) throws EntityNotFoundException; + /** * Gets a list of groups. * * @param parameters the {@link Parameters} object to get the parameters passed into the request * including: * - filter, sort & paging params (where, orderBy, skipCount, maxItems) - * - incFiles, incFolders (both true by default) + * - include param (parentIds, zones) * @return a paged list of {@code org.alfresco.rest.api.model.Group} objects */ CollectionWithPagingInfo getGroups(Parameters parameters); @@ -64,7 +77,7 @@ public interface Groups * @param parameters the {@link Parameters} object to get the parameters passed into the request * including: * - filter, sort & paging params (where, orderBy, skipCount, maxItems) - * - incFiles, incFolders (both true by default) + * - include param (parentIds, zones) * @return a paged list of {@code org.alfresco.rest.api.model.GroupMember} objects */ CollectionWithPagingInfo getGroupMembers(String groupId, Parameters parameters); diff --git a/source/java/org/alfresco/rest/api/groups/GroupsEntityResource.java b/source/java/org/alfresco/rest/api/groups/GroupsEntityResource.java index 6e8b52a0ec..dfca89ab73 100644 --- a/source/java/org/alfresco/rest/api/groups/GroupsEntityResource.java +++ b/source/java/org/alfresco/rest/api/groups/GroupsEntityResource.java @@ -28,6 +28,7 @@ package org.alfresco.rest.api.groups; import org.alfresco.rest.api.Groups; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; @@ -41,7 +42,7 @@ import org.springframework.beans.factory.InitializingBean; * @author cturlica */ @EntityResource(name = "groups", title = "Groups") -public class GroupsEntityResource implements EntityResourceAction.Read, InitializingBean +public class GroupsEntityResource implements EntityResourceAction.Read, EntityResourceAction.ReadById, InitializingBean { private Groups groups; @@ -62,4 +63,11 @@ public class GroupsEntityResource implements EntityResourceAction.Read, I { return groups.getGroups(params); } + + @Override + @WebApiDescription(title="Returns group information for group id") + public Group readById(String groupId, Parameters parameters) throws EntityNotFoundException + { + return groups.getGroup(groupId, parameters); + } } \ No newline at end of file diff --git a/source/java/org/alfresco/rest/api/impl/GroupsImpl.java b/source/java/org/alfresco/rest/api/impl/GroupsImpl.java index d7dc408e47..08d25672a8 100644 --- a/source/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/source/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -100,6 +100,16 @@ public class GroupsImpl implements Groups this.authorityService = authorityService; } + public Group getGroup(String groupId, Parameters parameters) throws EntityNotFoundException + { + AuthorityInfo authorityInfo = getAuthorityInfo(groupId); + + final Set rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP); + final List includeParam = parameters.getInclude(); + + return getGroup(authorityInfo, includeParam, rootAuthorities); + } + public CollectionWithPagingInfo getGroups(final Parameters parameters) { final List includeParam = parameters.getInclude(); diff --git a/source/test-java/org/alfresco/rest/api/tests/GroupsTest.java b/source/test-java/org/alfresco/rest/api/tests/GroupsTest.java index 6fd44376e6..fe2afc76e7 100644 --- a/source/test-java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/GroupsTest.java @@ -373,16 +373,24 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest } } - private void validateGroupDefaultFields(Group group) + private void validateGroupDefaultFields(Group group, boolean ignoreOptionallyIncluded) { assertNotNull(group); assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); assertNotNull(group.getIsRoot()); - // Optionally included. - assertNull(group.getParentIds()); - assertNull(group.getZones()); + if (!ignoreOptionallyIncluded) + { + // Optionally included. + assertNull(group.getParentIds()); + assertNull(group.getZones()); + } + } + + private void validateGroupDefaultFields(Group group) + { + validateGroupDefaultFields(group, false); } private ListResponse getGroupMembers(String groupId, final PublicApiClient.Paging paging, Map otherParams, String errorMessage, int expectedStatus) throws Exception @@ -561,4 +569,49 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest assertNotNull(groupMember.getMemberType()); } + @Test + public void testGetGroup() throws Exception + { + final Groups groupsProxy = publicApiClient.groups(); + try + { + createAuthorityContext(user1); + + setRequestContext(user1); + + // Check invalid group id. + { + groupsProxy.getGroup("invalidGroupId", HttpServletResponse.SC_NOT_FOUND); + } + + { + Group group = groupsProxy.getGroup(groupA.getId()); + validateGroupDefaultFields(group); + } + + { + Map otherParams = new HashMap<>(); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); + + Group group = groupsProxy.getGroup(groupA.getId(), otherParams, HttpServletResponse.SC_OK); + validateGroupDefaultFields(group, true); + assertNotNull(group.getParentIds()); + assertNull(group.getZones()); + } + + { + Map otherParams = new HashMap<>(); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES); + + Group group = groupsProxy.getGroup(groupA.getId(), otherParams, HttpServletResponse.SC_OK); + validateGroupDefaultFields(group, true); + assertNull(group.getParentIds()); + assertNotNull(group.getZones()); + } + } + finally + { + clearAuthorityContext(); + } + } } 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 ee4a1f3a21..ab5a7dcf95 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 @@ -70,6 +70,8 @@ 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.alfresco.rest.framework.core.exceptions.EntityNotFoundException; +import org.alfresco.rest.framework.resource.parameters.Parameters; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.chemistry.opencmis.client.api.Document; import org.apache.chemistry.opencmis.client.api.FileableCmisObject; @@ -706,7 +708,22 @@ public class PublicApiClient throw new PublicApiException(e); } } - + + public HttpResponse getSingle(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 update(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException { return update(entityCollectionName, entityId, relationCollectionName, relationId, body, null, errorMessage, 200); @@ -2248,6 +2265,31 @@ public class PublicApiClient public class Groups extends AbstractProxy { + public Group getGroup(String groupId) throws PublicApiException + { + return getGroup(groupId, HttpServletResponse.SC_OK); + } + + public Group getGroup(String groupId, int expectedStatus) throws PublicApiException + { + return getGroup(groupId, null, expectedStatus); + } + + public Group getGroup(String groupId, Map params, int expectedStatus) throws PublicApiException + { + HttpResponse response = getSingle("groups", groupId, null, null, params, "Failed to get group " + groupId, expectedStatus); + if ((response != null) && (response.getJsonResponse() != null)) + { + JSONObject jsonEntity = (JSONObject) response.getJsonResponse().get("entry"); + if (jsonEntity != null) + { + return Group.parseGroup(jsonEntity); + } + } + + return null; + } + public ListResponse getGroups(Map params, String errorMessage, int expectedStatus) throws PublicApiException, ParseException { HttpResponse response = getAll("groups", null, null, null, params, errorMessage, expectedStatus);