Search in sources :

Example 16 with CourseNodeVO

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();
}
Also used : CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AbstractFeedCourseNode(org.olat.course.nodes.AbstractFeedCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with CourseNodeVO

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;
}
Also used : CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO)

Example 18 with CourseNodeVO

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");
}
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) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) URL(java.net.URL) Test(org.junit.Test)

Example 19 with CourseNodeVO

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");
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) 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) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) List(java.util.List) CourseNode(org.olat.course.nodes.CourseNode) Test(org.junit.Test)

Example 20 with CourseNodeVO

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;
}
Also used : CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO)

Aggregations

CourseNodeVO (org.olat.restapi.support.vo.CourseNodeVO)22 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)12 HttpResponse (org.apache.http.HttpResponse)12 HttpPut (org.apache.http.client.methods.HttpPut)12 Test (org.junit.Test)12 CourseNode (org.olat.course.nodes.CourseNode)12 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)12 HttpEntity (org.apache.http.HttpEntity)8 CourseVO (org.olat.restapi.support.vo.CourseVO)8 File (java.io.File)6 URL (java.net.URL)6 HttpPost (org.apache.http.client.methods.HttpPost)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)6 ModuleConfiguration (org.olat.modules.ModuleConfiguration)6 Condition (org.olat.course.condition.Condition)4 IQSURVCourseNode (org.olat.course.nodes.IQSURVCourseNode)4 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)4 MSCourseNode (org.olat.course.nodes.MSCourseNode)4