Search in sources :

Example 41 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class ChooseNodeController method doCreateNode.

private void doCreateNode(String type) {
    ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
    // user chose a position to insert a new node
    CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
    createdNode = newNodeConfig.getInstance();
    // Set some default values
    String title = new String(newNodeConfig.getLinkText(getLocale()));
    createdNode.setShortTitle(title);
    createdNode.setNoAccessExplanation(translate("form.noAccessExplanation.default"));
    // Insert it now
    CourseEditorTreeModel editorTreeModel = course.getEditorTreeModel();
    if (editorTreeModel.getRootNode().equals(currentNode)) {
        // root, add as last child
        int pos = currentNode.getChildCount();
        CourseNode selectedNode = currentNode.getCourseNode();
        editorTreeModel.insertCourseNodeAt(createdNode, selectedNode, pos);
    } else {
        CourseEditorTreeNode parentNode = (CourseEditorTreeNode) currentNode.getParent();
        CourseNode selectedNode = parentNode.getCourseNode();
        int pos = currentNode.getPosition();
        editorTreeModel.insertCourseNodeAt(createdNode, selectedNode, pos + 1);
    }
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

Example 42 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class QuickPublishController method doAutoPublish.

private boolean doAutoPublish() {
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess publishProcess = PublishProcess.getInstance(course, cetm, getLocale());
    PublishTreeModel publishTreeModel = publishProcess.getPublishTreeModel();
    if (publishTreeModel.hasPublishableChanges()) {
        List<String> nodeToPublish = new ArrayList<String>();
        visitPublishModel(publishTreeModel.getRootNode(), publishTreeModel, nodeToPublish);
        // only add selection if changes were possible
        for (Iterator<String> selectionIt = nodeToPublish.iterator(); selectionIt.hasNext(); ) {
            String ident = selectionIt.next();
            TreeNode node = publishProcess.getPublishTreeModel().getNodeById(ident);
            if (!publishTreeModel.isSelectable(node)) {
                selectionIt.remove();
            }
        }
        publishProcess.createPublishSetFor(nodeToPublish);
        PublishSetInformations set = publishProcess.testPublishSet(getLocale());
        StatusDescription[] status = set.getWarnings();
        // publish not possible when there are errors
        StringBuilder errMsg = new StringBuilder();
        for (int i = 0; i < status.length; i++) {
            if (status[i].isError()) {
                errMsg.append(status[i].getLongDescription(getLocale()));
                logError("Status error by publish: " + status[i].getLongDescription(getLocale()), null);
            }
        }
        if (errMsg.length() > 0) {
            getWindowControl().setWarning(errMsg.toString());
            return false;
        }
        PublishEvents publishEvents = publishProcess.getPublishEvents();
        try {
            publishProcess.applyPublishSet(getIdentity(), getLocale(), false);
        } catch (Exception e) {
            logError("", e);
        }
        if (publishEvents.getPostPublishingEvents().size() > 0) {
            for (MultiUserEvent event : publishEvents.getPostPublishingEvents()) {
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(event, courseOres);
            }
        }
    }
    return true;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) PublishTreeModel(org.olat.course.tree.PublishTreeModel) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) TreeNode(org.olat.core.gui.components.tree.TreeNode) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 43 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class NodeExportVisitor method load.

/**
 * Load the course from disk/database, load the run structure from xml file etc.
 */
void load() {
    /*
		 * remember that loading of the courseConfiguration is already done within
		 * the constructor !
		 */
    Object obj;
    obj = readObject(RUNSTRUCTURE_XML);
    if (!(obj instanceof Structure))
        throw new AssertException("Error reading course run structure.");
    runStructure = (Structure) obj;
    initHasAssessableNodes();
    obj = readObject(EDITORTREEMODEL_XML);
    if (!(obj instanceof CourseEditorTreeModel))
        throw new AssertException("Error reading course editor tree model.");
    editorTreeModel = (CourseEditorTreeModel) obj;
}
Also used : AssertException(org.olat.core.logging.AssertException) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel)

Example 44 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class NodeExportVisitor method postImport.

@Override
public void postImport(File importDirectory, CourseEnvironmentMapper envMapper) {
    Structure importedStructure = getRunStructure();
    visit(new NodePostImportVisitor(importDirectory, this, envMapper, Processing.runstructure), importedStructure.getRootNode());
    saveRunStructure();
    CourseEditorTreeModel importedEditorModel = getEditorTreeModel();
    visit(new NodePostImportVisitor(importDirectory, this, envMapper, Processing.editor), importedEditorModel.getRootNode());
    saveEditorTreeModel();
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel)

Example 45 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project openolat by klemens.

the class ModifyCourseEvent method createCourse.

/**
 * Creates an empty course with a single root node. The course is linked to
 * the resourceable ores. The efficiency statment are enabled per default!
 *
 * @param ores
 * @param shortTitle Short title of root node
 * @param longTitle Long title of root node
 * @param learningObjectives Learning objectives of root node
 * @return An empty course with a single root node.
 */
public static ICourse createCourse(RepositoryEntry courseEntry, String shortTitle, String longTitle, String learningObjectives) {
    OLATResource courseResource = courseEntry.getOlatResource();
    PersistingCourseImpl newCourse = new PersistingCourseImpl(courseResource);
    // Put new course in course cache
    loadedCourses.put(newCourse.getResourceableId(), newCourse);
    Structure initialStructure = new Structure();
    CourseNode runRootNode = new STCourseNode();
    runRootNode.setShortTitle(shortTitle);
    runRootNode.setLongTitle(longTitle);
    runRootNode.setLearningObjectives(learningObjectives);
    initialStructure.setRootNode(runRootNode);
    newCourse.setRunStructure(initialStructure);
    newCourse.saveRunStructure();
    CourseEditorTreeModel editorTreeModel = new CourseEditorTreeModel();
    CourseEditorTreeNode editorRootNode = new CourseEditorTreeNode((CourseNode) ObjectCloner.deepCopy(runRootNode));
    editorTreeModel.setRootNode(editorRootNode);
    newCourse.setEditorTreeModel(editorTreeModel);
    newCourse.saveEditorTreeModel();
    // enable efficiency statement per default
    CourseConfig courseConfig = newCourse.getCourseConfig();
    courseConfig.setEfficencyStatementIsEnabled(true);
    newCourse.setCourseConfig(courseConfig);
    return newCourse;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) STCourseNode(org.olat.course.nodes.STCourseNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) OLATResource(org.olat.resource.OLATResource) STCourseNode(org.olat.course.nodes.STCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseConfig(org.olat.course.config.CourseConfig)

Aggregations

CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)46 ICourse (org.olat.course.ICourse)26 CourseNode (org.olat.course.nodes.CourseNode)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 Test (org.junit.Test)18 RepositoryEntry (org.olat.repository.RepositoryEntry)16 Identity (org.olat.core.id.Identity)14 INode (org.olat.core.util.nodes.INode)12 ArrayList (java.util.ArrayList)6 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)6 File (java.io.File)4 URI (java.net.URI)4 HttpEntity (org.apache.http.HttpEntity)4 HttpResponse (org.apache.http.HttpResponse)4 HttpPost (org.apache.http.client.methods.HttpPost)4 HttpPut (org.apache.http.client.methods.HttpPut)4 AssertException (org.olat.core.logging.AssertException)4 CourseConfig (org.olat.course.config.CourseConfig)4 PublishProcess (org.olat.course.editor.PublishProcess)4 PublishSetInformations (org.olat.course.editor.PublishSetInformations)4