Search in sources :

Example 1 with ErrorList

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

the class RepositoryServiceImpl method deletePermanently.

@Override
public ErrorList deletePermanently(RepositoryEntry entry, Identity identity, Roles roles, Locale locale) {
    ErrorList errors = new ErrorList();
    boolean debug = log.isDebug();
    // invoke handler delete callback
    if (debug)
        log.debug("deleteRepositoryEntry start entry=" + entry);
    entry = (RepositoryEntry) dbInstance.loadObject(entry, true);
    if (debug)
        log.debug("deleteRepositoryEntry after load entry=" + entry);
    RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(entry);
    OLATResource resource = entry.getOlatResource();
    // delete old context
    if (!handler.readyToDelete(entry, identity, roles, locale, errors)) {
        return errors;
    }
    userCourseInformationsManager.deleteUserCourseInformations(entry);
    certificatesManager.deleteRepositoryEntry(entry);
    // delete all bookmarks referencing deleted entry
    CoreSpringFactory.getImpl(MarkManager.class).deleteMarks(entry);
    // delete all catalog entries referencing deleted entry
    catalogManager.resourceableDeleted(entry);
    // delete assessment modes
    assessmentModeDao.delete(entry);
    // delete reminders
    reminderDao.delete(entry);
    // delete all policies
    securityManager.deletePolicies(resource);
    // delete reservations
    reservationDao.deleteReservations(resource);
    // delete references
    referenceManager.deleteAllReferencesOf(resource);
    // delete all pending tasks
    persistentTaskDao.delete(resource);
    dbInstance.commit();
    // delete lectures
    CoreSpringFactory.getImpl(LectureService.class).delete(entry);
    dbInstance.commit();
    // delete license
    CoreSpringFactory.getImpl(LicenseService.class).delete(resource);
    dbInstance.commit();
    // detach portfolio if there are some lost
    CoreSpringFactory.getImpl(PortfolioService.class).detachCourseFromBinders(entry);
    dbInstance.commit();
    // inform handler to do any cleanup work... handler must delete the
    // referenced resourceable a swell.
    handler.cleanupOnDelete(entry, resource);
    dbInstance.commit();
    // delete all test sessions
    assessmentTestSessionDao.deleteAllUserTestSessionsByCourse(entry);
    // nullify the reference
    assessmentEntryDao.removeEntryForReferenceEntry(entry);
    assessmentEntryDao.deleteEntryForRepositoryEntry(entry);
    dbInstance.commit();
    if (debug)
        log.debug("deleteRepositoryEntry after reload entry=" + entry);
    deleteRepositoryEntryAndBaseGroups(entry);
    if (debug)
        log.debug("deleteRepositoryEntry Done");
    return errors;
}
Also used : ErrorList(org.olat.repository.ErrorList) PortfolioService(org.olat.modules.portfolio.PortfolioService) MarkManager(org.olat.core.commons.services.mark.MarkManager) LicenseService(org.olat.core.commons.services.license.LicenseService) OLATResource(org.olat.resource.OLATResource) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) LectureService(org.olat.modules.lecture.LectureService)

Example 2 with ErrorList

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

the class ConfirmDeletePermanentlyController method deleteEntries.

private boolean deleteEntries(UserRequest ureq, List<RepositoryEntry> entries, List<ErrorList> errorList) {
    boolean allOk = true;
    Roles roles = ureq.getUserSession().getRoles();
    for (RepositoryEntry entry : entries) {
        RepositoryEntry reloadedEntry = repositoryService.loadByKey(entry.getKey());
        if (reloadedEntry != null) {
            ErrorList errors = repositoryService.deletePermanently(reloadedEntry, getIdentity(), roles, getLocale());
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(reloadedEntry, OlatResourceableType.genRepoEntry));
            if (errors.hasErrors()) {
                allOk = false;
                errorList.add(errors);
            } else {
                EntryChangedEvent e = new EntryChangedEvent(reloadedEntry, getIdentity(), Change.deleted, "delete");
                ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, RepositoryService.REPOSITORY_EVENT_ORES);
            }
        }
    }
    return allOk;
}
Also used : ErrorList(org.olat.repository.ErrorList) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 3 with ErrorList

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

the class CourseWebService method deleteCourse.

