Search in sources :

Example 6 with GroupVO

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

the class LearningGroupWebService method createGroup.

/**
 * Create a group.
 * @response.representation.qname {http://www.example.com}groupVO
 * @response.representation.mediaType application/xml, application/json
 * @response.representation.doc A business group in the OLAT system
 * @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The saved business group
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group cannot be found
 * @param groupKey The key of the group
 * @param group The group
 * @param request The HTTP request
 * @return
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createGroup(final GroupVO group, @Context HttpServletRequest request) {
    Identity identity = RestSecurityHelper.getIdentity(request);
    if (identity == null || !isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    if (group.getKey() != null && group.getKey().longValue() > 0) {
        return postGroup(group.getKey(), group, request);
    }
    if (!StringHelper.containsNonWhitespace(group.getName())) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    Integer minPart = normalize(group.getMinParticipants());
    Integer maxPart = normalize(group.getMaxParticipants());
    BusinessGroup newBG = bgs.createBusinessGroup(identity, group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), minPart, maxPart, false, false, null);
    GroupVO savedVO = ObjectFactory.get(newBG);
    return Response.ok(savedVO).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) GroupVO(org.olat.restapi.support.vo.GroupVO) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 7 with GroupVO

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

the class LearningGroupWebService method getGroupList.

/**
 * Return the list of all groups if you have group manager permission, or all
 * learning group that you particip with or owne.
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc This is the list of all groups in OLAT system
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
 * @param externalId Search with an external ID
 * @param managed (true / false) Search only managed / not managed groups
 * @param request The HTTP Request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroupList(@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<BusinessGroup> groups;
    SearchBusinessGroupParams params;
    if (isGroupManager(request)) {
        params = new SearchBusinessGroupParams();
    } else {
        Identity identity = RestSecurityHelper.getIdentity(request);
        params = new SearchBusinessGroupParams(identity, true, true);
    }
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    params.setManaged(managed);
    groups = bgs.findBusinessGroups(params, null, 0, -1);
    int count = 0;
    GroupVO[] groupVOs = new GroupVO[groups.size()];
    for (BusinessGroup bg : groups) {
        groupVOs[count++] = ObjectFactory.get(bg);
    }
    return Response.ok(groupVOs).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) GroupVO(org.olat.restapi.support.vo.GroupVO) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with GroupVO

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

the class ObjectFactory method get.

public static GroupVO get(BusinessGroup grp) {
    GroupVO vo = new GroupVO();
    vo.setKey(grp.getKey());
    vo.setName(grp.getName());
    vo.setDescription(grp.getDescription());
    vo.setMaxParticipants(grp.getMaxParticipants());
    vo.setMinParticipants(grp.getMinParticipants());
    vo.setExternalId(grp.getExternalId());
    vo.setManagedFlags(grp.getManagedFlagsString());
    vo.setType("LearningGroup");
    return vo;
}
Also used : GroupVO(org.olat.restapi.support.vo.GroupVO)

Example 9 with GroupVO

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

the class GroupMgmtTest method testCreateCourseGroup.

@Test
public void testCreateCourseGroup() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    GroupVO vo = new GroupVO();
    vo.setName("rest-g5-new");
    vo.setDescription("rest-g5 description");
    vo.setType("BuddyGroup");
    URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, vo);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    GroupVO newGroupVo = conn.parse(response, GroupVO.class);
    assertNotNull(newGroupVo);
    BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
    assertNotNull(bg);
    assertEquals(bg.getKey(), newGroupVo.getKey());
    assertEquals(bg.getName(), "rest-g5-new");
    assertEquals(bg.getDescription(), "rest-g5 description");
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 10 with GroupVO

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

the class GroupMgmtTest method updateDeleteNews.

@Test
public void updateDeleteNews() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create the group
    GroupVO vo = new GroupVO();
    vo.setName("rest-g8-news");
    vo.setDescription("rest-g8 for news operations");
    vo.setType("BuddyGroup");
    URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, vo);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    GroupVO newGroupVo = conn.parse(response, GroupVO.class);
    assertNotNull(newGroupVo);
    // update the configuration
    GroupConfigurationVO configVo = new GroupConfigurationVO();
    configVo.setTools(new String[] { "hasNews" });
    configVo.setNews("<p>News!</p>");
    URI configRequest = UriBuilder.fromUri(getContextURI()).path("groups").path(newGroupVo.getKey().toString()).path("configuration").build();
    HttpPost configMethod = conn.createPost(configRequest, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(configMethod, configVo);
    HttpResponse configResponse = conn.execute(configMethod);
    assertEquals(200, configResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(configResponse.getEntity());
    // update the news an contact node
    URI newsRequest = UriBuilder.fromUri(getContextURI()).path("groups").path(newGroupVo.getKey().toString()).path("news").build();
    HttpPost updateNewsMethod = conn.createPost(newsRequest, MediaType.APPLICATION_JSON);
    conn.addEntity(updateNewsMethod, new BasicNameValuePair("news", "<p>The last news</p>"));
    HttpResponse updateResponse = conn.execute(updateNewsMethod);
    assertEquals(200, updateResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(updateResponse.getEntity());
    // check the last news
    BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    String news = collabTools.lookupNews();
    assertEquals("<p>The last news</p>", news);
    // delete the news
    HttpDelete deleteNewsMethod = conn.createDelete(newsRequest, MediaType.APPLICATION_JSON);
    HttpResponse deleteResponse = conn.execute(deleteNewsMethod);
    assertEquals(200, deleteResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(deleteResponse.getEntity());
    // reload and check the news are empty
    dbInstance.commitAndCloseSession();
    CollaborationTools reloadedCollabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    String deletedNews = reloadedCollabTools.lookupNews();
    assertNull(deletedNews);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GroupConfigurationVO(org.olat.restapi.support.vo.GroupConfigurationVO) HttpDelete(org.apache.http.client.methods.HttpDelete) BusinessGroup(org.olat.group.BusinessGroup) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

GroupVO (org.olat.restapi.support.vo.GroupVO)54 URI (java.net.URI)36 HttpResponse (org.apache.http.HttpResponse)36 Test (org.junit.Test)36 BusinessGroup (org.olat.group.BusinessGroup)30 HttpGet (org.apache.http.client.methods.HttpGet)20 BusinessGroupService (org.olat.group.BusinessGroupService)16 InputStream (java.io.InputStream)14 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)14 HttpPost (org.apache.http.client.methods.HttpPost)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 GET (javax.ws.rs.GET)8 Identity (org.olat.core.id.Identity)8 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 CollaborationTools (org.olat.collaboration.CollaborationTools)6 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)6 GroupConfigurationVO (org.olat.restapi.support.vo.GroupConfigurationVO)6 ArrayList (java.util.ArrayList)4