Search in sources :

Example 11 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project openolat by klemens.

the class KeyAndNameConverterTest method convertAreaKeyToKey.

@Test
public void convertAreaKeyToKey() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    BGArea newArea = new MockArea(567l, "Area 1");
    BGAreaReference areaRef = new BGAreaReference(newArea, 345l, "Area 1");
    envMapper.getAreas().add(areaRef);
    String convertedExp = convertExpressionKeyToKey("inLearningArea(\"345\")", envMapper);
    Assert.assertEquals("inLearningArea(\"567\")", convertedExp);
}
Also used : BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 12 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project openolat by klemens.

the class KeyAndNameConverterTest method convertAreaNameToKey.

@Test
public void convertAreaNameToKey() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    BGArea newArea = new MockArea(567l, "Area 1");
    BGAreaReference areaRef = new BGAreaReference(newArea, 345l, "Area 1");
    envMapper.getAreas().add(areaRef);
    String convertedExp = convertExpressionNameToKey("inLearningArea(\"Area 1\")", envMapper);
    Assert.assertEquals("inLearningArea(\"567\")", convertedExp);
}
Also used : BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 13 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project openolat by klemens.

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 14 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project openolat by klemens.

the class PersistingCourseGroupManager method importCourseBusinessGroups.

/**
 * @see org.olat.course.groupsandrights.CourseGroupManager#importCourseBusinessGroups(java.io.File)
 */
@Override
public CourseEnvironmentMapper importCourseBusinessGroups(File fImportDirectory) {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    OLATResource resource = getCourseResource();
    RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(resource, true);
    File fGroupXML1 = new File(fImportDirectory, LEARNINGGROUPEXPORT_XML);
    if (fGroupXML1.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML1);
        envMapper.addBusinessGroupEnvironment(env);
    }
    File fGroupXML2 = new File(fImportDirectory, RIGHTGROUPEXPORT_XML);
    if (fGroupXML2.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML2);
        envMapper.addBusinessGroupEnvironment(env);
    }
    return envMapper;
}
Also used : BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 15 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project openolat by klemens.

the class PersistingCourseGroupManager method getBusinessGroupEnvironment.

/**
 * This operation load all business groups and areas. Use with caution, costly!
 * @param resource
 * @param fGroupExportXML
 * @return
 */
public CourseEnvironmentMapper getBusinessGroupEnvironment() {
    CourseEnvironmentMapper env = new CourseEnvironmentMapper();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, getCourseEntry(), 0, -1);
    for (BusinessGroup group : groups) {
        env.getGroups().add(new BusinessGroupReference(group));
    }
    List<BGArea> areas = areaManager.findBGAreasInContext(getCourseResource());
    for (BGArea area : areas) {
        env.getAreas().add(new BGAreaReference(area));
    }
    return env;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Aggregations

CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)32 Test (org.junit.Test)18 BGArea (org.olat.group.area.BGArea)16 BGAreaReference (org.olat.group.model.BGAreaReference)16 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)16 File (java.io.File)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 ICourse (org.olat.course.ICourse)6 OLATResource (org.olat.resource.OLATResource)6 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)4 PersistingCourseGroupManager (org.olat.course.groupsandrights.PersistingCourseGroupManager)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)4 XStream (com.thoughtworks.xstream.XStream)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Roles (org.olat.core.id.Roles)2 TreeVisitor (org.olat.core.util.tree.TreeVisitor)2 Visitor (org.olat.core.util.tree.Visitor)2 CorruptedCourseException (org.olat.course.CorruptedCourseException)2