Search in sources :

Example 16 with CourseEnvironmentMapper

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

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

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

the class OLATUpgrade_8_2_0 method upgradeCourseConditions.

private boolean upgradeCourseConditions(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CONDITIONS)) {
        int counter = 0;
        List<RepositoryEntry> entries;
        SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
        params.setRoles(new Roles(true, false, false, false, false, false, false));
        params.addResourceTypes("CourseModule");
        do {
            entries = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, REPO_ENTRIES_BATCH_SIZE, true);
            for (RepositoryEntry entry : entries) {
                try {
                    ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
                    CourseEnvironmentMapper envMapper = getCourseEnvironmentMapper(entry);
                    course.postImport(null, envMapper);
                } catch (CorruptedCourseException e) {
                    log.error("Course seems corrupt: " + entry.getOlatResource().getResourceableId());
                } catch (Exception e) {
                    log.error("Course seems highly corrupt: " + entry.getOlatResource().getResourceableId());
                }
            }
            dbInstance.intermediateCommit();
            counter += entries.size();
            log.audit("Processed repository entries: " + entries.size());
        } while (entries.size() == REPO_ENTRIES_BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_CONDITIONS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CorruptedCourseException(org.olat.course.CorruptedCourseException) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) CorruptedCourseException(org.olat.course.CorruptedCourseException)

Example 18 with CourseEnvironmentMapper

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

the class KeyAndNameConverterTest method convertBusinessGroupKeyToName.

@Test
public void convertBusinessGroupKeyToName() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    MockBusinessGroup newGroup = new MockBusinessGroup(567l, "Group 1");
    BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, null, null);
    envMapper.getGroups().add(bgRef);
    String convertedExp = convertExpressionKeyToName("isLearningGroupFull(\"567\")", envMapper);
    Assert.assertEquals("isLearningGroupFull(\"Group 1\")", convertedExp);
}
Also used : BusinessGroupReference(org.olat.group.model.BusinessGroupReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 19 with CourseEnvironmentMapper

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

the class KeyAndNameConverterTest method convertBusinessGroupNameToKey.

@Test
public void convertBusinessGroupNameToKey() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    MockBusinessGroup newGroup = new MockBusinessGroup(567l, "Group 1");
    BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, 345l, "Group 1");
    envMapper.getGroups().add(bgRef);
    String convertedExp = convertExpressionNameToKey("inLearningGroup(\"Group 1\")", envMapper);
    Assert.assertEquals("inLearningGroup(\"567\")", convertedExp);
}
Also used : BusinessGroupReference(org.olat.group.model.BusinessGroupReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 20 with CourseEnvironmentMapper

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

the class KeyAndNameConverterTest method convertAreaKeyToName.

@Test
public void convertAreaKeyToName() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    BGArea newArea = new MockArea(567l, "Area 1");
    BGAreaReference areaRef = new BGAreaReference(newArea, null, null);
    envMapper.getAreas().add(areaRef);
    String convertedExp = convertExpressionKeyToName("inLearningArea(\"567\")", envMapper);
    Assert.assertEquals("inLearningArea(\"Area 1\")", 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)

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