Search in sources :

Example 6 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method removeTutor.

/**
 * Removes the owner from the group.
 * @response.representation.200.doc The user is removed as owner from the group
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group or the user cannot be found
 * @param groupKey The key of the group
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@DELETE
@Path("{groupKey}/owners/{identityKey}")
public Response removeTutor(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        if (!isGroupManager(request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
        final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (identity == null || group == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        bgs.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), group);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to remove an owner to a group", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 7 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method removeParticipant.

/**
 * Removes a participant from the group.
 * @response.representation.200.doc The user is remove from the group as participant
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group or the user cannot be found
 * @param groupKey The key of the group
 * @param identityKey The id of the user
 * @param request The HTTP request
 * @return
 */
@DELETE
@Path("{groupKey}/participants/{identityKey}")
public Response removeParticipant(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        if (!isGroupManager(request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
        final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (identity == null || group == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        bgs.removeParticipants(ureq.getIdentity(), Collections.singletonList(identity), group, null);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to remove a participant to a group", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 8 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method addTutor.

/**
 * Adds an owner to the group.
 * @response.representation.200.doc The user is added as owner of the group
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group or the user cannot be found
 * @param groupKey The key of the group
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@PUT
@Path("{groupKey}/owners/{identityKey}")
public Response addTutor(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        if (!isGroupManager(request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
        final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
        if (identity == null || group == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        bgs.addOwners(ureq.getIdentity(), ureq.getUserSession().getRoles(), Collections.singletonList(identity), group, null);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to add an owner to a group", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 9 with BusinessGroupService

use of org.olat.group.BusinessGroupService 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 10 with BusinessGroupService

use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.

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)

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