Search in sources :

Example 46 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class NodeExportVisitor method exportToFilesystem.

/**
 * @see org.olat.course.ICourse#exportToFilesystem(java.io.File)
 * <p>
 * See OLAT-5368: Course Export can take longer than say 2min.
 * <p>
 */
@Override
public void exportToFilesystem(OLATResource originalCourseResource, File exportDirectory, boolean runtimeDatas, boolean backwardsCompatible) {
    long s = System.currentTimeMillis();
    log.info("exportToFilesystem: exporting course " + this + " to " + exportDirectory + "...");
    File fCourseBase = getCourseBaseContainer().getBasefile();
    // make the folder structure
    File fExportedDataDir = new File(exportDirectory, EXPORTED_DATA_FOLDERNAME);
    fExportedDataDir.mkdirs();
    // export course config
    FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export courseconfig");
    // export business groups
    CourseEnvironmentMapper envMapper = getCourseEnvironment().getCourseGroupManager().getBusinessGroupEnvironment();
    if (backwardsCompatible) {
        // prevents duplicate names
        envMapper.avoidDuplicateNames();
    }
    getCourseEnvironment().getCourseGroupManager().exportCourseBusinessGroups(fExportedDataDir, envMapper, runtimeDatas, backwardsCompatible);
    if (backwardsCompatible) {
        XStream xstream = CourseXStreamAliases.getReadCourseXStream();
        Structure exportedStructure = (Structure) XStreamHelper.readObject(xstream, new File(fCourseBase, RUNSTRUCTURE_XML));
        visit(new NodePostExportVisitor(envMapper, backwardsCompatible), exportedStructure.getRootNode());
        XStreamHelper.writeObject(xstream, new File(exportDirectory, RUNSTRUCTURE_XML), exportedStructure);
        CourseEditorTreeModel exportedEditorModel = (CourseEditorTreeModel) XStreamHelper.readObject(xstream, new File(fCourseBase, EDITORTREEMODEL_XML));
        visit(new NodePostExportVisitor(envMapper, backwardsCompatible), exportedEditorModel.getRootNode());
        XStreamHelper.writeObject(xstream, new File(exportDirectory, EDITORTREEMODEL_XML), exportedEditorModel);
    } else {
        // export editor structure
        FileUtils.copyFileToDir(new File(fCourseBase, EDITORTREEMODEL_XML), exportDirectory, "course export exitortreemodel");
        // export run structure
        FileUtils.copyFileToDir(new File(fCourseBase, RUNSTRUCTURE_XML), exportDirectory, "course export runstructure");
    }
    // export layout and media folder
    FileUtils.copyDirToDir(new File(fCourseBase, "layout"), exportDirectory, "course export layout folder");
    FileUtils.copyDirToDir(new File(fCourseBase, "media"), exportDirectory, "course export media folder");
    // export course folder
    FileUtils.copyDirToDir(getIsolatedCourseBaseFolder(), exportDirectory, "course export folder");
    // export any node data
    log.info("exportToFilesystem: exporting course " + this + ": exporting all nodes...");
    Visitor visitor = new NodeExportVisitor(fExportedDataDir, this);
    TreeVisitor tv = new TreeVisitor(visitor, getEditorTreeModel().getRootNode(), true);
    tv.visitAll();
    log.info("exportToFilesystem: exporting course " + this + ": exporting all nodes...done.");
    // OLAT-5368: do intermediate commit to avoid transaction timeout
    // discussion intermediatecommit vs increased transaction timeout:
    // pro intermediatecommit: not much
    // pro increased transaction timeout: would fix OLAT-5368 but only move the problem
    // @TODO OLAT-2597: real solution is a long-running background-task concept...
    DBFactory.getInstance().intermediateCommit();
    // export shared folder
    CourseConfig config = getCourseConfig();
    if (config.hasCustomSharedFolder()) {
        log.info("exportToFilesystem: exporting course " + this + ": shared folder...");
        if (!SharedFolderManager.getInstance().exportSharedFolder(config.getSharedFolderSoftkey(), fExportedDataDir)) {
            // export failed, delete reference to shared folder in the course config
            log.info("exportToFilesystem: exporting course " + this + ": export of shared folder failed.");
            config.setSharedFolderSoftkey(CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY);
            CourseConfigManagerImpl.getInstance().saveConfigTo(this, config);
        }
        log.info("exportToFilesystem: exporting course " + this + ": shared folder...done.");
    }
    // OLAT-5368: do intermediate commit to avoid transaction timeout
    // discussion intermediatecommit vs increased transaction timeout:
    // pro intermediatecommit: not much
    // pro increased transaction timeout: would fix OLAT-5368 but only move the problem
    // @TODO OLAT-2597: real solution is a long-running background-task concept...
    DBFactory.getInstance().intermediateCommit();
    // export glossary
    if (config.hasGlossary()) {
        log.info("exportToFilesystem: exporting course " + this + ": glossary...");
        if (!GlossaryManager.getInstance().exportGlossary(config.getGlossarySoftKey(), fExportedDataDir)) {
            // export failed, delete reference to glossary in the course config
            log.info("exportToFilesystem: exporting course " + this + ": export of glossary failed.");
            config.setGlossarySoftKey(null);
            CourseConfigManagerImpl.getInstance().saveConfigTo(this, config);
        }
        log.info("exportToFilesystem: exporting course " + this + ": glossary...done.");
    }
    // OLAT-5368: do intermediate commit to avoid transaction timeout
    // discussion intermediatecommit vs increased transaction timeout:
    // pro intermediatecommit: not much
    // pro increased transaction timeout: would fix OLAT-5368 but only move the problem
    // @TODO OLAT-2597: real solution is a long-running background-task concept...
    DBFactory.getInstance().intermediateCommit();
    log.info("exportToFilesystem: exporting course " + this + ": configuration and repo data...");
    // export configuration file
    FileUtils.copyFileToDir(new File(fCourseBase, CourseConfigManager.COURSECONFIG_XML), exportDirectory, "course export configuration and repo info");
    // export repo metadata
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry myRE = rm.lookupRepositoryEntry(this, true);
    RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(myRE, fExportedDataDir);
    importExport.exportDoExportProperties();
    // OLAT-5368: do intermediate commit to avoid transaction timeout
    // discussion intermediatecommit vs increased transaction timeout:
    // pro intermediatecommit: not much
    // pro increased transaction timeout: would fix OLAT-5368 but only move the problem
    // @TODO OLAT-2597: real solution is a long-running background-task concept...
    DBFactory.getInstance().intermediateCommit();
    // export reminders
    CoreSpringFactory.getImpl(ReminderService.class).exportReminders(myRE, fExportedDataDir);
    log.info("exportToFilesystem: exporting course " + this + " to " + exportDirectory + " done.");
    log.info("finished export course '" + getCourseTitle() + "' in t=" + Long.toString(System.currentTimeMillis() - s));
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) ReminderService(org.olat.modules.reminder.ReminderService) XStream(com.thoughtworks.xstream.XStream) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseConfig(org.olat.course.config.CourseConfig) TreeVisitor(org.olat.core.util.tree.TreeVisitor) RepositoryManager(org.olat.repository.RepositoryManager) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 47 with CourseConfig

