use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.restapi.support.vo.CatalogEntryVO in project OpenOLAT by OpenOLAT.
the class CatalogTest method testPutCatalogEntryQuery.
@Test
public void testPutCatalogEntryQuery() throws IOException, URISyntaxException {
RepositoryEntry re = createRepository("put-cat-entry-query", 6458439l);
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).queryParam("name", "Sub-entry-2").queryParam("description", "Sub-entry-description-2").queryParam("type", String.valueOf(CatalogEntry.TYPE_NODE)).queryParam("repoEntryKey", re.getKey().toString()).build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
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);
CatalogEntry ce = null;
for (CatalogEntry child : children) {
if (vo.getKey().equals(child.getKey())) {
ce = child;
break;
}
}
assertNotNull(ce);
assertNotNull(ce.getRepositoryEntry());
assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
conn.shutdown();
}
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.qname {http://www.example.com}catalogEntryVO
* @response.representation.mediaType application/xml, application/json
* @response.representation.doc The catalog entry
* @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_CATALOGENTRYVO}
* @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 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 httpRquest The HTTP request
* @param uriInfo The URI informations
* @return The response
*/
@PUT
@Path("{path:.*}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addCatalogEntry(@PathParam("path") List<PathSegment> path, CatalogEntryVO entryVo, @Context HttpServletRequest httpRequest, @Context UriInfo uriInfo) {
if (!isAuthor(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Long parentKey = getCatalogEntryKeyFromPath(path);
if (parentKey == null) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
CatalogEntry parent = catalogManager.loadCatalogEntry(parentKey);
if (parent == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
int type = guessType(entryVo);
if (type == CatalogEntry.TYPE_NODE && !canAdminSubTree(parent, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntry re = null;
if (entryVo.getRepositoryEntryKey() != null) {
re = RepositoryManager.getInstance().lookupRepositoryEntry(entryVo.getRepositoryEntryKey());
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
}
Identity id = getUserRequest(httpRequest).getIdentity();
LockResult lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockRes, id, LOCK_TOKEN);
if (!lock.isSuccess()) {
return getLockedResponse(lock, httpRequest);
}
CatalogEntry ce = null;
try {
ce = catalogManager.createCatalogEntry();
ce.setType(guessType(entryVo));
ce.setName(entryVo.getName());
ce.setDescription(entryVo.getDescription());
ce.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
if (re != null) {
ce.setRepositoryEntry(re);
}
catalogManager.addCatalogEntry(parent, ce);
} 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 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.CatalogEntryVO in project OpenOLAT by OpenOLAT.
the class CatalogWebService method updatePostCatalogEntry.
/**
* Updates the 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 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_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updatePostCatalogEntry(@PathParam("path") List<PathSegment> path, @FormParam("name") String name, @FormParam("description") String description, // fxdiff FXOLAT-122: course management
@FormParam("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);
}
Aggregations