Search in sources :

Example 21 with CourseEnvironmentMapper

use of org.olat.course.export.CourseEnvironmentMapper in project OpenOLAT by OpenOLAT.

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

use of org.olat.course.export.CourseEnvironmentMapper 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 23 with CourseEnvironmentMapper

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

the class CourseHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
    ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
    // cfc.release();
    if (course == null) {
        return null;
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    // create empty run structure
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    Structure runStructure = course.getRunStructure();
    runStructure.getRootNode().removeAllChildren();
    CourseFactory.saveCourse(course.getResourceableId());
    // import references
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
    importReferences(rootNode, course, initialAuthor, locale, withReferences);
    if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
        importSharedFolder(course, initialAuthor);
    }
    if (withReferences && course.getCourseConfig().hasGlossary()) {
        importGlossary(course, initialAuthor);
    }
    // create group management / import groups
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
    CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
    envMapper.setAuthor(initialAuthor);
    // upgrade course
    course = CourseFactory.loadCourse(cgm.getCourseResource());
    course.postImport(fImportBaseDirectory, envMapper);
    // rename root nodes, but only when user modified the course title
    boolean doUpdateTitle = true;
    File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
    if (repoConfigXml.exists()) {
        RepositoryEntryImport importConfig;
        try {
            importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
            if (importConfig != null) {
                if (displayname.equals(importConfig.getDisplayname())) {
                    // do not update if title was not modified during import
                    // user does not expect to have an updated title and there is a chance
                    // the root node title is not the same as the course title
                    doUpdateTitle = false;
                }
            }
        } catch (FileNotFoundException e) {
        // ignore
        }
    }
    if (doUpdateTitle) {
        // do not use truncate!
        course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
        course.getRunStructure().getRootNode().setLongTitle(displayname);
    }
    // course.saveRunStructure();
    CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
    // do not use truncate!
    editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
    editorRootNode.getCourseNode().setLongTitle(displayname);
    // mark entire structure as dirty/new so the user can re-publish
    markDirtyNewRecursively(editorRootNode);
    // root has already been created during export. Unmark it.
    editorRootNode.setNewnode(false);
    // save and close edit session
    CourseFactory.saveCourse(course.getResourceableId());
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
    if (imp.anyExportedPropertiesAvailable()) {
        re = imp.importContent(re, getMediaContainer(re));
    }
    // import reminders
    importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
    // clean up export folder
    cleanExportAfterImport(fImportBaseDirectory);
    return re;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) FileNotFoundException(java.io.FileNotFoundException) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryImport(org.olat.repository.RepositoryEntryImportExport.RepositoryEntryImport) FileInputStream(java.io.FileInputStream) Structure(org.olat.course.Structure) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) RepositoryService(org.olat.repository.RepositoryService)

Example 24 with CourseEnvironmentMapper

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

the class CourseHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    final OLATResource sourceResource = source.getOlatResource();
    final OLATResource targetResource = target.getOlatResource();
    CourseFactory.copyCourse(sourceResource, targetResource);
    // transaction copied
    ICourse sourceCourse = CourseFactory.loadCourse(source);
    CourseGroupManager sourceCgm = sourceCourse.getCourseEnvironment().getCourseGroupManager();
    CourseEnvironmentMapper env = PersistingCourseGroupManager.getInstance(sourceResource).getBusinessGroupEnvironment();
    File fExportDir = new File(WebappHelper.getTmpDir(), UUID.randomUUID().toString());
    fExportDir.mkdirs();
    sourceCgm.exportCourseBusinessGroups(fExportDir, env, false, false);
    ICourse course = CourseFactory.loadCourse(target);
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    // import groups
    CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fExportDir);
    envMapper.setAuthor(author);
    // upgrade to the current version of the course
    course = CourseFactory.loadCourse(cgm.getCourseResource());
    course.postCopy(envMapper, sourceCourse);
    cloneReminders(author, envMapper, source, target);
    cloneLectureConfig(source, target);
    return target;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 25 with CourseEnvironmentMapper

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

the class OLATUpgrade_8_2_0 method getCourseEnvironmentMapper.

private CourseEnvironmentMapper getCourseEnvironmentMapper(RepositoryEntry courseResource) {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseResource, 0, -1);
    for (BusinessGroup group : groups) {
        envMapper.getGroups().add(new BusinessGroupReference(group));
    }
    List<BGArea> areas = areaManager.findBGAreasInContext(courseResource.getOlatResource());
    for (BGArea area : areas) {
        envMapper.getAreas().add(new BGAreaReference(area));
    }
    return envMapper;
}
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