Search in sources :

Example 6 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class PublishProcessTest method testPublishNewNodeButNotMarkedAsSuch.

/**
 * Publish a course with a node marked as not new but the
 * node dosn't exist in the run structure.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishNewNodeButNotMarkedAsSuch() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course_err3_not_new.zip");
    // change node 1
    ICourse course = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    CourseEditorTreeNode node1 = (CourseEditorTreeNode) cetm.getRootNode().getChildAt(0);
    // publish the course and must survive this without exception
    // as the course has no changes but we try to publish it
    List<String> nodeIds = Collections.singletonList(node1.getIdent());
    publishCourse(nodeIds, re, author);
    // check the change
    ICourse reloadedCourse = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    Assert.assertEquals(3, reloadedCourse.getRunStructure().getRootNode().getChildCount());
    INode runNode1 = reloadedCourse.getRunStructure().getRootNode().getChildAt(0);
    Assert.assertNotNull(runNode1);
    CourseNode runNode1Impl = (CourseNode) runNode1;
    Assert.assertEquals("Node 1 from hell", runNode1Impl.getShortTitle());
}
Also used : INode(org.olat.core.util.nodes.INode) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 7 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class PublishProcessTest method testPublishNewNodeNotMarkedAsSuchAndNotPublished.

/**
 * Publish a course with a node marked as not new but
 * the node doesn't exist in the run structure. The node
 * itself is not published.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishNewNodeNotMarkedAsSuchAndNotPublished() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course_err5_not_new_or_published.zip");
    // change node 1
    ICourse course = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    // publish the course and must survive this without exception
    // as the course has no changes but we try to publish it
    List<String> nodeIds = Collections.singletonList(cetm.getRootNode().getIdent());
    publishCourse(nodeIds, re, author);
    // check the change
    ICourse reloadedCourse = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
    Assert.assertEquals(2, reloadedCourse.getRunStructure().getRootNode().getChildCount());
    INode runNode1 = reloadedCourse.getRunStructure().getRootNode().getChildAt(0);
    Assert.assertNotNull(runNode1);
    CourseNode runNode1Impl = (CourseNode) runNode1;
    Assert.assertEquals("Node 2", runNode1Impl.getShortTitle());
}
Also used : INode(org.olat.core.util.nodes.INode) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 8 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class GTAManagerTest method getGTACourseNode.

private GTACourseNode getGTACourseNode(RepositoryEntry courseEntry) {
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    for (int i = rootNode.getChildCount(); i-- > 0; ) {
        INode child = rootNode.getChildAt(i);
        if (child instanceof GTACourseNode) {
            return ((GTACourseNode) child);
        }
    }
    return null;
}
Also used : INode(org.olat.core.util.nodes.INode) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode)

Example 9 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class EditorMainController method doCreateAlternateBuildingBlock.

/**
 * The following operation are done:
 * <ul>
 * 	<li>create a new instance of the replacement type
 * 	<li>add the new element below the original element
 * 	<li>copy the element title, description and the generic configuration options
 * 	<li>copy the access, visibility and scoring rules (easy and expert)
 * 	<li>optionally copy some other configuration if this is possible at all
 * 	<li>move all child elements from the original to the replacement element
 * 	<li>mark the original element as deleted
 * </ul>
 *
 * @param chosenNode
 * @param selectAlternative
 */
private void doCreateAlternateBuildingBlock(UserRequest ureq, ICourse course, CourseNode chosenNode, String selectAlternative) {
    if (!StringHelper.containsNonWhitespace(selectAlternative))
        return;
    // create the alternative node
    CourseNodeConfiguration newConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(selectAlternative);
    CourseNode newNode = newConfig.getInstance();
    // copy configurations
    chosenNode.copyConfigurationTo(newNode, course);
    // insert the node
    CourseEditorTreeNode cetn = (CourseEditorTreeNode) cetm.getNodeById(chosenNode.getIdent());
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) cetn.getParent();
    int position = cetn.getPosition() + 1;
    CourseEditorTreeNode newCetn = course.getEditorTreeModel().insertCourseNodeAt(newNode, parentNode.getCourseNode(), position);
    doInsert(ureq, newNode);
    // copy the children
    while (cetn.getChildCount() > 0) {
        CourseEditorTreeNode childNode = (CourseEditorTreeNode) cetn.getChildAt(0);
        newCetn.addChild(childNode);
    }
    // set all dirty
    TreeVisitor tv = new TreeVisitor(new Visitor() {

        public void visit(INode node) {
            ((CourseEditorTreeNode) node).setDirty(true);
        }
    }, newCetn, true);
    tv.visitAll();
    // mark as deleted
    doDelete(course, chosenNode.getIdent());
    // save
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

Example 10 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class CourseEditorEnvImpl method checkFolderNodes.

private List<StatusDescription> checkFolderNodes(INode rootNode, ICourse course, List<StatusDescription> descriptions) {
    List<StatusDescription> descriptionsI = descriptions;
    Visitor visitor = new Visitor() {

        @Override
        public void visit(INode node) {
            CourseEditorTreeNode courseNode = (CourseEditorTreeNode) course.getEditorTreeModel().getNodeById(node.getIdent());
            if (!courseNode.isDeleted() && courseNode.getCourseNode() instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) courseNode.getCourseNode();
                if (bcNode.isSharedFolder()) {
                    String translPackage = Util.getPackageName(BCCourseNodeEditController.class);
                    StatusDescription status = new StatusDescription(StatusDescription.ERROR, "warning.no.sharedfolder", "warning.no.sharedfolder", null, translPackage);
                    status.setDescriptionForUnit(bcNode.getIdent());
                    // set which pane is affected by error
                    status.setActivateableViewIdentifier(BCCourseNodeEditController.PANE_TAB_FOLDER);
                    descriptionsI.add(status);
                }
            }
        }
    };
    TreeVisitor v = new TreeVisitor(visitor, rootNode, false);
    v.visitAll();
    return descriptionsI;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) BCCourseNode(org.olat.course.nodes.BCCourseNode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode)

Aggregations

INode (org.olat.core.util.nodes.INode)106 Visitor (org.olat.core.util.tree.Visitor)44 CourseNode (org.olat.course.nodes.CourseNode)44 ICourse (org.olat.course.ICourse)40 TreeVisitor (org.olat.core.util.tree.TreeVisitor)30 ArrayList (java.util.ArrayList)28 Identity (org.olat.core.id.Identity)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 TreeNode (org.olat.core.gui.components.tree.TreeNode)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 BCCourseNode (org.olat.course.nodes.BCCourseNode)14 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)14 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)14 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)12 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)12 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)12 HashMap (java.util.HashMap)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 GET (javax.ws.rs.GET)8