Search in sources :

Example 6 with CourseNodeVO

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

Example 7 with CourseNodeVO

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;
}
Also used : Condition(org.olat.course.condition.Condition) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) ICourse(org.olat.course.ICourse) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode)

Example 8 with CourseNodeVO

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);
}
Also used : CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 9 with CourseNodeVO

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");
}
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 10 with CourseNodeVO

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");
}
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

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