Search in sources :

Example 11 with BusinessGroupService

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

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

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

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

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

the class LearningGroupWebService method getGroupList.

/**
 * Return the list of all groups if you have group manager permission, or all
 * learning group that you particip with or owne.
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc This is the list of all groups in OLAT system
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
 * @param externalId Search with an external ID
 * @param managed (true / false) Search only managed / not managed groups
 * @param request The HTTP Request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroupList(@QueryParam("externalId") String externalId, @QueryParam("managed") Boolean managed, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<BusinessGroup> groups;
    SearchBusinessGroupParams params;
    if (isGroupManager(request)) {
        params = new SearchBusinessGroupParams();
    } else {
        Identity identity = RestSecurityHelper.getIdentity(request);
        params = new SearchBusinessGroupParams(identity, true, true);
    }
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    params.setManaged(managed);
    groups = bgs.findBusinessGroups(params, null, 0, -1);
    int count = 0;
    GroupVO[] groupVOs = new GroupVO[groups.size()];
    for (BusinessGroup bg : groups) {
        groupVOs[count++] = ObjectFactory.get(bg);
    }
    return Response.ok(groupVOs).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) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with BusinessGroupService

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

the class LearningGroupWebService method addParticipant.

/**
 * Adds a participant to the group.
 * @response.representation.200.doc The user is added as participant 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}/participants/{identityKey}")
public Response addParticipant(@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();
        }
        BusinessGroupAddResponse state = bgs.addParticipants(ureq.getIdentity(), ureq.getUserSession().getRoles(), Collections.singletonList(identity), group, null);
        if (state.getAddedIdentities().contains(identity)) {
            return Response.ok().build();
        } else if (state.getIdentitiesAlreadyInGroup().contains(identity)) {
            return Response.ok().status(Status.NOT_MODIFIED).build();
        }
        return Response.serverError().status(Status.PRECONDITION_FAILED).build();
    } catch (Exception e) {
        log.error("Trying to add 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) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 15 with BusinessGroupService

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

the class OpenOLATStatisticsWebService method getUserStatisticsVO.

private UserStatisticsVO getUserStatisticsVO() {
    UserStatisticsVO stats = new UserStatisticsVO();
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    // activeUserCount="88" // registered and activated identities, same as in GUI
    long countActiveUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, Constants.USERSTATUS_ACTIVE);
    stats.setActiveUserCount(countActiveUsers);
    // active last day
    Calendar lastDay = Calendar.getInstance();
    lastDay.add(Calendar.DATE, -1);
    long activeUserCountDay = securityManager.countUniqueUserLoginsSince(lastDay.getTime());
    stats.setActiveUserCountLastDay(activeUserCountDay);
    // active last week
    Calendar lastWeek = Calendar.getInstance();
    lastWeek.add(Calendar.DATE, -7);
    long activeUserCountWeek = securityManager.countUniqueUserLoginsSince(lastWeek.getTime());
    stats.setActiveUserCountLastWeek(activeUserCountWeek);
    // active last month
    Calendar lastMonth = Calendar.getInstance();
    lastMonth.add(Calendar.MONTH, -1);
    long activeUserCountMonth = securityManager.countUniqueUserLoginsSince(lastMonth.getTime());
    stats.setActiveUserCountLastMonth(activeUserCountMonth);
    // active last 6 month
    Calendar last6Month = Calendar.getInstance();
    last6Month.add(Calendar.MONTH, -6);
    long activeUserCount6Month = securityManager.countUniqueUserLoginsSince(last6Month.getTime());
    stats.setActiveUserCountLast6Month(activeUserCount6Month);
    // externalUserCount="12" // EP invite identities, later maybe also used in courses for MOOCS, external experts etc)
    long invitationsCount = CoreSpringFactory.getImpl(InvitationDAO.class).countInvitations();
    stats.setExternalUserCount(invitationsCount);
    // blockedUserCount="0" // identities in login blocked state
    long blockedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    stats.setBlockedUserCount(blockedUserCount);
    // deletedUserCount="943" // deleted identities
    long deletedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_DELETED);
    stats.setDeletedUserCount(deletedUserCount);
    // totalUserCount="1043" // Sum of all above
    long countUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, null);
    stats.setTotalUserCount(countUsers);
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    long countGroups = bgs.countBusinessGroups(null, null);
    stats.setTotalGroupCount(countGroups);
    return stats;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) Calendar(java.util.Calendar) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) UserStatisticsVO(org.olat.restapi.system.vo.UserStatisticsVO) BaseSecurity(org.olat.basesecurity.BaseSecurity)

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