/**
 * Delete a course by id.
 *
 * @response.representation.200.doc The metadatas of the deleted course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param request The HTTP request
 * @return It returns the XML representation of the <code>Structure</code>
 *         object representing the course.
 */
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!isAuthorEditor(course, request) && !isInstitutionalResourceManager(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    UserRequest ureq = getUserRequest(request);
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
    if (errors.hasErrors()) {
        return Response.serverError().status(500).build();
    }
    ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    return Response.ok().build();
}
Also used : ErrorList(org.olat.repository.ErrorList) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 4 with ErrorList

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

the class RepositoryEntryResource method deleteCourse.

/**
 * Delete a resource by id
 *
 * @response.representation.200.doc The metadatas of the deleted resource
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param courseId The course resourceable's id
 * @param request The HTTP request
 * @return It returns the XML representation of the <code>Structure</code>
 *         object representing the course.
 */
@DELETE
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteCourse(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!isAuthorEditor(re, request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    UserRequest ureq = getUserRequest(request);
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    ErrorList errors = rs.deletePermanently(re, ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale());
    if (errors.hasErrors()) {
        return Response.serverError().status(500).build();
    }
    ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.LEARNING_RESOURCE_DELETE, getClass(), LoggingResourceable.wrap(re, OlatResourceableType.genRepoEntry));
    return Response.ok().build();
}
Also used : ErrorList(org.olat.repository.ErrorList) RepositoryEntry(org.olat.repository.RepositoryEntry) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 5 with ErrorList

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

the class ConfirmDeletePermanentlyController method doCompleteDelete.

private void doCompleteDelete(UserRequest ureq) {
    List<ErrorList> errorList = new ArrayList<>();
    boolean allOk = deleteEntries(ureq, rows, errorList);
    if (allOk && deleteReferencesEl.isVisible() && deleteReferencesEl.isEnabled() && deleteReferencesEl.isOneSelected() && deleteReferencesEl.isSelected(0)) {
        Map<Long, ReferenceInfos> referencesMap = new HashMap<>();
        for (ReferenceInfos reference : references) {
            referencesMap.put(reference.getEntry().getKey(), reference);
        }
        Collection<String> selectedKeys = referencesEl.getSelectedKeys();
        List<RepositoryEntry> referencesToDelete = new ArrayList<>(selectedKeys.size());
        for (String selectedRefKey : selectedKeys) {
            Long key = new Long(selectedRefKey);
            ReferenceInfos refInfos = referencesMap.get(key);
            if (refInfos != null && refInfos.isOrphan() && refInfos.isOwner() && !refInfos.isManaged()) {
                referencesToDelete.add(referencesMap.get(key).getEntry());
            }
        }
        allOk &= deleteEntries(ureq, referencesToDelete, errorList);
    }
    if (allOk) {
        showInfo("info.entry.deleted");
    } else {
        List<String> msgs = new ArrayList<>();
        for (ErrorList error : errorList) {
            if (StringHelper.containsNonWhitespace(error.getFirstError())) {
                msgs.add(error.getFirstError());
            }
        }
        if (msgs.size() == 1) {
            getWindowControl().setWarning(msgs.get(0));
        } else if (msgs.size() > 1) {
            StringBuilder sb = new StringBuilder();
            sb.append("<ul>");
            for (String msg : msgs) {
                sb.append("<li>").append(msg).append("</li>");
            }
            sb.append("</ul>");
            getWindowControl().setWarning(sb.toString());
        } else {
            showWarning("info.could.not.delete.entry");
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) ErrorList(org.olat.repository.ErrorList) ReferenceInfos(org.olat.resource.references.ReferenceInfos)

Aggregations

ErrorList (org.olat.repository.ErrorList)12 RepositoryEntry (org.olat.repository.RepositoryEntry)10 DELETE (javax.ws.rs.DELETE)4 Produces (javax.ws.rs.Produces)4 UserRequest (org.olat.core.gui.UserRequest)4 Roles (org.olat.core.id.Roles)4 RepositoryService (org.olat.repository.RepositoryService)4 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 LicenseService (org.olat.core.commons.services.license.LicenseService)2 MarkManager (org.olat.core.commons.services.mark.MarkManager)2 Identity (org.olat.core.id.Identity)2 LectureService (org.olat.modules.lecture.LectureService)2 PortfolioService (org.olat.modules.portfolio.PortfolioService)2 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)2 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)2 OLATResource (org.olat.resource.OLATResource)2