Search in sources :

Example 6 with CorruptedCourseException

use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_12_0_0 method upgradeLastModified.

private boolean upgradeLastModified(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    boolean allOk = true;
    if (!uhd.getBooleanDataValue(LAST_USER_MODIFICATION)) {
        int counter = 0;
        final Roles roles = new Roles(true, true, true, true, false, true, false);
        final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
        params.setRoles(roles);
        params.setResourceTypes(Collections.singletonList("CourseModule"));
        List<RepositoryEntry> courses;
        do {
            courses = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, 50, true);
            for (RepositoryEntry course : courses) {
                try {
                    allOk &= processCourseAssessmentLastModified(course);
                } catch (CorruptedCourseException e) {
                    log.error("Corrupted course: " + course.getKey(), e);
                }
            }
            counter += courses.size();
            log.audit("Last modifications migration processed: " + courses.size() + ", total courses processed (" + counter + ")");
            dbInstance.commitAndCloseSession();
        } while (courses.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(LAST_USER_MODIFICATION, allOk);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return allOk;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CorruptedCourseException(org.olat.course.CorruptedCourseException) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 7 with CorruptedCourseException

use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.

the class CertificateAndEfficiencyStatementListController method doLaunchCourse.

private void doLaunchCourse(UserRequest ureq, Long resourceKey) {
    RepositoryEntry entry = repositoryService.loadByResourceKey(resourceKey);
    if (entry == null) {
        showWarning("efficiencyStatements.course.noexists");
    } else if (!repositoryManager.isAllowedToLaunch(ureq, entry)) {
        showWarning("efficiencyStatements.course.noaccess");
    } else {
        try {
            String businessPath = "[RepositoryEntry:" + entry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        } catch (CorruptedCourseException e) {
            logError("Course corrupted: " + entry.getKey() + " (" + entry.getResourceableId() + ")", e);
            showError("cif.error.corrupted");
        }
    }
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 8 with CorruptedCourseException

use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.

the class CertificatesManagerImpl method isCertificationAllowed.

@Override
public boolean isCertificationAllowed(Identity identity, RepositoryEntry entry) {
    boolean allowed = false;
    try {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseConfig config = course.getCourseEnvironment().getCourseConfig();
        if (config.isRecertificationEnabled()) {
            Certificate certificate = getLastCertificate(identity, entry.getOlatResource().getKey());
            if (certificate == null) {
                allowed = true;
            } else {
                Calendar cal = Calendar.getInstance();
                Date now = cal.getTime();
                Date nextCertificationDate = getDateNextRecertification(certificate, config);
                allowed = (nextCertificationDate != null ? nextCertificationDate.before(now) : false);
            }
        } else {
            allowed = !hasCertificate(identity, entry.getOlatResource().getKey());
        }
    } catch (CorruptedCourseException e) {
        log.error("", e);
    }
    return allowed;
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) Calendar(java.util.Calendar) ICourse(org.olat.course.ICourse) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Certificate(org.olat.course.certificate.Certificate)

Example 9 with CorruptedCourseException

use of org.olat.course.CorruptedCourseException in project OpenOLAT by OpenOLAT.

the class AssessmentModeListModel method getValueAt.

@Override
public Object getValueAt(AssessmentMode mode, int col) {
    switch(Cols.values()[col]) {
        case status:
            {
                List<String> warnings = null;
                Status status = mode.getStatus();
                try {
                    if (StringHelper.containsNonWhitespace(mode.getStartElement())) {
                        ICourse course = CourseFactory.loadCourse(mode.getRepositoryEntry());
                        CourseNode node = course.getRunStructure().getNode(mode.getStartElement());
                        if (node == null) {
                            warnings = new ArrayList<>(2);
                            warnings.add(translator.translate("warning.missing.start.element"));
                        }
                    }
                    if (StringHelper.containsNonWhitespace(mode.getElementList())) {
                        ICourse course = CourseFactory.loadCourse(mode.getRepositoryEntry());
                        String elements = mode.getElementList();
                        for (String element : elements.split(",")) {
                            CourseNode node = course.getRunStructure().getNode(element);
                            if (node == null) {
                                if (warnings == null) {
                                    warnings = new ArrayList<>(2);
                                }
                                warnings.add(translator.translate("warning.missing.element"));
                                break;
                            }
                        }
                    }
                } catch (CorruptedCourseException e) {
                    log.error("", e);
                    if (warnings == null) {
                        warnings = new ArrayList<>(2);
                    }
                    warnings.add(translator.translate("cif.error.corrupted"));
                }
                return new EnhancedStatus(status, warnings);
            }
        case course:
            return mode.getRepositoryEntry().getDisplayname();
        case externalId:
            return mode.getRepositoryEntry().getExternalId();
        case externalRef:
            return mode.getRepositoryEntry().getExternalRef();
        case name:
            return mode.getName();
        case begin:
            return mode.getBegin();
        case end:
            return mode.getEnd();
        case leadTime:
            return mode.getLeadTime();
        case followupTime:
            return mode.getFollowupTime();
        case target:
            return mode.getTargetAudience();
        case start:
            {
                boolean canStart = mode.isManualBeginEnd();
                if (canStart) {
                    canStart = coordinationService.canStart(mode);
                }
                return canStart;
            }
        case stop:
            {
                boolean canStop = mode.isManualBeginEnd();
                if (canStop) {
                    canStop = coordinationService.canStop(mode);
                }
                return canStop;
            }
    }
    return null;
}
Also used : EnhancedStatus(org.olat.course.assessment.model.EnhancedStatus) Status(org.olat.course.assessment.AssessmentMode.Status) CorruptedCourseException(org.olat.course.CorruptedCourseException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) EnhancedStatus(org.olat.course.assessment.model.EnhancedStatus)

Example 10 with CorruptedCourseException

use of org.olat.course.CorruptedCourseException in project openolat by klemens.

the class CourseHandler method readyToDelete.

@Override
public boolean readyToDelete(RepositoryEntry entry, Identity identity, Roles roles, Locale locale, ErrorList errors) {
    ReferenceManager refM = CoreSpringFactory.getImpl(ReferenceManager.class);
    String referencesSummary = refM.getReferencesToSummary(entry.getOlatResource(), locale);
    if (referencesSummary != null) {
        Translator translator = Util.createPackageTranslator(RepositoryManager.class, locale);
        errors.setError(translator.translate("details.delete.error.references", new String[] { referencesSummary, entry.getDisplayname() }));
        return false;
    }
    /*
		 * make an archive of the course nodes with valuable data
		 */
    UserManager um = UserManager.getInstance();
    String charset = um.getUserCharset(identity);
    try {
        CourseFactory.archiveCourse(entry.getOlatResource(), charset, locale, identity, roles);
    } catch (CorruptedCourseException e) {
        log.error("The course is corrupted, cannot archive it: " + entry, e);
    }
    return true;
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) ReferenceManager(org.olat.resource.references.ReferenceManager)

Aggregations

CorruptedCourseException (org.olat.course.CorruptedCourseException)38 ICourse (org.olat.course.ICourse)24 RepositoryEntry (org.olat.repository.RepositoryEntry)22 Roles (org.olat.core.id.Roles)10 CourseNode (org.olat.course.nodes.CourseNode)10 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)10 Identity (org.olat.core.id.Identity)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 GroupRoles (org.olat.basesecurity.GroupRoles)4 CourseConfig (org.olat.course.config.CourseConfig)4 RepositoryHandler (org.olat.repository.handlers.RepositoryHandler)4 OLATResource (org.olat.resource.OLATResource)4 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 List (java.util.List)2 Test (org.junit.Test)2 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)2 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)2