Search in sources :

Example 1 with GroupVOes

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

the class UserMgmtTest method testUserGroup_owner.

@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);
    // g1
    assertEquals(1, groups.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupVOes(org.olat.restapi.support.vo.GroupVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with GroupVOes

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

the class UserMgmtTest method testUserGroup_owner.

@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);
    // g1
    assertEquals(1, groups.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupVOes(org.olat.restapi.support.vo.GroupVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with GroupVOes

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

the class UserMgmtTest method testUserGroup_participant.

@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);
    // g2 and g3
    assertEquals(2, groups.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupVOes(org.olat.restapi.support.vo.GroupVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 4 with GroupVOes

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

the class MyGroupWebService method getGroupList.

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, owner, participant);
    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;
        GroupVO[] groupVOs = new GroupVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.get(group);
        }
        GroupVOes voes = new GroupVOes();
        voes.setGroups(groupVOs);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        groups = bgs.findBusinessGroups(params, null, 0, -1);
        int count = 0;
        GroupVO[] groupVOs = new GroupVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.get(group);
        }
        return Response.ok(groupVOs).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupVOes(org.olat.restapi.support.vo.GroupVOes) GroupVO(org.olat.restapi.support.vo.GroupVO) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Example 5 with GroupVOes

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

the class MyGroupWebService method getGroupList.

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, owner, participant);
    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;
        GroupVO[] groupVOs = new GroupVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.get(group);
        }
        GroupVOes voes = new GroupVOes();
        voes.setGroups(groupVOs);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        groups = bgs.findBusinessGroups(params, null, 0, -1);
        int count = 0;
        GroupVO[] groupVOs = new GroupVO[groups.size()];
        for (BusinessGroup group : groups) {
            groupVOs[count++] = ObjectFactory.get(group);
        }
        return Response.ok(groupVOs).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupVOes(org.olat.restapi.support.vo.GroupVOes) GroupVO(org.olat.restapi.support.vo.GroupVO) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Aggregations

GroupVOes (org.olat.restapi.support.vo.GroupVOes)8 URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Test (org.junit.Test)6 BusinessGroup (org.olat.group.BusinessGroup)2 BusinessGroupService (org.olat.group.BusinessGroupService)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 GroupVO (org.olat.restapi.support.vo.GroupVO)2