use of org.olat.course.config.CourseConfig in project openolat by klemens.

the class CalendarTest method startup.

@Before
public void startup() {
    if (id1 == null) {
        id1 = JunitTestHelper.createAndPersistIdentityAsUser("cal-1-" + UUID.randomUUID().toString());
    }
    if (id2 == null) {
        id2 = JunitTestHelper.createAndPersistIdentityAsUser("cal-2-" + UUID.randomUUID().toString());
    }
    if (course1 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
        Assert.assertTrue(courseConfig.isCalendarEnabled());
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 10; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            KalendarEvent event = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test " + i, begin, end);
            calendarManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
        cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -1);
        Date begin2 = cal.getTime();
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Date end2 = cal.getTime();
        KalendarEvent event2 = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test 2", begin2, end2);
        calendarManager.addEventTo(calendarWrapper.getKalendar(), event2);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course1, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        repositoryService.addRole(id1, entry, GroupRoles.participant.name());
        dbInstance.commit();
    }
    if (course2 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
        dbInstance.commit();
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
        Assert.assertNotNull(calendarWrapper);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        dbInstance.commit();
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Before(org.junit.Before)

Example 48 with CourseConfig

use of org.olat.course.config.CourseConfig in project openolat by klemens.

the class CourseHandler method importGlossary.

private void importGlossary(ICourse course, Identity owner) {
    GlossaryManager gm = GlossaryManager.getInstance();
    RepositoryEntryImportExport importExport = gm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    GlossaryResource resource = gm.createGlossary();
    if (resource == null) {
        log.error("Error adding glossary directry during repository reference import: " + importExport.getDisplayName());
        return;
    }
    // unzip contents
    VFSContainer glossaryContainer = gm.getGlossaryRootFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), glossaryContainer);
    } else {
        log.warn("The actual contents of the glossary were not found in the export.");
    }
    // create repository entry
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
    RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
    // set the new glossary reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setGlossarySoftKey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(course, importedRepositoryEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) GlossaryManager(org.olat.modules.glossary.GlossaryManager) File(java.io.File) GlossaryResource(org.olat.fileresource.types.GlossaryResource) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 49 with CourseConfig

