Search in sources :

Example 16 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

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 17 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method doMoveCategory.

private void doMoveCategory(UserRequest ureq, CatalogEntryRow row) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(entryResourceMoveCtrl);
    CatalogEntry moveMe = catalogManager.getCatalogEntryBy(row, catalogEntry);
    if (moveMe != null) {
        entryResourceMoveCtrl = new CatalogEntryMoveController(getWindowControl(), ureq, moveMe, getTranslator());
        listenTo(entryResourceMoveCtrl);
        cmc = new CloseableModalController(getWindowControl(), "close", entryResourceMoveCtrl.getInitialComponent(), true, translate("tools.move.catalog.entry"));
        listenTo(cmc);
        cmc.activate();
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) CatalogEntry(org.olat.repository.CatalogEntry)

Example 18 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method doAddResource.

private void doAddResource(UserRequest ureq, RepositoryEntry selectedEntry) {
    CatalogEntry newLinkNotPersistedYet = catalogManager.createCatalogEntry();
    newLinkNotPersistedYet.setName(selectedEntry.getDisplayname());
    newLinkNotPersistedYet.setDescription(selectedEntry.getDescription());
    newLinkNotPersistedYet.setRepositoryEntry(selectedEntry);
    newLinkNotPersistedYet.setType(CatalogEntry.TYPE_LEAF);
    newLinkNotPersistedYet.setOwnerGroup(securityManager.createAndPersistSecurityGroup());
    catalogManager.addCatalogEntry(catalogEntry, newLinkNotPersistedYet);
    loadResources(ureq);
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry)

Example 19 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty()) {
        return;
    }
    ContextEntry entry = entries.get(0);
    String type = entry.getOLATResourceable().getResourceableTypeName();
    if ("CatalogEntry".equalsIgnoreCase(type)) {
        Long entryKey = entry.getOLATResourceable().getResourceableId();
        if (entryKey != null && entryKey.longValue() > 0) {
            activateRoot(ureq, entryKey);
        }
    } else if ("Node".equalsIgnoreCase(type)) {
        // the "Node" is only for internal usage
        StateEntry stateEntry = entry.getTransientState();
        if (stateEntry instanceof CatalogStateEntry) {
            CatalogEntry catEntry = ((CatalogStateEntry) stateEntry).getEntry();
            CatalogNodeManagerController nextCtrl = selectCatalogEntry(ureq, catEntry);
            if (nextCtrl != null && entries.size() > 1) {
                nextCtrl.activate(ureq, entries.subList(1, entries.size()), null);
            }
        }
    }
}
Also used : StateEntry(org.olat.core.id.context.StateEntry) CatalogEntry(org.olat.repository.CatalogEntry) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 20 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method doAddCategory.

private void doAddCategory(UserRequest ureq) {
    removeAsListenerAndDispose(addEntryCtrl);
    removeAsListenerAndDispose(cmc);
    catModificationLock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockRes, getIdentity(), LOCK_TOKEN);
    if (catModificationLock.isSuccess()) {
        CatalogEntry ce = catalogManager.createCatalogEntry();
        addEntryCtrl = new CatalogEntryEditController(ureq, getWindowControl(), ce, catalogEntry);
        addEntryCtrl.setElementCssClass("o_sel_catalog_add_category_popup");
        listenTo(addEntryCtrl);
        cmc = new CloseableModalController(getWindowControl(), "close", addEntryCtrl.getInitialComponent(), true, translate("tools.add.catalog.category"));
        listenTo(cmc);
        cmc.activate();
    } else {
        String ownerName = userManager.getUserDisplayName(catModificationLock.getOwner());
        showError("catalog.locked.by", ownerName);
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) CatalogEntry(org.olat.repository.CatalogEntry)

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