Search in sources :

Example 31 with BusinessGroupService

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

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

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

the class LearningGroupWebService method postGroupConfiguration.

@POST
@Path("{groupKey}/configuration")
public Response postGroupConfiguration(@PathParam("groupKey") Long groupKey, final GroupConfigurationVO group, @Context HttpServletRequest request) {
    if (!isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    String[] selectedTools = group.getTools();
    if (selectedTools == null) {
        selectedTools = new String[0];
    }
    String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    for (int i = availableTools.length; i-- > 0; ) {
        boolean enable = false;
        String tool = availableTools[i];
        for (String selectedTool : selectedTools) {
            if (tool.equals(selectedTool)) {
                enable = true;
            }
        }
        tools.setToolEnabled(tool, enable);
    }
    Map<String, Integer> toolsAccess = group.getToolsAccess();
    if (toolsAccess != null) {
        // ignore null for backward compatibility, don't change current configuration
        for (String tool : toolsAccess.keySet()) {
            tools.setToolAccess(tool, toolsAccess.get(tool));
        }
    }
    if (StringHelper.containsNonWhitespace(group.getNews())) {
        tools.saveNews(group.getNews());
    }
    boolean ownersIntern = bg.isOwnersVisibleIntern();
    if (group.getOwnersVisible() != null) {
        ownersIntern = group.getOwnersVisible().booleanValue();
    }
    boolean participantsIntern = bg.isParticipantsVisibleIntern();
    if (group.getParticipantsVisible() != null) {
        participantsIntern = group.getParticipantsVisible().booleanValue();
    }
    boolean waitingListIntern = bg.isWaitingListVisibleIntern();
    if (group.getWaitingListVisible() != null) {
        waitingListIntern = group.getWaitingListVisible().booleanValue();
    }
    boolean ownersPublic = bg.isOwnersVisiblePublic();
    if (group.getOwnersPublic() != null) {
        ownersPublic = group.getOwnersPublic().booleanValue();
    }
    boolean participantsPublic = bg.isParticipantsVisiblePublic();
    if (group.getParticipantsPublic() != null) {
        participantsPublic = group.getParticipantsPublic().booleanValue();
    }
    boolean waitingListPublic = bg.isWaitingListVisiblePublic();
    if (group.getWaitingListPublic() != null) {
        waitingListPublic = group.getWaitingListPublic().booleanValue();
    }
    bg = bgs.updateDisplayMembers(bg, ownersIntern, participantsIntern, waitingListIntern, ownersPublic, participantsPublic, waitingListPublic, bg.isDownloadMembersLists());
    return Response.ok().build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 34 with BusinessGroupService

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

Example 35 with BusinessGroupService

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

the class ENWebService method getGroups.

/**
 * Retrieves the groups where the enrollment happens
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The groups
 * @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 course or course node not found
 * @param nodeId The node's id
 * @param httpRequest The HTTP request
 * @return An array of groups
 */
@GET
@Path("{nodeId}/groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroups(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
    if (!isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!isAuthorEditor(course, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    CourseNode node = getParentNode(course, nodeId);
    ModuleConfiguration config = node.getModuleConfiguration();
    String groupNames = (String) config.get(ENCourseNode.CONFIG_GROUPNAME);
    @SuppressWarnings("unchecked") List<Long> groupKeys = (List<Long>) config.get(ENCourseNode.CONFIG_GROUP_IDS);
    if (groupKeys == null && StringHelper.containsNonWhitespace(groupNames)) {
        groupKeys = bgs.toGroupKeys(groupNames, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
    }
    if (groupKeys == null || groupKeys.isEmpty()) {
        return Response.ok(new GroupVO[0]).build();
    }
    List<GroupVO> voes = new ArrayList<GroupVO>();
    List<BusinessGroup> groups = bgs.loadBusinessGroups(groupKeys);
    for (BusinessGroup group : groups) {
        voes.add(get(group));
    }
    GroupVO[] voArr = new GroupVO[voes.size()];
    voes.toArray(voArr);
    return Response.ok(voArr).build();
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) GroupVO(org.olat.restapi.support.vo.GroupVO) BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) List(java.util.List) ENCourseNode(org.olat.course.nodes.ENCourseNode) CourseNode(org.olat.course.nodes.CourseNode) 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