Search in sources :

Example 56 with CatalogEntry

use of org.olat.repository.CatalogEntry 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 57 with CatalogEntry

use of org.olat.repository.CatalogEntry 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 58 with CatalogEntry

use of org.olat.repository.CatalogEntry in project openolat by klemens.

the class CatalogWebService method removeOwner.

/**
 * Remove an owner of the local sub tree
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The catalog entry
 * @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
 * @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 identityKey The id of the user
 * @param httpRquest The HTTP request
 * @return The response
 */
@DELETE
@Path("{path:.*}/owners/{identityKey}")
public Response removeOwner(@PathParam("path") List<PathSegment> path, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    Long key = getCatalogEntryKeyFromPath(path);
    if (key == null) {
        return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
    }
    CatalogEntry ce = catalogManager.loadCatalogEntry(key);
    if (ce == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    if (!isAuthor(httpRequest) && !canAdminSubTree(ce, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity identity = securityManager.loadIdentityByKey(identityKey, false);
    if (identity == null) {
        return Response.ok().build();
    }
    SecurityGroup sg = ce.getOwnerGroup();
    if (sg == null) {
        return Response.ok().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 {
        securityManager.removeIdentityFromSecurityGroup(identity, ce.getOwnerGroup());
    } catch (Exception e) {
        throw new WebApplicationException(e);
    } finally {
        CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(lock);
    }
    return Response.ok().build();
}
Also used : LockResult(org.olat.core.util.coordinate.LockResult) WebApplicationException(javax.ws.rs.WebApplicationException) CatalogEntry(org.olat.repository.CatalogEntry) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) WebApplicationException(javax.ws.rs.WebApplicationException) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 59 with CatalogEntry

use of org.olat.repository.CatalogEntry in project openolat by klemens.

the class PublishProcess method publishToCatalog.

protected void publishToCatalog(String choiceValue, List<CategoryLabel> labels) {
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Property prop = cpm.findCourseNodeProperty(rootNode, null, null, "catalog-choice");
    if (prop == null) {
        prop = cpm.createCourseNodePropertyInstance(rootNode, null, null, "catalog-choice", null, null, choiceValue, null);
        cpm.saveProperty(prop);
    } else {
        prop.setStringValue(choiceValue);
        cpm.updateProperty(prop);
    }
    CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
    List<CatalogEntry> refParentCategories = cm.getCatalogCategoriesFor(repositoryEntry);
    a_a: for (CategoryLabel label : labels) {
        CatalogEntry category = label.getCategory();
        CatalogEntry parentCategory = label.getParentCategory();
        if (label.isDeleted()) {
            // test
            if (category.getKey() != null) {
                List<CatalogEntry> children = cm.getChildrenOf(category);
                for (CatalogEntry child : children) {
                    if (child.getRepositoryEntry() != null && child.getRepositoryEntry().equalsByPersistableKey(repositoryEntry)) {
                        cm.deleteCatalogEntry(child);
                    }
                }
            }
        } else if (category.getKey() == null) {
            // it's a new entry -> check if not already in catalog at this position
            for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
                CatalogEntry refParentCategory = refIt.next();
                if (refParentCategory.equalsByPersistableKey(parentCategory)) {
                    refIt.remove();
                    break a_a;
                }
            }
            category.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
            cm.addCatalogEntry(parentCategory, category);
        } else {
            for (Iterator<CatalogEntry> refIt = refParentCategories.iterator(); refIt.hasNext(); ) {
                CatalogEntry refParentCategory = refIt.next();
                if (refParentCategory.equalsByPersistableKey(category)) {
                    refIt.remove();
                }
            }
        }
    }
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) List(java.util.List) ArrayList(java.util.ArrayList) CourseNode(org.olat.course.nodes.CourseNode) CategoryLabel(org.olat.course.editor.PublishStepCatalog.CategoryLabel) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) CatalogManager(org.olat.repository.manager.CatalogManager)

Example 60 with CatalogEntry

use of org.olat.repository.CatalogEntry in project openolat by klemens.

the class CatalogHelper method addCourseToCatalogEntry.

/**
 * Add a persisted course to the given catalog entry.
 *
 * @param course course object
 * @param catEntry catalog entry
 */
public static final void addCourseToCatalogEntry(final ICourse course, final CatalogEntry catEntry) {
    OLATResource ores = OLATResourceManager.getInstance().findResourceable(course.getResourceableId(), course.getResourceableTypeName());
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry re = rm.lookupRepositoryEntry(ores, true);
    CatalogManager cm = CoreSpringFactory.getImpl(CatalogManager.class);
    CatalogEntry newLinkNotPersistedYet = cm.createCatalogEntry();
    newLinkNotPersistedYet.setName(re.getDisplayname());
    newLinkNotPersistedYet.setDescription(re.getDescription());
    newLinkNotPersistedYet.setRepositoryEntry(re);
    newLinkNotPersistedYet.setType(CatalogEntry.TYPE_LEAF);
    newLinkNotPersistedYet.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup());
    cm.addCatalogEntry(catEntry, newLinkNotPersistedYet);
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) OLATResource(org.olat.resource.OLATResource) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) CatalogManager(org.olat.repository.manager.CatalogManager)

Aggregations

CatalogEntry (org.olat.repository.CatalogEntry)122 Test (org.junit.Test)30 CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)30 URI (java.net.URI)28 HttpResponse (org.apache.http.HttpResponse)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)20 Path (javax.ws.rs.Path)18 SecurityGroup (org.olat.basesecurity.SecurityGroup)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)12 GET (javax.ws.rs.GET)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 HttpPost (org.apache.http.client.methods.HttpPost)10 OLATResourceable (org.olat.core.id.OLATResourceable)10 ContextEntry (org.olat.core.id.context.ContextEntry)10 LockResult (org.olat.core.util.coordinate.LockResult)10 CatalogManager (org.olat.repository.manager.CatalogManager)8 Link (org.olat.core.gui.components.link.Link)6