Search in sources :

Example 51 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class CourseGroupWebService method putNewGroup.

/**
 * Creates a new group for the course.
 * @response.representation.qname {http://www.example.com}groupVO
 * @response.representation.mediaType application/xml, application/json
 * @response.representation.doc A group to save
 * @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 persisted 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
 * @param group The group's metadatas
 * @param request The HTTP request
 * @return
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response putNewGroup(GroupVO group, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isGroupManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    UserRequest ureq = RestSecurityHelper.getUserRequest(request);
    BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class);
    RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(course, false);
    BusinessGroup bg;
    if (group.getKey() != null && group.getKey() > 0) {
        // group already exists
        bg = bgm.loadBusinessGroup(group.getKey());
        bgm.addResourceTo(bg, courseRe);
    } else {
        Integer min = normalize(group.getMinParticipants());
        Integer max = normalize(group.getMaxParticipants());
        bg = bgm.createBusinessGroup(ureq.getIdentity(), group.getName(), group.getDescription(), group.getExternalId(), group.getManagedFlags(), min, max, false, false, courseRe);
    }
    GroupVO savedVO = ObjectFactory.get(bg);
    return Response.ok(savedVO).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) GroupVO(org.olat.restapi.support.vo.GroupVO) UserRequest(org.olat.core.gui.UserRequest) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 52 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

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 53 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

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 54 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

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

GroupVO (org.olat.restapi.support.vo.GroupVO)54 URI (java.net.URI)36 HttpResponse (org.apache.http.HttpResponse)36 Test (org.junit.Test)36 BusinessGroup (org.olat.group.BusinessGroup)30 HttpGet (org.apache.http.client.methods.HttpGet)20 BusinessGroupService (org.olat.group.BusinessGroupService)16 InputStream (java.io.InputStream)14 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)14 HttpPost (org.apache.http.client.methods.HttpPost)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 GET (javax.ws.rs.GET)8 Identity (org.olat.core.id.Identity)8 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 CollaborationTools (org.olat.collaboration.CollaborationTools)6 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)6 GroupConfigurationVO (org.olat.restapi.support.vo.GroupConfigurationVO)6 ArrayList (java.util.ArrayList)4