Search in sources :

Example 6 with ErrorList

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

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 7 with ErrorList

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

the class RepositoryServiceImplTest method deleteCoursePermanently.

@Test
public void deleteCoursePermanently() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();
    Roles roles = new Roles(false, false, false, true, false, false, false);
    ErrorList errors = repositoryService.deletePermanently(re, initialAuthor, roles, Locale.ENGLISH);
    Assert.assertNotNull(errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : ErrorList(org.olat.repository.ErrorList) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 8 with ErrorList

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

the class RepositoryServiceImplTest method deleteCoursePermanently.

@Test
public void deleteCoursePermanently() {
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("auth-del-1");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(initialAuthor);
    dbInstance.commitAndCloseSession();
    Roles roles = new Roles(false, false, false, true, false, false, false);
    ErrorList errors = repositoryService.deletePermanently(re, initialAuthor, roles, Locale.ENGLISH);
    Assert.assertNotNull(errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : ErrorList(org.olat.repository.ErrorList) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 9 with ErrorList

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

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 10 with ErrorList

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

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