Search in sources :

Example 16 with CourseVOes

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

the class UserCoursesWebService method getMyCourses.

/**
 * Retrieves the list of "My entries" but limited to courses.
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param start The first result
 * @param limit Max result
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return The list of my entries
 */
@GET
@Path("my")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMyCourses(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsStudent(identity, null, start, limit, RepositoryEntryOrder.nameAsc);
        int totalCount = rm.countLearningResourcesAsStudent(identity);
        CourseVO[] vos = toCourseVo(repoEntries);
        CourseVOes voes = new CourseVOes();
        voes.setCourses(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsStudent(identity, null, 0, -1, RepositoryEntryOrder.nameAsc);
        CourseVO[] vos = toCourseVo(repoEntries);
        return Response.ok(vos).build();
    }
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CourseVOes (org.olat.restapi.support.vo.CourseVOes)16 RepositoryEntry (org.olat.repository.RepositoryEntry)14 CourseVO (org.olat.restapi.support.vo.CourseVO)14 URI (java.net.URI)8 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)8 HttpResponse (org.apache.http.HttpResponse)8 HttpGet (org.apache.http.client.methods.HttpGet)8 Test (org.junit.Test)8 Identity (org.olat.core.id.Identity)8 RepositoryManager (org.olat.repository.RepositoryManager)8 InputStream (java.io.InputStream)6 Path (javax.ws.rs.Path)6 ICourse (org.olat.course.ICourse)6 Roles (org.olat.core.id.Roles)2 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)2 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)2 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)2