use of org.olat.restapi.support.vo.CourseNodeVO in project OpenOLAT by OpenOLAT.
the class AbstractCourseNodeWebService method attach.
protected Response attach(Long courseId, String parentNodeId, String nodeId, String type, Integer position, String shortTitle, String longTitle, String objectives, String visibilityExpertRules, String accessExpertRules, CustomConfigDelegate config, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (config != null && !config.isValid()) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseEditSession editSession = null;
try {
editSession = openEditSession(course, getIdentity(request));
if (!editSession.canEdit()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNodeVO node;
if (nodeId != null) {
node = updateCourseNode(nodeId, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, editSession);
} else {
CourseNode parentNode = getParentNode(course, parentNodeId);
if (parentNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
node = createCourseNode(type, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, editSession, parentNode, position);
}
return Response.ok(node).build();
} catch (Exception ex) {
log.error("Error while adding an enrolment building block", ex);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
saveAndCloseCourse(editSession);
}
}
use of org.olat.restapi.support.vo.CourseNodeVO in project OpenOLAT by OpenOLAT.
the class AbstractCourseNodeWebService method createCourseNode.
private CourseNodeVO createCourseNode(String type, String shortTitle, String longTitle, String learningObjectives, String visibilityExpertRules, String accessExpertRules, CustomConfigDelegate delegateConfig, CourseEditSession editSession, CourseNode parentNode, Integer position) {
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
CourseNode insertedNode = newNodeConfig.getInstance();
insertedNode.setShortTitle(shortTitle);
insertedNode.setLongTitle(longTitle);
insertedNode.setLearningObjectives(learningObjectives);
insertedNode.setNoAccessExplanation("You don't have access");
if (StringHelper.containsNonWhitespace(visibilityExpertRules)) {
Condition cond = this.createExpertCondition(CONDITION_ID_VISIBILITY, visibilityExpertRules);
insertedNode.setPreConditionVisibility(cond);
}
if (StringHelper.containsNonWhitespace(accessExpertRules) && insertedNode instanceof AbstractAccessableCourseNode) {
Condition cond = createExpertCondition(CONDITION_ID_ACCESS, accessExpertRules);
((AbstractAccessableCourseNode) insertedNode).setPreConditionAccess(cond);
}
ICourse course = editSession.getCourse();
if (delegateConfig != null) {
ModuleConfiguration moduleConfig = insertedNode.getModuleConfiguration();
delegateConfig.configure(course, insertedNode, moduleConfig);
}
if (position == null || position.intValue() < 0) {
course.getEditorTreeModel().addCourseNode(insertedNode, parentNode);
} else {
course.getEditorTreeModel().insertCourseNodeAt(insertedNode, parentNode, position);
}
CourseEditorTreeNode editorNode = course.getEditorTreeModel().getCourseEditorNodeContaining(insertedNode);
CourseNodeVO vo = get(insertedNode);
vo.setParentId(editorNode.getParent() == null ? null : editorNode.getParent().getIdent());
return vo;
}
use of org.olat.restapi.support.vo.CourseNodeVO in project openolat by klemens.
the class CoursesContactElementTest method testBareBoneConfig.
@Test
public void testBareBoneConfig() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create an contact node
URI newContactUri = getElementsUri(course1).path("contact").queryParam("parentNodeId", rootNodeId).queryParam("position", "0").queryParam("shortTitle", "Contact-0").queryParam("longTitle", "Contact-long-0").queryParam("objectives", "Contact-objectives-0").build();
HttpPut method = conn.createPut(newContactUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseNodeVO contactNode = conn.parse(response, CourseNodeVO.class);
assertNotNull(contactNode);
assertNotNull(contactNode.getId());
assertEquals(contactNode.getShortTitle(), "Contact-0");
assertEquals(contactNode.getLongTitle(), "Contact-long-0");
assertEquals(contactNode.getLearningObjectives(), "Contact-objectives-0");
assertEquals(contactNode.getParentId(), rootNodeId);
}
use of org.olat.restapi.support.vo.CourseNodeVO in project openolat by klemens.
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.restapi.support.vo.CourseNodeVO in project openolat by klemens.
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");
}
Aggregations