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
This commit is contained in:
Andrei Rebegea
2017-06-14 16:51:30 +00:00
parent e8e52ae6d0
commit ff2fc3a9cb
5 changed files with 134 additions and 8 deletions

View File

@@ -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<GroupMember> getGroupMembers(String groupId, final PublicApiClient.Paging paging, Map<String, String> 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<String, String> 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<String, String> 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();
}
}
}

View File

@@ -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<String, String> 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<String, String> 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<Group> getGroups(Map<String, String> params, String errorMessage, int expectedStatus) throws PublicApiException, ParseException
{
HttpResponse response = getAll("groups", null, null, null, params, errorMessage, expectedStatus);