Search in sources :

Example 26 with CorruptedCourseException

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

the class HomeCalendarManager method appendCourseCalendars.

private void appendCourseCalendars(UserRequest ureq, WindowControl wControl, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        // add course calendars
        List<Object[]> resources = getCourses(ureq.getIdentity());
        Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());
        Set<Long> duplicates = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (duplicates.contains(courseEntry.getKey())) {
                continue;
            }
            duplicates.add(courseEntry.getKey());
            String role = (String) resource[1];
            Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
            try {
                ICourse course = CourseFactory.loadCourse(courseEntry);
                if (isCourseCalendarEnabled(course)) {
                    // calendar course aren't enabled per default but course node of type calendar are always possible
                    // REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue;
                    // add course calendar
                    KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
                    boolean isPrivileged = GroupRoles.owner.name().equals(role) || editoredResources.contains(courseEntry.getOlatResource());
                    if (isPrivileged) {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
                    } else {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                    }
                    if (role != null && (GroupRoles.owner.name().equals(role) || GroupRoles.coach.name().equals(role) || GroupRoles.participant.name().equals(role))) {
                        courseCalendarWrapper.setPrivateEventsVisible(true);
                    }
                    CalendarUserConfiguration config = configMap.get(courseCalendarWrapper.getCalendarKey());
                    if (config != null) {
                        courseCalendarWrapper.setConfiguration(config);
                    }
                    courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl));
                    calendars.add(courseCalendarWrapper);
                }
            } catch (CorruptedCourseException e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Corrupted course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            } catch (Exception e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Cannor read calendar of course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            }
        }
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException) CorruptedCourseException(org.olat.course.CorruptedCourseException) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) HashSet(java.util.HashSet)

Example 27 with CorruptedCourseException

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

the class CourseIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext parentResourceContext, Object parentObject, OlatFullIndexer indexWriter) {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    if (isLogDebugEnabled())
        logDebug("Analyse Course... repositoryEntry=" + repositoryEntry);
    try {
        RepositoryEntryStatus status = RepositoryManager.getInstance().createRepositoryEntryStatus(repositoryEntry.getStatusCode());
        if (status.isClosed()) {
            if (isLogDebugEnabled())
                logDebug("Course not indexed because it's closed: repositoryEntry=" + repositoryEntry);
            return;
        }
        ICourse course = CourseFactory.loadCourse(repositoryEntry);
        // course.getCourseTitle(); // do not index title => index root-node
        parentResourceContext.setParentContextType(TYPE);
        parentResourceContext.setParentContextName(course.getCourseTitle());
        doIndexCourse(parentResourceContext, course, course.getRunStructure().getRootNode(), indexWriter);
    } catch (CorruptedCourseException ex) {
        logWarn("Can not index repositoryEntry (" + repositoryEntry.getKey() + ")", ex);
    } catch (Exception ex) {
        logWarn("Can not index repositoryEntry=" + repositoryEntry, ex);
    }
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) RepositoryEntryStatus(org.olat.repository.RepositoryEntryStatus) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssertException(org.olat.core.logging.AssertException) CorruptedCourseException(org.olat.course.CorruptedCourseException) StartupException(org.olat.core.logging.StartupException) IOException(java.io.IOException)

Example 28 with CorruptedCourseException

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

the class OLATUpgrade_11_2_1 method processCourse.

private boolean processCourse(RepositoryEntry entry) {
    try {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode rootNode = course.getRunStructure().getRootNode();
        final List<TACourseNode> taskNodes = new ArrayList<>();
        new TreeVisitor(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof TACourseNode) {
                    taskNodes.add((TACourseNode) node);
                }
            }
        }, rootNode, false).visitAll();
        for (TACourseNode taskNode : taskNodes) {
            processTaskCourseNode(course, entry, taskNode);
        }
        return true;
    } catch (CorruptedCourseException e) {
        log.warn("Corrupted course: " + entry.getDisplayname() + " (" + entry.getKey() + ")", e);
        return true;
    } catch (Exception e) {
        log.error("", e);
        return true;
    }
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CorruptedCourseException(org.olat.course.CorruptedCourseException) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) CorruptedCourseException(org.olat.course.CorruptedCourseException)

Example 29 with CorruptedCourseException

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

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 30 with CorruptedCourseException

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

the class OLATUpgrade_12_0_0 method processCourseAssessmentLastModified.

private boolean processCourseAssessmentLastModified(RepositoryEntry entry) {
    try {
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode rootNode = course.getRunStructure().getRootNode();
        Set<Identity> changeSet = new HashSet<>();
        processCourseNodeAssessmentLastModified(course, entry, rootNode, changeSet);
        dbInstance.commitAndCloseSession();
        // update structure nodes and efficiency statement if any
        Set<Identity> identitiesWithEfficiencyStatements = findIdentitiesWithEfficiencyStatements(entry);
        for (Identity assessedIdentity : changeSet) {
            UserCourseEnvironment userCourseEnv = AssessmentHelper.createInitAndUpdateUserCourseEnvironment(assessedIdentity, course);
            if (identitiesWithEfficiencyStatements.contains(assessedIdentity)) {
                efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
            }
            dbInstance.commitAndCloseSession();
        }
    } catch (CorruptedCourseException e) {
        log.error("Corrupted course: " + entry.getKey(), e);
    } catch (Exception e) {
        log.error("Unexpected error", e);
    } finally {
        dbInstance.commitAndCloseSession();
    }
    return true;
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) Identity(org.olat.core.id.Identity) CorruptedCourseException(org.olat.course.CorruptedCourseException) HashSet(java.util.HashSet)

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