Search in sources :

Example 51 with CatalogEntry

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

the class CatalogManager method deleteCatalogEntry.

public void deleteCatalogEntry(RepositoryEntryRef entry, CatalogEntry parent) {
    CatalogEntry ce = getCatalogEntryBy(entry, parent);
    if (ce != null) {
        SecurityGroup owner = ce.getOwnerGroup();
        dbInstance.getCurrentEntityManager().remove(ce);
        if (owner != null) {
            log.debug("deleteCatalogEntry case_1: delete owner-group=" + owner);
            securityManager.deleteSecurityGroup(owner);
        }
    }
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Example 52 with CatalogEntry

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

the class CatalogManager method saveCatEntry.

private CatalogEntry saveCatEntry(String name, String desc, int type, SecurityGroup ownerGroup, RepositoryEntry repoEntry, CatalogEntry parent) {
    CatalogEntry ce = createCatalogEntry();
    ce.setName(name);
    ce.setDescription(desc);
    ce.setOwnerGroup(ownerGroup);
    ce.setRepositoryEntry(repoEntry);
    ce.setParent(parent);
    ce.setType(type);
    saveCatalogEntry(ce);
    return ce;
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry)

Example 53 with CatalogEntry

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

the class CatalogManager method deleteUserData.

/**
 * Remove identity as owner of catalog-entry.
 * If there is no other owner, the olat-administrator (define in spring config) will be added as owner.
 *
 * @see org.olat.user.UserDataDeletable#deleteUserData(org.olat.core.id.Identity)
 */
@Override
public void deleteUserData(Identity identity, String newDeletedUserName, File archivePath) {
    // Remove as owner
    List<CatalogEntry> catalogEntries = getCatalogEntriesOwnedBy(identity);
    for (CatalogEntry catalogEntry : catalogEntries) {
        securityManager.removeIdentityFromSecurityGroup(identity, catalogEntry.getOwnerGroup());
        if (securityManager.countIdentitiesOfSecurityGroup(catalogEntry.getOwnerGroup()) == 0) {
            // This group has no owner anymore => add OLAT-Admin as owner
            Identity admin = CoreSpringFactory.getImpl(RepositoryDeletionModule.class).getAdminUserIdentity();
            securityManager.addIdentityToSecurityGroup(admin, catalogEntry.getOwnerGroup());
            log.info("Delete user-data, add Administrator-identity as owner of catalogEntry=" + catalogEntry.getName());
        }
    }
    if (log.isDebug())
        log.debug("All owner entries in catalog deleted for identity=" + identity);
}
Also used : RepositoryDeletionModule(org.olat.repository.RepositoryDeletionModule) CatalogEntry(org.olat.repository.CatalogEntry) Identity(org.olat.core.id.Identity)

Example 54 with CatalogEntry

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

the class CatalogSettingsController method doRemove.

private void doRemove(CatalogEntry catEntry) {
    List<CatalogEntry> children = catalogManager.getChildrenOf(catEntry);
    // find all child element of this level that reference our repo entry
    for (CatalogEntry child : children) {
        RepositoryEntry childRepoEntry = child.getRepositoryEntry();
        if (childRepoEntry != null && childRepoEntry.equalsByPersistableKey(entry)) {
            // remove from catalog
            catalogManager.deleteCatalogEntry(child);
        }
    }
    // update table
    updateTable();
}
Also used : CatalogEntry(org.olat.repository.CatalogEntry) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 55 with CatalogEntry

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

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)

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