Search in sources :

Example 51 with BusinessGroupService

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

Example 52 with BusinessGroupService

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

the class LearningGroupWebService method getFolder.

@Path("{groupKey}/folder")
public VFSWebservice getFolder(@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_FOLDER)) {
        return null;
    }
    String relPath = collabTools.getFolderRelPath();
    QuotaManager qm = QuotaManager.getInstance();
    Quota folderQuota = qm.getCustomQuota(relPath);
    if (folderQuota == null) {
        Quota defQuota = qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_GROUPS);
        folderQuota = QuotaManager.getInstance().createQuota(relPath, defQuota.getQuotaKB(), defQuota.getUlLimitKB());
    }
    SubscriptionContext subsContext = null;
    VFSSecurityCallback secCallback = new VFSWebServiceSecurityCallback(true, true, true, folderQuota, subsContext);
    OlatRootFolderImpl rootContainer = new OlatRootFolderImpl(relPath, null);
    rootContainer.setLocalSecurityCallback(secCallback);
    return new VFSWebservice(rootContainer);
}
Also used : VFSWebServiceSecurityCallback(org.olat.core.util.vfs.restapi.VFSWebServiceSecurityCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Quota(org.olat.core.util.vfs.Quota) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) QuotaManager(org.olat.core.util.vfs.QuotaManager) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSWebservice(org.olat.core.util.vfs.restapi.VFSWebservice) Path(javax.ws.rs.Path)

Example 53 with BusinessGroupService

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

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)

Example 54 with BusinessGroupService

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

the class LearningGroupWebService method deleteGroup.

/**
 * Deletes the business group specified by the groupKey.
 * @response.representation.200.doc The business group is deleted
 * @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 request The HTTP request
 * @return
 */
@DELETE
@Path("{groupKey}")
public Response deleteGroup(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    if (!isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    bgs.deleteBusinessGroup(bg);
    return Response.ok().build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 55 with BusinessGroupService

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

the class LearningGroupWebService method getTutors.

/**
 * Returns the list of owners 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 Owners 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}/owners")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTutors(@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.isOwnersVisibleIntern()) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    List<Identity> coaches = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(bg, GroupRoles.coach.name());
    return getIdentityInGroup(coaches);
}
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)

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