Search in sources :

Example 6 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project OpenOLAT by OpenOLAT.

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)

Example 7 with CourseEditorTreeModel

use of org.olat.course.tree.CourseEditorTreeModel in project OpenOLAT by OpenOLAT.

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

use of org.olat.course.tree.CourseEditorTreeModel 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 9 with CourseEditorTreeModel

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

use of org.olat.course.tree.CourseEditorTreeModel in project OpenOLAT by OpenOLAT.

the class CoursesElementsTest method testUpdateRootNodeCoursePost.

@Test
public // fxdiff FXOLAT-122: course management
void testUpdateRootNodeCoursePost() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create an empty course
    URI uri = getCoursesUri().queryParam("shortTitle", "course4").queryParam("title", "course4 long name").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CourseVO course = conn.parse(response, CourseVO.class);
    assertNotNull(course);
    assertNotNull(course.getKey());
    assertNotNull(course.getEditorRootNodeId());
    // update the root node
    URI rootUri = getElementsUri(course).path("structure").path(course.getEditorRootNodeId()).build();
    HttpPost updateMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
    HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("shortTitle", "Structure-0b").addTextBody("longTitle", "Structure-long-0b").addTextBody("objectives", "Structure-objectives-0b").build();
    updateMethod.setEntity(entity);
    HttpResponse newStructureResponse = conn.execute(updateMethod);
    int newStructureCode = newStructureResponse.getStatusLine().getStatusCode();
    assertTrue(newStructureCode == 200 || newStructureCode == 201);
    // check the response
    CourseNodeVO structureNode = conn.parse(newStructureResponse, CourseNodeVO.class);
    assertNotNull(structureNode);
    assertNotNull(structureNode.getId());
    assertEquals(structureNode.getShortTitle(), "Structure-0b");
    assertEquals(structureNode.getLongTitle(), "Structure-long-0b");
    assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0b");
    assertEquals(structureNode.getId(), course.getEditorRootNodeId());
    // check the real node
    ICourse realCourse = CourseFactory.loadCourse(course.getKey());
    CourseEditorTreeModel editorTreeModel = realCourse.getEditorTreeModel();
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorTreeModel.getRootNode();
    assertNotNull(rootNode);
    assertNotNull(rootNode.getIdent());
    assertNotNull(rootNode.getCourseNode());
    assertEquals(rootNode.getCourseNode().getShortTitle(), "Structure-0b");
    assertEquals(rootNode.getCourseNode().getLongTitle(), "Structure-long-0b");
    assertEquals(rootNode.getCourseNode().getLearningObjectives(), "Structure-objectives-0b");
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpPost(org.apache.http.client.methods.HttpPost) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) HttpEntity(org.apache.http.HttpEntity) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

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