Search in sources :

Example 11 with Structure

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

the class PublishProcess method createPublishSetFor.

/**
 * first step in publishing course editor nodes.<br>
 * next step is testPublishSet, see method for more details.
 * @param nodeIdsToPublish
 */
public void createPublishSetFor(List<String> nodeIdsToPublish) {
    this.originalNodeIdsToPublish = nodeIdsToPublish;
    // append new nodes' subnodes
    int selectCount = nodeIdsToPublish.size();
    for (int i = 0; i < selectCount; i++) {
        // avoid using iterator here so we can modify the Collection
        String nodeId = nodeIdsToPublish.get(i);
        CourseEditorTreeNode cetn = editorTreeModel.getCourseEditorNodeById(nodeId);
        if (cetn.isNewnode() || cetn.isDeleted() || publishTreeModel.isMoved(cetn))
            appendPublishableSubnodeIds(cetn, nodeIdsToPublish);
    }
    /*
		 * generatePublishSet, testPublishSet, applyPublishSet
		 */
    /*
		 * several book keeping lists which are also used to modify the course
		 * editor model after the new runstructure is generated into ram.
		 */
    editorModelDeletedNodes = new ArrayList<CourseEditorTreeNode>();
    editorModelInsertedNodes = new ArrayList<CourseEditorTreeNode>();
    editorModelModifiedNodes = new ArrayList<CourseEditorTreeNode>();
    resultingCourseRun = new Structure();
    // has side effect on the above editorModelxxxNodes and the
    // resultingCourseRun;
    calculatePublishSet(nodeIdsToPublish);
}
Also used : CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) Structure(org.olat.course.Structure)

Example 12 with Structure

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

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 13 with Structure

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

the class PreviewConfigHelper method getPreviewCourseEnvironment.

public static CourseEnvironment getPreviewCourseEnvironment(boolean isCoach, boolean isCourseAdmin, ICourse course) {
    // generateEnvironment();
    final RepositoryEntry courseResource = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    final CourseGroupManager cgm = new PreviewCourseGroupManager(courseResource, new ArrayList<BusinessGroup>(), new ArrayList<BGArea>(), 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();
    CourseEnvironment previewCourseEnvironment = new PreviewCourseEnvironment(title, runStructure, new Date(), course.getCourseFolderContainer(), course.getCourseBaseContainer(), course.getResourceableId(), cpm, cgm, auditman, am, courseConfig);
    return previewCourseEnvironment;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) AssessmentManager(org.olat.course.assessment.AssessmentManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) BGArea(org.olat.group.area.BGArea) Structure(org.olat.course.Structure) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 14 with Structure

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

the class BulkAssessmentOverviewController method reloadTaskModel.

private void reloadTaskModel() {
    List<Task> tasks = taskManager.getTasks(courseEntry.getOlatResource());
    List<TaskData> taskDatas = new ArrayList<TaskData>(tasks.size());
    ICourse course = CourseFactory.loadCourse(courseEntry);
    Structure structure = course.getRunStructure();
    for (Task task : tasks) {
        String fullName = null;
        if (task.getCreator() != null) {
            fullName = userManager.getUserDisplayName(task.getCreator());
        }
        BulkAssessmentTask runnable = taskManager.getPersistedRunnableTask(task, BulkAssessmentTask.class);
        AssessableCourseNode courseNode = (AssessableCourseNode) structure.getNode(runnable.getCourseNodeIdent());
        taskDatas.add(new TaskData(task, runnable, courseNode, fullName));
    }
    taskModel.setObjects(taskDatas);
    taskListEl.reset();
    flc.contextPut("hasScheduledTasks", Boolean.valueOf(taskDatas.size() > 0));
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) Task(org.olat.core.commons.services.taskexecutor.Task) BulkAssessmentTask(org.olat.course.assessment.manager.BulkAssessmentTask) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) BulkAssessmentTask(org.olat.course.assessment.manager.BulkAssessmentTask) Structure(org.olat.course.Structure)

Example 15 with Structure

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

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)

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