Search in sources :

Example 1 with GroupInfoVOes

use of org.olat.restapi.support.vo.GroupInfoVOes in project OpenOLAT by OpenOLAT.

the class UserMgmtTest method testUserGroupInfosWithPaging.

@Test
public void testUserGroupInfosWithPaging() 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("infos").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());
    GroupInfoVOes groups = conn.parse(response, GroupInfoVOes.class);
    assertNotNull(groups);
    assertNotNull(groups.getGroups());
    assertEquals(1, groups.getGroups().length);
    // g1, g2 and g3
    assertEquals(3, groups.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupInfoVOes(org.olat.restapi.support.vo.GroupInfoVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with GroupInfoVOes

use of org.olat.restapi.support.vo.GroupInfoVOes in project openolat by klemens.

the class UserMgmtTest method testUserGroupInfosWithPaging.

@Test
public void testUserGroupInfosWithPaging() 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("infos").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());
    GroupInfoVOes groups = conn.parse(response, GroupInfoVOes.class);
    assertNotNull(groups);
    assertNotNull(groups.getGroups());
    assertEquals(1, groups.getGroups().length);
    // g1, g2 and g3
    assertEquals(3, groups.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupInfoVOes(org.olat.restapi.support.vo.GroupInfoVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with GroupInfoVOes

use of org.olat.restapi.support.vo.GroupInfoVOes in project OpenOLAT by OpenOLAT.

the class MyGroupWebService method getUserGroupInfosList.

/**
 * Return all groups with information of a user. Paging is mandatory!
 * @response.representation.200.qname {http://www.example.com}groupInfoVO
 * @response.representation.200.mediaType application/xml;pagingspec=1.0, application/json;pagingspec=1.0
 * @response.representation.200.doc The groups of the user
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPINFOVOes}
 * @response.representation.406.doc The request hasn't paging information
 * @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 with additional informations
 */
@GET
@Path("infos")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserGroupInfosList(@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) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    params.setManaged(managed);
    List<BusinessGroup> groups;
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = bgs.countBusinessGroups(params, null);
        groups = bgs.findBusinessGroups(params, null, start, limit);
        int count = 0;
        GroupInfoVO[] groupVOs = new GroupInfoVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.getInformation(retrievedUser, group);
        }
        GroupInfoVOes voes = new GroupInfoVOes();
        voes.setGroups(groupVOs);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) GroupInfoVOes(org.olat.restapi.support.vo.GroupInfoVOes) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with GroupInfoVOes

use of org.olat.restapi.support.vo.GroupInfoVOes in project openolat by klemens.

the class MyGroupWebService method getUserGroupInfosList.

/**
 * Return all groups with information of a user. Paging is mandatory!
 * @response.representation.200.qname {http://www.example.com}groupInfoVO
 * @response.representation.200.mediaType application/xml;pagingspec=1.0, application/json;pagingspec=1.0
 * @response.representation.200.doc The groups of the user
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPINFOVOes}
 * @response.representation.406.doc The request hasn't paging information
 * @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 with additional informations
 */
@GET
@Path("infos")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserGroupInfosList(@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) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    params.setManaged(managed);
    List<BusinessGroup> groups;
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = bgs.countBusinessGroups(params, null);
        groups = bgs.findBusinessGroups(params, null, start, limit);
        int count = 0;
        GroupInfoVO[] groupVOs = new GroupInfoVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.getInformation(retrievedUser, group);
        }
        GroupInfoVOes voes = new GroupInfoVOes();
        voes.setGroups(groupVOs);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) GroupInfoVOes(org.olat.restapi.support.vo.GroupInfoVOes) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GroupInfoVOes (org.olat.restapi.support.vo.GroupInfoVOes)4 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 Test (org.junit.Test)2 BusinessGroup (org.olat.group.BusinessGroup)2 BusinessGroupService (org.olat.group.BusinessGroupService)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 GroupInfoVO (org.olat.restapi.support.vo.GroupInfoVO)2