Search in sources :

Example 1 with CourseInfoVOes

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

the class CoursesInfosTest method testGetCourseInfos.

@Test
public void testGetCourseInfos() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = conn.getContextURI().path("repo").path("courses").path("infos").build();
    HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(get);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    CourseInfoVOes infos = conn.parse(response, CourseInfoVOes.class);
    Assert.assertNotNull(infos);
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CourseInfoVOes(org.olat.restapi.support.vo.CourseInfoVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with CourseInfoVOes

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

the class CoursesInfosWebService method getCourseInfoList.

/**
 * Get courses informations viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
 * @response.representation.200.doc List of visible courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVOes}
 * @param start
 * @param limit
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfoList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    // fxdiff VCRP-1,2: access control of resources
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
        List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>();
        final Set<Long> forumNotified = new HashSet<Long>();
        final Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
        collectSubscriptions(identity, forumNotified, courseNotified);
        for (RepositoryEntry entry : repoEntries) {
            CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
            if (info != null) {
                infos.add(info);
            }
        }
        CourseInfoVO[] vos = infos.toArray(new CourseInfoVO[infos.size()]);
        CourseInfoVOes voes = new CourseInfoVOes();
        voes.setInfos(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        return Response.serverError().status(Status.FORBIDDEN).build();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CourseInfoVOes(org.olat.restapi.support.vo.CourseInfoVOes) ArrayList(java.util.ArrayList) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with CourseInfoVOes

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

the class CoursesInfosTest method testGetCourseInfos.

@Test
public void testGetCourseInfos() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = conn.getContextURI().path("repo").path("courses").path("infos").build();
    HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(get);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    CourseInfoVOes infos = conn.parse(response, CourseInfoVOes.class);
    Assert.assertNotNull(infos);
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CourseInfoVOes(org.olat.restapi.support.vo.CourseInfoVOes) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 4 with CourseInfoVOes

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

the class CoursesInfosWebService method getCourseInfoList.

/**
 * Get courses informations viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
 * @response.representation.200.doc List of visible courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVOes}
 * @param start
 * @param limit
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfoList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    // fxdiff VCRP-1,2: access control of resources
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
        List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>();
        final Set<Long> forumNotified = new HashSet<Long>();
        final Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
        collectSubscriptions(identity, forumNotified, courseNotified);
        for (RepositoryEntry entry : repoEntries) {
            CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
            if (info != null) {
                infos.add(info);
            }
        }
        CourseInfoVO[] vos = infos.toArray(new CourseInfoVO[infos.size()]);
        CourseInfoVOes voes = new CourseInfoVOes();
        voes.setInfos(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        return Response.serverError().status(Status.FORBIDDEN).build();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CourseInfoVOes(org.olat.restapi.support.vo.CourseInfoVOes) ArrayList(java.util.ArrayList) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CourseInfoVOes (org.olat.restapi.support.vo.CourseInfoVOes)4 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 Test (org.junit.Test)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryManager (org.olat.repository.RepositoryManager)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 CourseInfoVO (org.olat.restapi.support.vo.CourseInfoVO)2