use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CatalogWebService method updateCatalogEntry.
/**
* Updates the catalog entry with 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 entryVo The catalog entry
* @param newParentKey The parent key to move the entry (optional)
* @param httpRquest The HTTP request
* @param uriInfo The URI informations
* @return The response
*/
@POST
@Path("{path:.*}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateCatalogEntry(@PathParam("path") List<PathSegment> path, CatalogEntryVO entryVo, @QueryParam("newParentKey") Long newParentKey, @Context HttpServletRequest httpRequest, @Context UriInfo uriInfo) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Long key = getCatalogEntryKeyFromPath(path);
if (key == null) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
CatalogEntry ce = catalogManager.loadCatalogEntry(key);
if (ce.getType() == CatalogEntry.TYPE_NODE) {
// check if can admin category
if (!canAdminSubTree(ce, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
// fxdiff FXOLAT-122: course management
CatalogEntry newParent = null;
if (newParentKey != null) {
newParent = catalogManager.loadCatalogEntry(newParentKey);
if (newParent.getType() == CatalogEntry.TYPE_NODE) {
// check if can admin category
if (!canAdminSubTree(newParent, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
}
Identity id = getUserRequest(httpRequest).getIdentity();
LockResult lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockRes, id, LOCK_TOKEN);
if (!lock.isSuccess()) {
return getLockedResponse(lock, httpRequest);
}
try {
ce = catalogManager.loadCatalogEntry(ce);
if (ce == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// only update if needed
if (StringHelper.containsNonWhitespace(entryVo.getName())) {
ce.setName(entryVo.getName());
}
if (StringHelper.containsNonWhitespace(entryVo.getDescription())) {
ce.setDescription(entryVo.getDescription());
}
if (entryVo.getType() != null) {
ce.setType(guessType(entryVo));
}
catalogManager.updateCatalogEntry(ce);
if (newParent != null) {
catalogManager.moveCatalogEntry(ce, newParent);
}
} catch (Exception e) {
throw new WebApplicationException(e);
} finally {
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(lock);
}
CatalogEntryVO newEntryVo = link(get(ce), uriInfo);
return Response.ok(newEntryVo).build();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.
the class CatalogWebService method updateCatalogEntry.
/**
* Updates the catalog entry with 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 id The id of the catalog entry
* @param name The name
* @param description The description
* @param newParentKey The parent key to move the entry (optional)
* @param httpRquest The HTTP request
* @param uriInfo The URI informations
* @return The response
*/
@POST
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateCatalogEntry(@PathParam("path") List<PathSegment> path, @QueryParam("name") String name, @QueryParam("description") String description, // fxdiff FXOLAT-122: course management
@QueryParam("newParentKey") Long newParentKey, @Context HttpServletRequest httpRequest, @Context UriInfo uriInfo) {
CatalogEntryVO entryVo = new CatalogEntryVO();
entryVo.setName(name);
entryVo.setDescription(description);
return updateCatalogEntry(path, entryVo, newParentKey, httpRequest, uriInfo);
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project openolat by klemens.
the class CatalogTest method testPutCategoryJson.
@Test
public void testPutCategoryJson() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
CatalogEntryVO subEntry = new CatalogEntryVO();
subEntry.setName("Sub-entry-1");
subEntry.setDescription("Sub-entry-description-1");
subEntry.setType(CatalogEntry.TYPE_NODE);
URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
conn.addJsonEntity(method, subEntry);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
assertNotNull(vo);
List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
boolean saved = false;
for (CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
saved = true;
break;
}
}
assertTrue(saved);
conn.shutdown();
}
Aggregations