Search in sources :

Example 6 with Structure

use of org.olat.course.Structure in project openolat by klemens.

the class AssessmentModule method addToUpcomingWork.

/**
 * @param pe
 */
private void addToUpcomingWork(PublishEvent pe) {
    ICourse course = CourseFactory.loadCourse(pe.getPublishedCourseResId());
    boolean courseEfficiencyEnabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
    if (!courseEfficiencyEnabled) {
        // no efficiency enabled, stop here.
        return;
    }
    // deleted + inserted + modified node ids -> changedNodeIds
    Set<String> changedNodeIds = pe.getDeletedCourseNodeIds();
    changedNodeIds.addAll(pe.getInsertedCourseNodeIds());
    changedNodeIds.addAll(pe.getModifiedCourseNodeIds());
    // 
    boolean courseAssessmentChanged = false;
    Structure courseRun = course.getRunStructure();
    for (Iterator<String> iter = changedNodeIds.iterator(); iter.hasNext(); ) {
        String nodeId = iter.next();
        boolean wasNodeAsessable = AssessmentHelper.checkIfNodeIsAssessable(courseRun.getNode(nodeId));
        boolean isNodeAssessable = AssessmentHelper.checkIfNodeIsAssessable(course.getEditorTreeModel().getCourseNode(nodeId));
        // if node was or became assessable
        if (wasNodeAsessable || isNodeAssessable) {
            courseAssessmentChanged = true;
            break;
        }
    }
    if (!courseAssessmentChanged) {
        // assessment changes detected, stop here
        return;
    }
    synchronized (upcomingWork) {
        // o_clusterOK by:ld synchronized OK - only one cluster node must update the EfficiencyStatements (the course is locked for editing)
        upcomingWork.add(course.getResourceableId());
    }
    return;
}
Also used : ICourse(org.olat.course.ICourse) Structure(org.olat.course.Structure)

Example 7 with Structure

use of org.olat.course.Structure in project openolat by klemens.

the class PublishProcess method applyPublishSet.

/**
 * @param identity
 * @param locale
 * @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
 */
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
    // the active runstructure and the new created runstructure
    Structure existingCourseRun = course.getRunStructure();
    EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
    /*
		 * use book keeping lists for publish event
		 */
    Set<String> deletedCourseNodeIds = new HashSet<String>();
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            deletedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> insertedCourseNodeIds = new HashSet<String>();
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            insertedCourseNodeIds.add(cn.getIdent());
        }
    }
    Set<String> modifiedCourseNodeIds = new HashSet<String>();
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            modifiedCourseNodeIds.add(cn.getIdent());
        }
    }
    /*
		 * broadcast PRE PUBLISH event that a publish will take place
		 */
    PublishEvent beforePublish = new PublishEvent(course, identity);
    beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
    beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
    beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    beforePublish.setState(PublishEvent.PRE_PUBLISH);
    // old course structure accessible
    orec.fireEventToListenersOf(beforePublish, course);
    /*
		 * TODO:pb: discuss with fj: listeners could add information to
		 * beforePublish event such as a right to veto or add identities who is
		 * currently in the course, thus stopping the publishing author from
		 * publishing! i.e. if people are in a test or something like this.... we
		 * could the ask here beforePublish.accepted() and proceed only in this
		 * case.
		 */
    // 
    /*
		 * remove new nodes which were marked as delete and deletion is published.
		 */
    UserManager um = UserManager.getInstance();
    String charset = um.getUserCharset(identity);
    if (editorModelDeletedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.removeFromParent();
            if (!cetn.isNewnode() && oldCn != null) {
                // only clean up and archive of nodes which were already in run
                // save data, remove references
                deleteRefs(oldCn);
                archiveDeletedNode(identity, cn, oldCn, locale, charset);
                // 2) delete all user data
                oldCn.cleanupOnDelete(course);
            }
        }
    }
    /*
		 * mark modified ones as no longer dirty
		 */
    if (editorModelModifiedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            // null
            if (oldCn != null) {
                if (!(cn.getIdent().equals(oldCn.getIdent()))) {
                    throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
                }
            }
            cetn.setDirty(false);
            // 
            updateRefs(cn, oldCn);
        }
    }
    /*
		 * mark newly published ones is no longer new and dirty
		 */
    if (editorModelInsertedNodes.size() > 0) {
        for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
            CourseEditorTreeNode cetn = iter.next();
            CourseNode cn = cetn.getCourseNode();
            CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
            if (oldCn != null) {
                throw new AssertException("new node has an oldCN??");
            }
            cetn.setDirty(false);
            cetn.setNewnode(false);
            // 
            updateRefs(cn, null);
        }
    }
    /*
		 * saving
		 */
    long pubtimestamp = System.currentTimeMillis();
    editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
    // set the new runstructure and save it.
    existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
    CourseFactory.saveCourse(course.getResourceableId());
    // on old course, apply update to published nodes
    if (!newCourse) {
        for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
        for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
            cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
        }
    }
    // commit all changes before sending an event
    DBFactory.getInstance().commitAndCloseSession();
    /*
		 * broadcast event
		 */
    PublishEvent publishEvent = new PublishEvent(course, identity);
    publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
    publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
    publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
    // new course structure accessible
    // CourseFactory is one listener, which removes the course from the
    // cache.
    orec.fireEventToListenersOf(publishEvent, course);