use of org.olat.course.config.CourseConfig in project openolat by klemens.

the class GlossaryManagerImpl method deleteGlossary.

// TODO:RH:gloss change courseconfig, to keep more than 1 single glossary as a list
/**
 * @param res glossary to be deleted
 */
@Override
public void deleteGlossary(OLATResourceable res) {
    // first remove all references
    List<Reference> repoRefs = referenceManager.getReferencesTo(res);
    for (Iterator<Reference> iter = repoRefs.iterator(); iter.hasNext(); ) {
        Reference ref = iter.next();
        if (ref.getUserdata().equals(GLOSSARY_REPO_REF_IDENTIFYER)) {
            // remove the reference from the course configuration
            // TODO:RH:improvement: this should use a callback method or send a general delete
            // event so that the course can take care of this rather than having it
            // here hardcoded
            OLATResource courseResource = ref.getSource();
            // ICourse course = CourseFactory.loadCourse(courseResource);
            ICourse course = CourseFactory.openCourseEditSession(courseResource.getResourceableId());
            CourseConfig cc = course.getCourseEnvironment().getCourseConfig();
            cc.setGlossarySoftKey(null);
            CourseFactory.setCourseConfig(course.getResourceableId(), cc);
            CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            // remove reference from the references table
            referenceManager.delete(ref);
        }
    }
    // now remove the resource itself
    FileResourceManager.getInstance().deleteFileResource(res);
}
Also used : Reference(org.olat.resource.references.Reference) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig)

Example 50 with CourseConfig

use of org.olat.course.config.CourseConfig in project openolat by klemens.

the class AssessmentManagerTest method setUp.

@Before
public void setUp() throws Exception {
    try {
        log.info("setUp start ------------------------");
        Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("junit_auth");
        tutor = JunitTestHelper.createAndPersistIdentityAsRndUser("junit_tutor");
        student = JunitTestHelper.createAndPersistIdentityAsRndUser("junit_student");
        // import "Demo course" into the bcroot_junittest
        RepositoryEntry repositoryEntry = JunitTestHelper.deployDemoCourse(author);
        Long resourceableId = repositoryEntry.getOlatResource().getResourceableId();
        log.info("Demo course imported - resourceableId: " + resourceableId);
        course = CourseFactory.loadCourse(resourceableId);
        DBFactory.getInstance().closeSession();
        CourseConfig config = course.getCourseEnvironment().getCourseConfig();
        config.setEfficencyStatementIsEnabled(true);
        CourseFactory.setCourseConfig(course.getResourceableId(), config);
        course = CourseFactory.loadCourse(resourceableId);
        config = course.getCourseEnvironment().getCourseConfig();
        Assert.assertTrue(config.isEfficencyStatementEnabled());
        log.info("setUp done ------------------------");
    } catch (RuntimeException e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) CourseConfig(org.olat.course.config.CourseConfig) Before(org.junit.Before)

Aggregations

CourseConfig (org.olat.course.config.CourseConfig)60 ICourse (org.olat.course.ICourse)28 RepositoryEntry (org.olat.repository.RepositoryEntry)24 OLATResource (org.olat.resource.OLATResource)12 File (java.io.File)10 Identity (org.olat.core.id.Identity)10 Date (java.util.Date)8 RepositoryService (org.olat.repository.RepositoryService)8 BusinessGroup (org.olat.group.BusinessGroup)7 Roles (org.olat.core.id.Roles)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)6 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)6 Calendar (java.util.Calendar)4 Before (org.junit.Before)4 Dropdown (org.olat.core.gui.components.dropdown.Dropdown)4 LinkPopupSettings (org.olat.core.gui.components.link.LinkPopupSettings)4 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)4 Structure (org.olat.course.Structure)4