Search in sources :

Example 1 with CatalogEntryVOes

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

the class CatalogTest method testGetRootsWithPaging.

@Test
public void testGetRootsWithPaging() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVOes vos = conn.parse(response, CatalogEntryVOes.class);
    assertNotNull(vos);
    assertNotNull(vos.getCatalogEntries());
    // Root-1
    assertEquals(1, vos.getCatalogEntries().length);
    assertEquals(1, vos.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CatalogEntryVOes(org.olat.restapi.support.vo.CatalogEntryVOes) URI(java.net.URI) Test(org.junit.Test)

Example 2 with CatalogEntryVOes

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

the class CatalogWebService method getChildren.

/**
 * Returns a list of catalog entries.
 * @response.representation.200.qname {http://www.example.com}catalogEntryVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of catalog entries
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVOes}
 * @response.representation.404.doc The path could not be resolved to a valid catalog entry
 * @param path The path
 * @param start
 * @param limit
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return The response
 */
@GET
@Path("{path:.*}/children")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getChildren(@PathParam("path") List<PathSegment> path, @QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    if (path.isEmpty()) {
        return getRoots(httpRequest, request);
    }
    Long ceKey = getCatalogEntryKeyFromPath(path);
    if (ceKey == null) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    CatalogEntry ce = catalogManager.loadCatalogEntry(ceKey);
    if (ce == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = catalogManager.countChildrenOf(ce, -1);
        List<CatalogEntry> entries = catalogManager.getChildrenOf(ce, start, limit, CatalogEntry.OrderBy.name, true);
        CatalogEntryVO[] entryVOes = toArray(entries);
        CatalogEntryVOes voes = new CatalogEntryVOes();
        voes.setTotalCount(totalCount);
        voes.setCatalogEntries(entryVOes);
        return Response.ok(voes).build();
    } else {
        List<CatalogEntry> entries = catalogManager.getChildrenOf(ce);
        CatalogEntryVO[] entryVOes = toArray(entries);
        return Response.ok(entryVOes).build();
    }
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) CatalogEntryVOes(org.olat.restapi.support.vo.CatalogEntryVOes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with CatalogEntryVOes

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

the class CatalogTest method testGetRootsWithPaging.

@Test
public void testGetRootsWithPaging() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVOes vos = conn.parse(response, CatalogEntryVOes.class);
    assertNotNull(vos);
    assertNotNull(vos.getCatalogEntries());
    // Root-1
    assertEquals(1, vos.getCatalogEntries().length);
    assertEquals(1, vos.getTotalCount());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CatalogEntryVOes(org.olat.restapi.support.vo.CatalogEntryVOes) URI(java.net.URI) Test(org.junit.Test)

Example 4 with CatalogEntryVOes

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

the class CatalogWebService method getRoots.

/**
 * Returns the list of root catalog entries.
 * @response.representation.200.qname {http://www.example.com}catalogEntryVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of roots catalog entries
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVOes}
 * @return The response
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getRoots(@Context HttpServletRequest httpRequest, @Context Request request) {
    List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
    CatalogEntryVO[] entryVOes = toArray(rootEntries);
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        CatalogEntryVOes voes = new CatalogEntryVOes();
        voes.setCatalogEntries(entryVOes);
        voes.setTotalCount(1);
        return Response.ok(voes).build();
    } else {
        return Response.ok(entryVOes).build();
    }
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) CatalogEntryVOes(org.olat.restapi.support.vo.CatalogEntryVOes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with CatalogEntryVOes

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

the class CatalogWebService method getRoots.

/**
 * Returns the list of root catalog entries.
 * @response.representation.200.qname {http://www.example.com}catalogEntryVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of roots catalog entries
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVOes}
 * @return The response
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getRoots(@Context HttpServletRequest httpRequest, @Context Request request) {
    List<CatalogEntry> rootEntries = catalogManager.getRootCatalogEntries();
    CatalogEntryVO[] entryVOes = toArray(rootEntries);
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        CatalogEntryVOes voes = new CatalogEntryVOes();
        voes.setCatalogEntries(entryVOes);
        voes.setTotalCount(1);
        return Response.ok(voes).build();
    } else {
        return Response.ok(entryVOes).build();
    }
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) CatalogEntryVOes(org.olat.restapi.support.vo.CatalogEntryVOes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CatalogEntryVOes (org.olat.restapi.support.vo.CatalogEntryVOes)8 URI (java.net.URI)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 Test (org.junit.Test)4 CatalogEntry (org.olat.repository.CatalogEntry)4 CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)4 Path (javax.ws.rs.Path)2