use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogTest method testGetRoots.
@Test
public void testGetRoots() 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, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CatalogEntryVO> vos = parseEntryArray(body);
assertNotNull(vos);
// Root-1
assertEquals(1, vos.size());
conn.shutdown();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogTest method testGetChild.
@Test
public void testGetChild() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
assertNotNull(vo);
assertEquals(entry1.getName(), vo.getName());
assertEquals(entry1.getDescription(), vo.getDescription());
conn.shutdown();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogTest method testUpdateCatalogEntryJson.
@Test
public void testUpdateCatalogEntryJson() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
CatalogEntryVO entry = new CatalogEntryVO();
entry.setName("Entry-1-b");
entry.setDescription("Entry-description-1-b");
entry.setType(CatalogEntry.TYPE_NODE);
URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
conn.addJsonEntity(method, entry);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
assertNotNull(vo);
CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entry1);
assertEquals("Entry-1-b", updatedEntry.getName());
assertEquals("Entry-description-1-b", updatedEntry.getDescription());
conn.shutdown();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogWebService method getCatalogEntry.
/**
* Returns the metadata of the catalog entry.
* @response.representation.200.qname {http://www.example.com}catalogEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The catalog entry
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVO}
* @response.representation.401.doc The path could not be resolved to a valid catalog entry
* @param path The path
* @param uriInfo The URI informations
* @param httpRequest The HTTP request
* @param request The REST request
* @return The response
*/
@GET
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCatalogEntry(@PathParam("path") List<PathSegment> path, @Context UriInfo uriInfo, @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();
}
CatalogEntryVO vo = link(get(ce), uriInfo);
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogWebService method addCatalogEntry.
/**
* Adds a catalog entry under the path specified in the URL.
* @response.representation.200.qname {http://www.example.com}catalogEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The catalog entry
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVO}
* @response.representation.401.doc Not authorized
* @response.representation.404.doc The path could not be resolved to a valid catalog entry
* @param path The path
* @param name The name
* @param description The description
* @param type The type (leaf or node)
* @param repoEntryKey The id of the repository entry
* @param httpRquest The HTTP request
* @param uriInfo The URI informations
* @return The response
*/
@PUT
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addCatalogEntry(@PathParam("path") List<PathSegment> path, @QueryParam("name") String name, @QueryParam("description") String description, @QueryParam("type") Integer type, @QueryParam("repoEntryKey") Long repoEntryKey, @Context HttpServletRequest httpRequest, @Context UriInfo uriInfo) {
CatalogEntryVO entryVo = new CatalogEntryVO();
entryVo.setName(name);
entryVo.setDescription(description);
if (type != null) {
entryVo.setType(type.intValue());
}
entryVo.setRepositoryEntryKey(repoEntryKey);
return addCatalogEntry(path, entryVo, httpRequest, uriInfo);
}
Aggregations