use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class CoursesWebService method prepareCourse.
private static ICourse prepareCourse(RepositoryEntry addedEntry, String shortTitle, String longTitle, CourseConfigVO courseConfigVO) {
// set root node title
String courseShortTitle = addedEntry.getDisplayname();
if (StringHelper.containsNonWhitespace(shortTitle)) {
courseShortTitle = shortTitle;
}
String courseLongTitle = addedEntry.getDisplayname();
if (StringHelper.containsNonWhitespace(longTitle)) {
courseLongTitle = longTitle;
}
ICourse course = CourseFactory.openCourseEditSession(addedEntry.getOlatResource().getResourceableId());
course.getRunStructure().getRootNode().setShortTitle(Formatter.truncate(courseShortTitle, 25));
course.getRunStructure().getRootNode().setLongTitle(courseLongTitle);
CourseNode rootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode()).getCourseNode();
rootNode.setShortTitle(Formatter.truncate(courseShortTitle, 25));
rootNode.setLongTitle(courseLongTitle);
if (courseConfigVO != null) {
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
if (StringHelper.containsNonWhitespace(courseConfigVO.getSharedFolderSoftKey())) {
courseConfig.setSharedFolderSoftkey(courseConfigVO.getSharedFolderSoftKey());
}
if (courseConfigVO.getCalendar() != null) {
courseConfig.setCalendarEnabled(courseConfigVO.getCalendar().booleanValue());
}
if (courseConfigVO.getChat() != null) {
courseConfig.setChatIsEnabled(courseConfigVO.getChat().booleanValue());
}
if (courseConfigVO.getEfficencyStatement() != null) {
courseConfig.setEfficencyStatementIsEnabled(courseConfigVO.getEfficencyStatement().booleanValue());
}
if (StringHelper.containsNonWhitespace(courseConfigVO.getCssLayoutRef())) {
courseConfig.setCssLayoutRef(courseConfigVO.getCssLayoutRef());
}
if (StringHelper.containsNonWhitespace(courseConfigVO.getGlossarySoftkey())) {
courseConfig.setGlossarySoftKey(courseConfigVO.getGlossarySoftkey());
}
CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
return CourseFactory.loadCourse(addedEntry);
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class CoursesElementsTest method testUpdateRootNodeCoursePostWithFile.
@Test
public // fxdiff FXOLAT-122: course management
void testUpdateRootNodeCoursePostWithFile() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create an empty course
URI uri = getCoursesUri().queryParam("shortTitle", "course5").queryParam("title", "course5 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());
// the page
URL pageUrl = CoursesElementsTest.class.getResource("singlepage.html");
assertNotNull(pageUrl);
File page = new File(pageUrl.toURI());
// update the root node
URI rootUri = getElementsUri(course).path("structure").path(course.getEditorRootNodeId()).build();
HttpPost newStructureMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", page, ContentType.APPLICATION_OCTET_STREAM, page.getName()).addTextBody("filename", page.getName()).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "1").addTextBody("shortTitle", "Structure-0-with-file").addTextBody("longTitle", "Structure-long-0-with-file").addTextBody("objectives", "Structure-objectives-0-with-file").addTextBody("displayType", "file").build();
newStructureMethod.setEntity(entity);
HttpResponse newStructureCode = conn.execute(newStructureMethod);
assertTrue(newStructureCode.getStatusLine().getStatusCode() == 200 || newStructureCode.getStatusLine().getStatusCode() == 201);
// check the response
CourseNodeVO structureNode = conn.parse(newStructureCode, CourseNodeVO.class);
assertNotNull(structureNode);
assertNotNull(structureNode.getId());
assertEquals(structureNode.getShortTitle(), "Structure-0-with-file");
assertEquals(structureNode.getLongTitle(), "Structure-long-0-with-file");
assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0-with-file");
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-0-with-file");
assertEquals(rootNode.getCourseNode().getLongTitle(), "Structure-long-0-with-file");
assertEquals(rootNode.getCourseNode().getLearningObjectives(), "Structure-objectives-0-with-file");
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class PublishProcessTest method testPublishANotReallyNewNodeButDeleted.
/**
* Publish a course with a node marked as new and deleted but the
* node exists already in the run structure.
*
* @throws URISyntaxException
*/
@Test
public void testPublishANotReallyNewNodeButDeleted() throws URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
RepositoryEntry re = deployTestCourse("simple_course_err2_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 runNode2 = reloadedCourse.getRunStructure().getRootNode().getChildAt(0);
Assert.assertNotNull(runNode2);
CourseNode runNode2Impl = (CourseNode) runNode2;
Assert.assertEquals("Node 2", runNode2Impl.getShortTitle());
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class PublishProcessTest method testPublishANotPublishedNode.
/**
* Publish an unchanged course. We try to publish a node which
* was not changed nor deleted.
*
* @throws URISyntaxException
*/
@Test
public void testPublishANotPublishedNode() throws URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
RepositoryEntry re = deployTestCourse("simple_course.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);
}
use of org.olat.course.tree.CourseEditorTreeNode in project OpenOLAT by OpenOLAT.
the class PublishProcessTest method testPublishProcess.
/**
* Publish process without error
* @throws URISyntaxException
*/
@Test
public void testPublishProcess() throws URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAdmin("publisher-" + UUID.randomUUID().toString());
RepositoryEntry re = deployTestCourse("simple_course.zip");
// change node 1
ICourse course = CourseFactory.openCourseEditSession(re.getOlatResource().getResourceableId());
CourseEditorTreeModel cetm = course.getEditorTreeModel();
CourseEditorTreeNode node1 = (CourseEditorTreeNode) cetm.getRootNode().getChildAt(0);
node1.getCourseNode().setShortTitle("Node 1 prime");
cetm.nodeConfigChanged(node1);
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
// publish the course
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 prime", runNode1Impl.getShortTitle());
}
Aggregations