Search in sources :

Example 81 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class LearningGroupWebService method getParticipants.

/**
 * Returns the list of participants of the group specified by the groupKey.
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Participants of the business group
 * @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
 * @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}/participants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getParticipants(@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();
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        if (!bg.isParticipantsVisibleIntern()) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    List<Identity> participants = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(bg, GroupRoles.participant.name());
    return getIdentityInGroup(participants);
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 82 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class LearningGroupWebService method postGroup.

/**
 * Updates 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
 */
@POST
@Path("{groupKey}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response postGroup(@PathParam("groupKey") Long groupKey, final GroupVO group, @Context HttpServletRequest request) {
    if (!isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    final BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!StringHelper.containsNonWhitespace(group.getName())) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    Identity identity = RestSecurityHelper.getIdentity(request);
    BusinessGroup mergedBg = bgs.updateBusinessGroup(identity, bg, group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), normalize(group.getMinParticipants()), normalize(group.getMaxParticipants()));
    // save the updated group
    GroupVO savedVO = ObjectFactory.get(mergedBg);
    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) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 83 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class LearningGroupWebService method findById.

/**
 * Return the group specified by the key of the group.
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc A business group in the OLAT system
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
 * @param groupKey The key of the group
 * @param request The REST request
 * @param httpRequest The HTTP request
 * @return
 */
@GET
@Path("{groupKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response findById(@PathParam("groupKey") Long groupKey, @Context Request request, @Context HttpServletRequest httpRequest) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = RestSecurityHelper.getIdentity(httpRequest);
    if (!isGroupManager(httpRequest) && !bgs.isIdentityInBusinessGroup(identity, bg)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    Date lastModified = bg.getLastModified();
    Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
    if (response == null) {
        GroupVO vo = ObjectFactory.get(bg);
        response = Response.ok(vo);
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) GroupVO(org.olat.restapi.support.vo.GroupVO) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 84 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class LearningGroupWebService method getForum.

/**
 * Return the Forum web service
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@Path("{groupKey}/forum")
public ForumWebService getForum(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
    if (bg == null) {
        return null;
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return null;
        }
    }
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_FORUM)) {
        Forum forum = collabTools.getForum();
        return new ForumWebService(forum);
    }
    return null;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) ForumWebService(org.olat.modules.fo.restapi.ForumWebService) CollaborationTools(org.olat.collaboration.CollaborationTools) Identity(org.olat.core.id.Identity) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 85 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project openolat by klemens.

the class LearningGroupWebService method getWiki.

/**
 * Return the Forum web service
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@Path("{groupKey}/wiki")
public GroupWikiWebService getWiki(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return null;
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return null;
        }
    }
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_WIKI)) {
        return new GroupWikiWebService(bg);
    }
    return null;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupWikiWebService(org.olat.modules.wiki.restapi.GroupWikiWebService) CollaborationTools(org.olat.collaboration.CollaborationTools) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path)

Aggregations

BusinessGroupService (org.olat.group.BusinessGroupService)102 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)58 Path (javax.ws.rs.Path)38 Produces (javax.ws.rs.Produces)30 GET (javax.ws.rs.GET)24 CollaborationTools (org.olat.collaboration.CollaborationTools)18 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)18 ArrayList (java.util.ArrayList)16 GroupVO (org.olat.restapi.support.vo.GroupVO)16 RepositoryEntry (org.olat.repository.RepositoryEntry)14 List (java.util.List)12 UserRequest (org.olat.core.gui.UserRequest)12 ICourse (org.olat.course.ICourse)10 HashSet (java.util.HashSet)8 PUT (javax.ws.rs.PUT)8 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)8 Roles (org.olat.core.id.Roles)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6