Search in sources :

Example 86 with BusinessGroup

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

Example 87 with BusinessGroup

use of org.olat.group.BusinessGroup 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 88 with BusinessGroup

use of org.olat.group.BusinessGroup 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 89 with BusinessGroup

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

the class LearningGroupWebService method deleteNews.

/**
 * Deletes the news of the group if the news tool is enabled.
 * @response.representation.200.doc The news are deleted
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The business group cannot be found or hte news tool is not enabled
 * @param groupKey The key of the group
 * @param request The HTTP request
 * @return
 */
@DELETE
@Path("{groupKey}/news")
public Response deleteNews(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
    if (bg == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (tools.isToolEnabled(CollaborationTools.TOOL_NEWS)) {
        tools.saveNews(null);
        return Response.ok().build();
    } else {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) CollaborationTools(org.olat.collaboration.CollaborationTools) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 90 with BusinessGroup

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

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38