Search in sources :

Example 6 with CourseEnvironmentMapper

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

the class KeyAndNameConverterTest method convertGroupAndAreaKeyToName_sameKey.

@Test
public void convertGroupAndAreaKeyToName_sameKey() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    BGArea newArea = new MockArea(567l, "Area 1");
    BGAreaReference areaRef = new BGAreaReference(newArea, null, null);
    envMapper.getAreas().add(areaRef);
    MockBusinessGroup newGroup = new MockBusinessGroup(567l, "Group 1");
    BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, null, null);
    envMapper.getGroups().add(bgRef);
    String convertedExp = convertExpressionKeyToName("inLearningArea(\"567\") & isLearningGroupFull(\"567\")", envMapper);
    Assert.assertEquals("inLearningArea(\"Area 1\") & isLearningGroupFull(\"Group 1\")", convertedExp);
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 7 with CourseEnvironmentMapper

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

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)

Example 8 with CourseEnvironmentMapper

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

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

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

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)

Example 10 with CourseEnvironmentMapper

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

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)

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