Search in sources :

Example 56 with BusinessGroupService

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

the class LearningGroupWebService method getNews.

/**
 * Returns the  news.
 *
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group cannot be found or the news tool is not enabled
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@GET
@Path("{groupKey}/news")
@Produces({ MediaType.TEXT_PLAIN })
public Response getNews(@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 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();
        }
    }
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (tools.isToolEnabled(CollaborationTools.TOOL_NEWS)) {
        String news = tools.lookupNews();
        if (news == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        return Response.ok(news).build();
    } else {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 57 with BusinessGroupService

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

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 58 with BusinessGroupService

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

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 59 with BusinessGroupService

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

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 60 with BusinessGroupService

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

the class ContactsWebService method getMyContacts.

/**
 * Retrieve the contacts of the logged in identity.
 * @response.representation.200.doc The list of contacts
 * @param start
 * @param limit
 * @param httpRequest The HTTP request
 * @return The list of contacts
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMyContacts(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest) {
    Identity identity = getIdentity(httpRequest);
    if (identity == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<Identity> contacts = bgs.findContacts(identity, start, limit);
    int totalCount = bgs.countContacts(identity);
    int count = 0;
    ContactVO[] userVOs = new ContactVO[contacts.size()];
    for (Identity contact : contacts) {
        userVOs[count++] = new ContactVO(contact);
    }
    ContactVOes voes = new ContactVOes();
    voes.setUsers(userVOs);
    voes.setTotalCount(totalCount);
    return Response.ok(voes).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) 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