Search in sources :

Example 21 with CatalogEntryVO

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

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);
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 22 with CatalogEntryVO

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

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();
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) WebApplicationException(javax.ws.rs.WebApplicationException) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) Identity(org.olat.core.id.Identity) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 23 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO 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 24 with CatalogEntryVO

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

the class CatalogVOFactory method get.

public static CatalogEntryVO get(CatalogEntry entry) {
    CatalogEntryVO vo = new CatalogEntryVO();
    vo.setKey(entry.getKey());
    vo.setName(entry.getName());
    vo.setDescription(entry.getDescription());
    vo.setExternalURL(entry.getExternalURL());
    vo.setType(entry.getType());
    vo.setParentKey(entry.getParent() == null ? null : entry.getParent().getKey());
    vo.setRepositoryEntryKey(entry.getRepositoryEntry() == null ? null : entry.getRepositoryEntry().getKey());
    return vo;
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO)

Example 25 with CatalogEntryVO

use of org.olat.restapi.support.vo.CatalogEntryVO 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

CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)44 CatalogEntry (org.olat.repository.CatalogEntry)30 URI (java.net.URI)24 HttpResponse (org.apache.http.HttpResponse)24 Test (org.junit.Test)24 Produces (javax.ws.rs.Produces)16 Path (javax.ws.rs.Path)14 HttpPost (org.apache.http.client.methods.HttpPost)10 HttpPut (org.apache.http.client.methods.HttpPut)8 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 POST (javax.ws.rs.POST)6 HttpGet (org.apache.http.client.methods.HttpGet)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 InputStream (java.io.InputStream)4 PUT (javax.ws.rs.PUT)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Identity (org.olat.core.id.Identity)4 LockResult (org.olat.core.util.coordinate.LockResult)4