Search in sources :

Example 26 with GroupVO

use of org.olat.restapi.support.vo.GroupVO 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)

Example 27 with GroupVO

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

the class CourseGroupWebService method getGroupList.

/**
 * Lists all learn groups of the specified course.
 * @response.representation.200.qname {http://www.example.com}groupVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of all learning group of the course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
 * @response.representation.404.doc The context of the group not found
 * @param request The HTTP request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getGroupList() {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, courseEntryRef, 0, -1);
    int count = 0;
    GroupVO[] vos = new GroupVO[groups.size()];
    for (BusinessGroup group : groups) {
        vos[count++] = ObjectFactory.get(group);
    }
    return Response.ok(vos).build();
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) GroupVO(org.olat.restapi.support.vo.GroupVO) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with GroupVO

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

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

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

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

use of org.olat.restapi.support.vo.GroupVO 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)

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