Skip to content
Snippets Groups Projects
Commit a69bf4c9 authored by srosse's avatar srosse
Browse files

OO-623,OPENOLAT-80: enhance the REST API with users/{identityKey}/groups/owner and participant

parent 3a5ac929
No related branches found
No related tags found
No related merge requests found
......@@ -84,9 +84,63 @@ public class MyGroupWebService {
@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed,
@Context HttpServletRequest httpRequest, @Context Request request) {
return getGroupList(start, limit, externalId, managed, true, true, httpRequest, request);
}
/**
* Return all groups of a user where the user is coach/owner.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The groups of the user
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
* @response.representation.404.doc The identity not found
* @param start The first result
* @param limit The maximum results
* @param externalId Search with an external ID
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of groups
*/
@GET
@Path("owner")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getOwnedGroupList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit,
@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed,
@Context HttpServletRequest httpRequest, @Context Request request) {
return getGroupList(start, limit, externalId, managed, true, false, httpRequest, request);
}
/**
* Return all groups of a user where the user is participant.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The groups of the user
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
* @response.representation.404.doc The identity not found
* @param start The first result
* @param limit The maximum results
* @param externalId Search with an external ID
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of groups
*/
@GET
@Path("participant")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getParticipatingGroupList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit,
@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed,
@Context HttpServletRequest httpRequest, @Context Request request) {
return getGroupList(start, limit, externalId, managed, false, true, httpRequest, request);
}
private Response getGroupList(Integer start, Integer limit, String externalId, Boolean managed,
boolean owner, boolean participant, HttpServletRequest httpRequest, Request request) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, owner, participant);
if(StringHelper.containsNonWhitespace(externalId)) {
params.setExternalId(externalId);
}
......@@ -116,8 +170,10 @@ public class MyGroupWebService {
}
return Response.ok(groupVOs).build();
}
}
/**
* Return all groups with information of a user. Paging is mandatory!
* @response.representation.200.qname {http://www.example.com}groupInfoVO
......
......@@ -996,6 +996,48 @@ public class UserMgmtTest extends OlatJerseyTestCase {
conn.shutdown();
}
@Test
public void testUserGroup_owner() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
//retrieve all groups
URI uri =UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString())
.path("groups").path("owner").queryParam("start", 0).queryParam("limit", 1).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
GroupVOes groups = conn.parse(response, GroupVOes.class);
assertNotNull(groups);
assertNotNull(groups.getGroups());
assertEquals(1, groups.getGroups().length);
assertEquals(1, groups.getTotalCount());//g1
conn.shutdown();
}
@Test
public void testUserGroup_participant() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
//retrieve all groups
URI uri =UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString())
.path("groups").path("participant").queryParam("start", 0).queryParam("limit", 1).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
GroupVOes groups = conn.parse(response, GroupVOes.class);
assertNotNull(groups);
assertNotNull(groups.getGroups());
assertEquals(1, groups.getGroups().length);
assertEquals(2, groups.getTotalCount());//g2 and g3
conn.shutdown();
}
@Test
public void testUserGroupInfosWithPaging() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment