use of org.olat.restapi.support.vo.CourseNodeVO in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method getCourseNode.
/**
* Retrieves metadata of the course node
* @response.representation.200.qname {http://www.example.com}courseNodeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id
* @param request The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseNode(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CourseNode courseNode = getParentNode(course, nodeId);
if (courseNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CourseNodeVO vo = ObjectFactory.get(courseNode);
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CourseNodeVO in project OpenOLAT by OpenOLAT.
the class ObjectFactory method get.
public static CourseNodeVO get(CourseNode node) {
CourseNodeVO vo = new CourseNodeVO();
vo.setId(node.getIdent());
vo.setPosition(node.getPosition());
vo.setParentId(node.getParent() == null ? null : node.getParent().getIdent());
vo.setShortTitle(node.getShortTitle());
vo.setShortName(node.getShortName());
vo.setLongTitle(node.getLongTitle());
vo.setLearningObjectives(node.getLearningObjectives());
return vo;
}
use of org.olat.restapi.support.vo.CourseNodeVO 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.restapi.support.vo.CourseNodeVO in project OpenOLAT by OpenOLAT.
the class CoursesContactElementTest method testFullConfig.
@Test
public void testFullConfig() 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-1").queryParam("longTitle", "Contact-long-1").queryParam("objectives", "Contact-objectives-1").queryParam("coaches", "true").queryParam("participants", "true").queryParam("groups", "").queryParam("areas", "").queryParam("to", "test@frentix.com;test2@frentix.com").queryParam("defaultSubject", "Hello by contact 1").queryParam("defaultBody", "Hello by contact 1 body").build();
HttpPut method = conn.createPut(newContactUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
// check the return values
assertEquals(200, response.getStatusLine().getStatusCode());
CourseNodeVO contactNode = conn.parse(response, CourseNodeVO.class);
assertNotNull(contactNode);
assertNotNull(contactNode.getId());
// check the persisted value
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
TreeNode node = course.getEditorTreeModel().getNodeById(contactNode.getId());
assertNotNull(node);
CourseEditorTreeNode editorCourseNode = (CourseEditorTreeNode) node;
CourseNode courseNode = editorCourseNode.getCourseNode();
ModuleConfiguration config = courseNode.getModuleConfiguration();
assertNotNull(config);
assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOCOACHES), true);
assertEquals(config.getBooleanEntry(CONFIG_KEY_EMAILTOPARTICIPANTS), true);
@SuppressWarnings("unchecked") List<String> tos = (List<String>) config.get(CONFIG_KEY_EMAILTOADRESSES);
assertNotNull(tos);
assertEquals(2, tos.size());
assertEquals(config.get(CONFIG_KEY_MSUBJECT_DEFAULT), "Hello by contact 1");
assertEquals(config.get(CONFIG_KEY_MBODY_DEFAULT), "Hello by contact 1 body");
}
use of org.olat.restapi.support.vo.CourseNodeVO in project openolat by klemens.
the class ObjectFactory method get.
public static CourseNodeVO get(CourseNode node) {
CourseNodeVO vo = new CourseNodeVO();
vo.setId(node.getIdent());
vo.setPosition(node.getPosition());
vo.setParentId(node.getParent() == null ? null : node.getParent().getIdent());
vo.setShortTitle(node.getShortTitle());
vo.setShortName(node.getShortName());
vo.setLongTitle(node.getLongTitle());
vo.setLearningObjectives(node.getLearningObjectives());
return vo;
}
Aggregations