Search in sources :

Example 36 with CourseEditorTreeModel

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

the class PublishProcessTest method publishCourse.

private void publishCourse(List<String> nodeIds, RepositoryEntry re, Identity author) {
    ICourse course = CourseFactory.openCourseEditSession(re.getOlatResource().getResourceableId());
    CourseEditorTreeModel cetm = course.getEditorTreeModel();
    PublishProcess pp = PublishProcess.getInstance(course, cetm, locale);
    // create publish node list
    pp.createPublishSetFor(nodeIds);
    PublishSetInformations set = pp.testPublishSet(locale);
    StatusDescription[] sds = set.getWarnings();
    Assert.assertNotNull(sds);
    Assert.assertEquals(0, sds.length);
    pp.applyPublishSet(author, locale, true);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) ICourse(org.olat.course.ICourse)

Example 37 with CourseEditorTreeModel

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

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 38 with CourseEditorTreeModel

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

the class PublishProcessTest method testPublishANotReallyNewNode.

/**
 * Publish a course with a node marked as new but the node
 * exists already in the run structure.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishANotReallyNewNode() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course_err1_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 not really new", 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 39 with CourseEditorTreeModel

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

the class PublishProcessTest method testPublishNewNodeButNotMarkedAsSuchAndDeleted.

/**
 * Publish a course with a node marked as not new and deleted but
 * the node doesn't exist in the run structure.
 *
 * @throws URISyntaxException
 */
@Test
public void testPublishNewNodeButNotMarkedAsSuchAndDeleted() throws URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
    RepositoryEntry re = deployTestCourse("simple_course_err4_not_new_deleted.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(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) 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 40 with CourseEditorTreeModel

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

the class CourseExtensionHelper method createNode.

/**
 * Creates a course node and appends it to the course. (not persisted yet)
 *
 * @param c course object
 * @param shortTitle short title for node
 * @param longTitle long title for node
 * @return created course node
 */
public static final CourseNode createNode(ICourse course, final String shortTitle, final String longTitle, final String type) {
    // create a node with default data
    CourseNodeConfiguration nodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
    CourseNode node = nodeConfig.getInstance();
    node.setShortTitle(shortTitle);
    node.setLongTitle(longTitle);
    // append node to course
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    final CourseEditorTreeModel cetm = course.getEditorTreeModel();
    final CourseNode rootNode = cetm.getCourseNode(course.getRunStructure().getRootNode().getIdent());
    course.getEditorTreeModel().addCourseNode(node, rootNode);
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    OLog log = Tracing.createLoggerFor(CourseExtensionHelper.class);
    if (log.isDebug())
        log.debug("Created new course node: " + nodeConfig.getAlias());
    return node;
}
Also used : OLog(org.olat.core.logging.OLog) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

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