Search in sources :

Example 21 with GroupVO

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

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)

Example 22 with GroupVO

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

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 23 with GroupVO

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

the class CourseGroupWebService method getGroupList.

/**
 * Lists all learn groups of the specified course.
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of all learning group of the course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
 * @response.representation.404.doc The context of the group not found
 * @param request The HTTP request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroupList() {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, courseEntryRef, 0, -1);
    int count = 0;
    GroupVO[] vos = new GroupVO[groups.size()];
    for (BusinessGroup group : groups) {
        vos[count++] = ObjectFactory.get(group);
    }
    return Response.ok(vos).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupVO(org.olat.restapi.support.vo.GroupVO) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with GroupVO

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

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 25 with GroupVO

use of org.olat.restapi.support.vo.GroupVO 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)

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