Search in sources :

Example 16 with CorruptedCourseException

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

the class QTIEditorMainController method createReferenceesMsg.

/**
 * helper method to create the message about qti resource stakeholders and
 * from where the qti resource is referenced.
 *
 * @return
 */
private String createReferenceesMsg(UserRequest ureq) {
    /*
		 * problems: A tries to reference this test, after test editor has been
		 * started
		 */
    changeEmail = new ContactMessage(ureq.getIdentity());
    // the owners of this qtiPkg
    RepositoryEntry myEntry = repositoryManager.lookupRepositoryEntry(qtiPackage.getRepresentingResourceable(), false);
    // add qti resource owners as group
    ContactList cl = new ContactList("qtiPkgOwners");
    cl.addAllIdentites(repositoryService.getMembers(myEntry, GroupRoles.owner.name()));
    changeEmail.addEmailTo(cl);
    StringBuilder result = new StringBuilder();
    result.append(translate("qti.restricted.leading"));
    for (Iterator<Reference> iter = referencees.iterator(); iter.hasNext(); ) {
        Reference element = iter.next();
        if ("CourseModule".equals(element.getSource().getResourceableTypeName())) {
            ICourse course = null;
            try {
                course = CourseFactory.loadCourse(element.getSource().getResourceableId());
                if (course == null) {
                    continue;
                }
            } catch (CorruptedCourseException ex) {
                logError("", ex);
                continue;
            }
            CourseNode cn = course.getEditorTreeModel().getCourseNode(element.getUserdata());
            if (cn == null) {
                logError("Cannot find course element " + element.getUserdata() + " in course " + course, null);
                continue;
            }
            String courseTitle = course.getCourseTitle();
            StringBuilder stakeHolders = new StringBuilder();
            // the course owners
            RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course, false);
            if (entry != null) {
                // OO-1300
                List<Identity> stakeHoldersIds = repositoryService.getMembers(entry, GroupRoles.owner.name());
                if (stakeHoldersIds != null && stakeHoldersIds.size() > 0) {
                    // add stakeholders as group
                    cl = new ContactList(courseTitle);
                    cl.addAllIdentites(stakeHoldersIds);
                    changeEmail.addEmailTo(cl);
                    for (Identity stakeHoldersId : stakeHoldersIds) {
                        if (stakeHolders.length() > 0)
                            stakeHolders.append(", ");
                        User user = stakeHoldersId.getUser();
                        stakeHolders.append(user.getProperty(UserConstants.FIRSTNAME, getLocale())).append(" ").append(user.getProperty(UserConstants.LASTNAME, getLocale()));
                    }
                }
            }
            String courseNodeTitle = cn.getShortTitle();
            result.append(translate("qti.restricted.course", StringHelper.escapeHtml(courseTitle)));
            result.append(translate("qti.restricted.node", StringHelper.escapeHtml(courseNodeTitle)));
            result.append(translate("qti.restricted.owners", stakeHolders.toString()));
        }
    }
    return result.toString();
}
Also used : User(org.olat.core.id.User) Reference(org.olat.resource.references.Reference) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) ContactList(org.olat.core.util.mail.ContactList) ContactMessage(org.olat.core.util.mail.ContactMessage) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 17 with CorruptedCourseException

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

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)

Example 18 with CorruptedCourseException

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

the class EfficiencyStatementManagerTest method testBigDatas.

@Test
public void testBigDatas() {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(new Roles(true, false, false, false, false, false, false));
    params.setResourceTypes(Collections.singletonList("CourseModule"));
    List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 10000);
    int count = 0;
    for (RepositoryEntry entry : entries) {
        Long resourceableId = entry.getOlatResource().getResourceableId();
        try {
            ICourse course = CourseFactory.loadCourse(resourceableId);
            boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
            if (!enabled) {
                course = CourseFactory.openCourseEditSession(entry.getOlatResource().getResourceableId());
                CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
                courseConfig.setEfficencyStatementIsEnabled(true);
                CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
                CourseFactory.saveCourse(course.getResourceableId());
                CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            }
            DBFactory.getInstance().commitAndCloseSession();
            try {
                int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
                if (fromIndex < 100) {
                    fromIndex = 100;
                }
                List<Identity> assessedIdentities = loadIdentities.subList(fromIndex - 100, fromIndex);
                // force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
                RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                efficiencyStatementManager.updateEfficiencyStatements(courseEntry, assessedIdentities);
            } catch (Exception e) {
                e.printStackTrace();
            }
            DBFactory.getInstance().commitAndCloseSession();
            DBFactory.getInstance().closeSession();
        } catch (CorruptedCourseException e) {
            System.out.println("Error");
        }
        if (count++ % 100 == 0) {
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseConfig(org.olat.course.config.CourseConfig) CorruptedCourseException(org.olat.course.CorruptedCourseException) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 19 with CorruptedCourseException

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

the class AuthorListController method doOverrideCloseResource.

private void doOverrideCloseResource(UserRequest ureq, AuthoringEntryRow row) {
    try {
        RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(row.getResourceType());
        if (handler != null) {
            String businessPath = "[RepositoryEntry:" + row.getKey() + "]";
            ureq.getUserSession().putEntry("override_readonly_" + row.getKey(), Boolean.TRUE);
            if (!NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl())) {
                tableEl.reloadData();
            }
        }
    } catch (CorruptedCourseException e) {
        logError("Course corrupted: " + row.getKey() + " (" + row.getOLATResourceable().getResourceableId() + ")", e);
        showError("cif.error.corrupted");
    }
}
Also used : CorruptedCourseException(org.olat.course.CorruptedCourseException) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) OrderedRepositoryHandler(org.olat.repository.handlers.RepositoryHandlerFactory.OrderedRepositoryHandler)

Example 20 with CorruptedCourseException

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

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