Search in sources :

Example 66 with CatalogEntry

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

the class CatalogWebService method getOwners.

/**
 * Get the owners 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 httpRquest The HTTP request
 * @return The response
 */
@GET
@Path("{path:.*}/owners")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getOwners(@PathParam("path") List<PathSegment> path, @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();
    }
    SecurityGroup sg = ce.getOwnerGroup();
    if (sg == null) {
        return Response.ok(new UserVO[0]).build();
    }
    List<Identity> ids = BaseSecurityManager.getInstance().getIdentitiesOfSecurityGroup(sg);
    int count = 0;
    UserVO[] voes = new UserVO[ids.size()];
    for (Identity id : ids) {
        voes[count++] = UserVOFactory.get(id);
    }
    return Response.ok(voes).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) CatalogEntry(org.olat.repository.CatalogEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with CatalogEntry

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

the class CatalogWebService method deleteCatalogEntry.

/**
 * Deletes 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 httpRquest The HTTP request
 * @return The response
 */
@DELETE
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCatalogEntry(@PathParam("path") List<PathSegment> path, @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 (!canAdminSubTree(ce, 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 {
        catalogManager.deleteCatalogEntry(ce);
    } 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) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 68 with CatalogEntry

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

the class CatalogManagerController 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) {
            List<ContextEntry> parentLine = new ArrayList<>();
            for (CatalogEntry node = catalogManager.getCatalogEntryByKey(entryKey); node != null && node.getParent() != null; node = node.getParent()) {
                OLATResourceable nodeRes = OresHelper.createOLATResourceableInstance("Node", node.getKey());
                ContextEntry ctxEntry = BusinessControlFactory.getInstance().createContextEntry(nodeRes);
                ctxEntry.setTransientState(new CatalogStateEntry(node));
                parentLine.add(ctxEntry);
            }
            Collections.reverse(parentLine);
            toolbarPanel.popUpToRootController(ureq);
            catalogCtrl.activate(ureq, parentLine, null);
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) CatalogEntry(org.olat.repository.CatalogEntry) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 69 with CatalogEntry

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

the class CatalogNodeManagerController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // one mapper for all users
    flc.contextPut("mapperThumbnailUrl", mapperThumbnailKey.getUrl());
    int level = 0;
    CatalogEntry parent = catalogEntry.getParent();
    while (parent != null) {
        level++;
        parent = parent.getParent();
    }
    flc.contextPut("catalogLevel", level);
    String url = Settings.getServerContextPathURI() + "/url/CatalogEntry/" + catalogEntry.getKey();
    if (loginModule.isGuestLoginLinksEnabled()) {
        flc.contextPut("guestExtLink", url + "?guest=true&amp;lang=" + getLocale().getLanguage());
    }
    if (!isGuest) {
        flc.contextPut("extLink", url);
    }
    FlexiTableColumnModel entriesColumnsModel = getCatalogFlexiTableColumnModel("opened-");
    entriesModel = new CatalogEntryRowModel(entriesColumnsModel);
    entriesEl = uifactory.addTableElement(getWindowControl(), "entries", entriesModel, getTranslator(), formLayout);
    FlexiTableColumnModel closedEntriesColumnsModel = getCatalogFlexiTableColumnModel("closed-");
    closedEntriesModel = new CatalogEntryRowModel(closedEntriesColumnsModel);
    closedEntriesEl = uifactory.addTableElement(getWindowControl(), "closedEntries", closedEntriesModel, getTranslator(), formLayout);
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)

Example 70 with CatalogEntry

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

the class CatalogNodeManagerController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (editLink == source) {
        doEditCategory(ureq);
    } else if (nominateLink == source) {
        doEditOwners(ureq);
    } else if (contactLink == source) {
        doContact(ureq);
    } else if (deleteLink == source) {
        doConfirmDelete(ureq);
    } else if (moveLink == source) {
        doMoveCategory(ureq);
    } else if (addCategoryLink == source) {
        doAddCategory(ureq);
    } else if (addResourceLink == source) {
        doAddResource(ureq);
    } else if (source instanceof Link) {
        Link link = (Link) source;
        if ("select_node".equals(link.getCommand())) {
            Long categoryNodeKey = (Long) link.getUserObject();
            CatalogEntry entry = catalogManager.getCatalogNodeByKey(categoryNodeKey);
            selectCatalogEntry(ureq, entry);
        }
    } else if ("img_select".equals(event.getCommand())) {
        String node = ureq.getParameter("node");
        if (StringHelper.isLong(node)) {
            try {
                Long categoryNodeKey = new Long(node);
                CatalogEntry entry = catalogManager.getCatalogNodeByKey(categoryNodeKey);
                selectCatalogEntry(ureq, entry);
            } catch (NumberFormatException e) {
                logWarn("Not a valid long: " + node, e);
            }
        }
    }
    super.event(ureq, source, event);
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) Link(org.olat.core.gui.components.link.Link)

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