Search in sources :

Example 1 with GroupInfoVO

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

the class LearningGroupWebService method getInformations.

/**
 * Returns the informations of the group specified by the groupKey.
 * @response.representation.200.qname {http://www.example.com}groupInfoVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Participants of the business group
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPINFOVO}
 * @response.representation.404.doc The business group cannot be found
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@GET
@Path("{groupKey}/infos")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getInformations(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = RestSecurityHelper.getIdentity(request);
    if (!isGroupManager(request)) {
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    GroupInfoVO info = getInformation(identity, bg);
    return Response.ok(info).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with GroupInfoVO

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

the class GroupMgmtTest method testGetGroupInfos.

@Test
public void testGetGroupInfos() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/infos").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    GroupInfoVO vo = conn.parse(response, GroupInfoVO.class);
    assertNotNull(vo);
    assertEquals(Boolean.TRUE, vo.getHasWiki());
    assertEquals("<p>Hello world</p>", vo.getNews());
    assertNotNull(vo.getForumKey());
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with GroupInfoVO

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

the class ObjectFactory method getInformation.

public static GroupInfoVO getInformation(Identity identity, BusinessGroup grp) {
    GroupInfoVO vo = new GroupInfoVO();
    vo.setKey(grp.getKey());
    vo.setName(grp.getName());
    vo.setDescription(grp.getDescription());
    vo.setMaxParticipants(grp.getMaxParticipants());
    vo.setMinParticipants(grp.getMinParticipants());
    vo.setType("LearningGroup");
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(grp);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_FORUM)) {
        vo.setForumKey(collabTools.getForum().getKey());
    }
    String news = collabTools.lookupNews();
    vo.setNews(news);
    boolean hasWiki = collabTools.isToolEnabled(CollaborationTools.TOOL_WIKI);
    vo.setHasWiki(hasWiki);
    boolean hasFolder = collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER);
    vo.setHasFolder(hasFolder);
    boolean hasFolderWrite = hasFolder;
    if (hasFolder) {
        Long access = collabTools.lookupFolderAccess();
        if (access != null && access.intValue() == CollaborationTools.FOLDER_ACCESS_OWNERS) {
            // is owner?
            hasFolderWrite = CoreSpringFactory.getImpl(BusinessGroupService.class).hasRoles(identity, grp, GroupRoles.coach.name());
        }
    }
    vo.setFolderWrite(hasFolderWrite);
    return vo;
}
Also used : GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) CollaborationTools(org.olat.collaboration.CollaborationTools)

Example 4 with GroupInfoVO

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

the class LearningGroupWebService method getInformations.

/**
 * Returns the informations of the group specified by the groupKey.
 * @response.representation.200.qname {http://www.example.com}groupInfoVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Participants of the business group
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPINFOVO}
 * @response.representation.404.doc The business group cannot be found
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@GET
@Path("{groupKey}/infos")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getInformations(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = RestSecurityHelper.getIdentity(request);
    if (!isGroupManager(request)) {
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    GroupInfoVO info = getInformation(identity, bg);
    return Response.ok(info).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupInfoVO(org.olat.restapi.support.vo.GroupInfoVO) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with GroupInfoVO

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

Aggregations

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