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();
}
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();
}
}
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();
}
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();
}
}
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();
}
}
Aggregations