/*
		 * END NEW STYLE PUBLISH
		 */
}
Also used : AssertException(org.olat.core.logging.AssertException) UserManager(org.olat.user.UserManager) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) EventBus(org.olat.core.util.event.EventBus) CourseNode(org.olat.course.nodes.CourseNode) Structure(org.olat.course.Structure) HashSet(java.util.HashSet)

Example 8 with Structure

use of org.olat.course.Structure in project openolat by klemens.

the class DENCourseNodeNotificationHandler method getCourseDENNodes.

/**
 * @param course
 * @return
 */
private List<DENCourseNode> getCourseDENNodes(ICourse course) {
    List<DENCourseNode> denNodes = new ArrayList<DENCourseNode>(10);
    Structure courseStruct = course.getRunStructure();
    CourseNode rootNode = courseStruct.getRootNode();
    getCourseDENNodes(rootNode, denNodes);
    return denNodes;
}
Also used : ArrayList(java.util.ArrayList) CourseNode(org.olat.course.nodes.CourseNode) DENCourseNode(de.bps.course.nodes.DENCourseNode) Structure(org.olat.course.Structure) DENCourseNode(de.bps.course.nodes.DENCourseNode)

Example 9 with Structure

use of org.olat.course.Structure 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 10 with Structure

use of org.olat.course.Structure in project OpenOLAT by OpenOLAT.

the class PreviewConfigController method generateEnvironment.

private void generateEnvironment() {
    List<BGArea> tmpAreas = areaManager.loadAreas(psf.getAreaKeys());
    List<BusinessGroup> groups = businessGroupService.loadBusinessGroups(psf.getGroupKeys());
    // get learning areas for groups
    Set<BGArea> areas = new HashSet<BGArea>();
    areas.addAll(tmpAreas);
    List<BGArea> areaByGroups = areaManager.findBGAreasOfBusinessGroups(groups);
    areas.addAll(areaByGroups);
    role = psf.getRole();
    ICourse course = CourseFactory.loadCourse(ores);
    // default is student
    isGlobalAuthor = false;
    isGuestOnly = false;
    isCoach = false;
    isCourseAdmin = false;
    /*
		 * if (role.equals(PreviewSettingsForm.ROLE_STUDENT)) { } else
		 */
    if (role.equals(PreviewSettingsForm.ROLE_GUEST)) {
        isGuestOnly = true;
    } else if (role.equals(PreviewSettingsForm.ROLE_COURSECOACH)) {
        isCoach = true;
    } else if (role.equals(PreviewSettingsForm.ROLE_COURSEADMIN)) {
        isCourseAdmin = true;
    } else if (role.equals(PreviewSettingsForm.ROLE_GLOBALAUTHOR)) {
        isGlobalAuthor = true;
    }
    final RepositoryEntry courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    final CourseGroupManager cgm = new PreviewCourseGroupManager(courseResource, new ArrayList<BusinessGroup>(groups), new ArrayList<BGArea>(areas), isCoach, isCourseAdmin);
    final UserNodeAuditManager auditman = new PreviewAuditManager();
    final AssessmentManager am = new PreviewAssessmentManager();
    final CoursePropertyManager cpm = new PreviewCoursePropertyManager();
    final Structure runStructure = course.getEditorTreeModel().createStructureForPreview();
    final String title = course.getCourseTitle();
    final CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    simCourseEnv = new PreviewCourseEnvironment(title, runStructure, psf.getDate(), course.getCourseFolderContainer(), course.getCourseBaseContainer(), course.getResourceableId(), cpm, cgm, auditman, am, courseConfig);
    simIdentEnv = new IdentityEnvironment();
    simIdentEnv.setRoles(new Roles(false, false, false, isGlobalAuthor, isGuestOnly, false, false));
    final Identity ident = new PreviewIdentity();
    simIdentEnv.setIdentity(ident);
    // identity must be set before attributes OLAT-4811
    simIdentEnv.setAttributes(psf.getAttributesMap());
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) AssessmentManager(org.olat.course.assessment.AssessmentManager) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseConfig(org.olat.course.config.CourseConfig) BGArea(org.olat.group.area.BGArea) Structure(org.olat.course.Structure) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) Roles(org.olat.core.id.Roles) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Aggregations

Structure (org.olat.course.Structure)22 ICourse (org.olat.course.ICourse)8 CourseNode (org.olat.course.nodes.CourseNode)8 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)8 ArrayList (java.util.ArrayList)6 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 HashSet (java.util.HashSet)4 AssessmentManager (org.olat.course.assessment.AssessmentManager)4 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)4 CourseConfig (org.olat.course.config.CourseConfig)4 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)4 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)4 BusinessGroup (org.olat.group.BusinessGroup)4 BGArea (org.olat.group.area.BGArea)4 DENCourseNode (de.bps.course.nodes.DENCourseNode)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Date (java.util.Date)2