use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CourseTest method testGetCourse.
@Test
public void testGetCourse() throws IOException, URISyntaxException {
assertTrue("Cannot login as administrator", conn.login("administrator", "openolat"));
URI uri = conn.getContextURI().path("repo").path("courses").path(course1.getResourceableId().toString()).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseVO course = conn.parse(response, CourseVO.class);
assertNotNull(course);
assertEquals(course1.getResourceableId(), course.getKey());
assertEquals(course1.getCourseTitle(), course.getTitle());
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CoursesElementsTest method testCreateCoursePost.
@Test
public void testCreateCoursePost() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create an empty course
URI uri = getCoursesUri().queryParam("shortTitle", "course3").queryParam("title", "course3 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());
// create an structure node
URI newStructureUri = getElementsUri(course).path("structure").build();
HttpPost newStructureMethod = conn.createPost(newStructureUri, MediaType.APPLICATION_JSON);
HttpEntity newStructureEnttiy = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "0").addTextBody("shortTitle", "Structure-0").addTextBody("longTitle", "Structure-long-0").addTextBody("objectives", "Structure-objectives-0").build();
newStructureMethod.setEntity(newStructureEnttiy);
HttpResponse newStructureResponse = conn.execute(newStructureMethod);
int newStructureCode = newStructureResponse.getStatusLine().getStatusCode();
assertTrue(newStructureCode == 200 || newStructureCode == 201);
CourseNodeVO structureNode = conn.parse(newStructureResponse, CourseNodeVO.class);
assertNotNull(structureNode);
assertNotNull(structureNode.getId());
assertEquals(structureNode.getShortTitle(), "Structure-0");
assertEquals(structureNode.getLongTitle(), "Structure-long-0");
assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0");
assertEquals(structureNode.getParentId(), course.getEditorRootNodeId());
// create single page
URL pageUrl = CoursesElementsTest.class.getResource("singlepage.html");
assertNotNull(pageUrl);
File page = new File(pageUrl.toURI());
URI newPageUri = getElementsUri(course).path("singlepage").build();
HttpPost newPageMethod = conn.createPost(newPageUri, 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", "Single-Page-0").addTextBody("longTitle", "Single-Page-long-0").addTextBody("objectives", "Single-Page-objectives-0").build();
newPageMethod.setEntity(entity);
HttpResponse newPageCode = conn.execute(newPageMethod);
assertTrue(newPageCode.getStatusLine().getStatusCode() == 200 || newPageCode.getStatusLine().getStatusCode() == 201);
CourseNodeVO pageNode = conn.parse(newPageCode, CourseNodeVO.class);
assertNotNull(pageNode);
assertNotNull(pageNode.getId());
assertEquals(pageNode.getShortTitle(), "Single-Page-0");
assertEquals(pageNode.getLongTitle(), "Single-Page-long-0");
assertEquals(pageNode.getLearningObjectives(), "Single-Page-objectives-0");
assertEquals(structureNode.getParentId(), course.getEditorRootNodeId());
// create a folder node
URI newFolderUri = getElementsUri(course).path("folder").build();
HttpPost newFolderMethod = conn.createPost(newFolderUri, MediaType.APPLICATION_JSON);
String rule = "hasLanguage(\"de\")";
conn.addEntity(newFolderMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "2"), new BasicNameValuePair("shortTitle", "Folder-0"), new BasicNameValuePair("longTitle", "Folder-long-0"), new BasicNameValuePair("objectives", "Folder-objectives-0"), new BasicNameValuePair("visibilityExpertRules", rule), new BasicNameValuePair("downloadExpertRules", rule), new BasicNameValuePair("uploadExpertRules", rule));
HttpResponse newFolderCode = conn.execute(newFolderMethod);
assertTrue(newFolderCode.getStatusLine().getStatusCode() == 200 || newFolderCode.getStatusLine().getStatusCode() == 201);
CourseNodeVO folderNode = conn.parse(newFolderCode, CourseNodeVO.class);
assertNotNull(folderNode);
assertNotNull(folderNode.getId());
assertEquals(folderNode.getShortTitle(), "Folder-0");
assertEquals(folderNode.getLongTitle(), "Folder-long-0");
assertEquals(folderNode.getLearningObjectives(), "Folder-objectives-0");
assertEquals(folderNode.getParentId(), course.getEditorRootNodeId());
// create a forum node
URI newForumUri = getElementsUri(course).path("forum").build();
HttpPost newForumMethod = conn.createPost(newForumUri, MediaType.APPLICATION_JSON);
conn.addEntity(newForumMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "3"), new BasicNameValuePair("shortTitle", "Forum-0"), new BasicNameValuePair("longTitle", "Forum-long-0"), new BasicNameValuePair("objectives", "Forum-objectives-0"));
HttpResponse newForumCode = conn.execute(newForumMethod);
assertTrue(newForumCode.getStatusLine().getStatusCode() == 200 || newForumCode.getStatusLine().getStatusCode() == 201);
CourseNodeVO forumNode = conn.parse(newForumCode, CourseNodeVO.class);
assertNotNull(forumNode);
assertNotNull(forumNode.getId());
assertEquals(forumNode.getShortTitle(), "Forum-0");
assertEquals(forumNode.getLongTitle(), "Forum-long-0");
assertEquals(forumNode.getLearningObjectives(), "Forum-objectives-0");
assertEquals(forumNode.getParentId(), course.getEditorRootNodeId());
// create a task node
URI newTaskUri = getElementsUri(course).path("task").build();
HttpPost newTaskMethod = conn.createPost(newTaskUri, MediaType.APPLICATION_JSON);
conn.addEntity(newTaskMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "4"), new BasicNameValuePair("shortTitle", "Task-0"), new BasicNameValuePair("longTitle", "Task-long-0"), new BasicNameValuePair("objectives", "Task-objectives-0"), new BasicNameValuePair("points", "25"), new BasicNameValuePair("text", "A very difficult test"));
HttpResponse newTaskCode = conn.execute(newTaskMethod);
assertTrue(newTaskCode.getStatusLine().getStatusCode() == 200 || newTaskCode.getStatusLine().getStatusCode() == 201);
CourseNodeVO taskNode = conn.parse(newTaskCode, CourseNodeVO.class);
assertNotNull(taskNode);
assertNotNull(taskNode.getId());
assertEquals(taskNode.getShortTitle(), "Task-0");
assertEquals(taskNode.getLongTitle(), "Task-long-0");
assertEquals(taskNode.getLearningObjectives(), "Task-objectives-0");
assertEquals(taskNode.getParentId(), course.getEditorRootNodeId());
// create a test node
URI newTestUri = getElementsUri(course).path("test").build();
HttpPost newTestMethod = conn.createPost(newTestUri, MediaType.APPLICATION_JSON);
conn.addEntity(newTestMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("testResourceableId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "5"), new BasicNameValuePair("shortTitle", "Test-0"), new BasicNameValuePair("longTitle", "Test-long-0"), new BasicNameValuePair("objectives", "Test-objectives-0"));
HttpResponse newTestCode = conn.execute(newTestMethod);
// must bind a real test
assertTrue(newTestCode.getStatusLine().getStatusCode() == 404);
EntityUtils.consume(newTestCode.getEntity());
/*
assertTrue(newTestCode == 200 || newTestCode == 201);
String newTestBody = newTestMethod.getResponseBodyAsString();
CourseNodeVO testNode = parse(newTestBody, CourseNodeVO.class);
assertNotNull(testNode);
assertNotNull(testNode.getId());
assertEquals(testNode.getShortTitle(), "Test-0");
assertEquals(testNode.getParentId(), course.getEditorRootNodeId());
*/
// create an assessment node
URI newAssessmentUri = getElementsUri(course).path("assessment").build();
HttpPost newAssessmentMethod = conn.createPost(newAssessmentUri, MediaType.APPLICATION_JSON);
conn.addEntity(newAssessmentMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "5"), new BasicNameValuePair("shortTitle", "Assessment-0"), new BasicNameValuePair("longTitle", "Assessment-long-0"), new BasicNameValuePair("objectives", "Assessment-objectives-0"));
HttpResponse newAssessmentCode = conn.execute(newAssessmentMethod);
assertTrue(newAssessmentCode.getStatusLine().getStatusCode() == 200 || newAssessmentCode.getStatusLine().getStatusCode() == 201);
CourseNodeVO assessmentNode = conn.parse(newAssessmentCode, CourseNodeVO.class);
assertNotNull(assessmentNode);
assertNotNull(assessmentNode.getId());
assertEquals(assessmentNode.getShortTitle(), "Assessment-0");
assertEquals(assessmentNode.getLongTitle(), "Assessment-long-0");
assertEquals(assessmentNode.getLearningObjectives(), "Assessment-objectives-0");
assertEquals(assessmentNode.getParentId(), course.getEditorRootNodeId());
// create an contact node
URI newContactUri = getElementsUri(course).path("contact").build();
HttpPost newContactMethod = conn.createPost(newContactUri, MediaType.APPLICATION_JSON);
conn.addEntity(newContactMethod, new BasicNameValuePair("parentNodeId", course.getEditorRootNodeId()), new BasicNameValuePair("position", "6"), new BasicNameValuePair("shortTitle", "Contact-0"), new BasicNameValuePair("longTitle", "Contact-long-0"), new BasicNameValuePair("objectives", "Contact-objectives-0"));
HttpResponse newContactCode = conn.execute(newContactMethod);
assertEquals(200, newContactCode.getStatusLine().getStatusCode());
CourseNodeVO contactNode = conn.parse(newContactCode, 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(), course.getEditorRootNodeId());
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class RepositoryRestClient method deployCourse.
public CourseVO deployCourse(File archive, String resourcename, String displayname) throws URISyntaxException, IOException {
RestConnection conn = new RestConnection(deploymentUrl);
assertTrue(conn.login(username, password));
URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("repo/courses").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
String softKey = UUID.randomUUID().toString();
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", archive, ContentType.APPLICATION_OCTET_STREAM, archive.getName()).addTextBody("filename", archive.getName()).addTextBody("resourcename", resourcename).addTextBody("displayname", displayname).addTextBody("access", "3").addTextBody("softkey", softKey).build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
assertNotNull(vo);
assertNotNull(vo.getRepoEntryKey());
assertNotNull(vo.getKey());
return vo;
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CourseWebService method publishCourse.
/**
* Publish the course.
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The metadatas of the created course
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param locale The course locale
* @param request The HTTP request
* @return It returns the metadatas of the published course.
*/
@POST
@Path("publish")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response publishCourse(@QueryParam("locale") Locale locale, @QueryParam("access") Integer access, @QueryParam("membersOnly") Boolean membersOnly, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
if (!isAuthorEditor(course, request) && !isInstitutionalResourceManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
int newAccess = access == null ? RepositoryEntry.ACC_USERS : access.intValue();
boolean members = membersOnly == null ? false : membersOnly.booleanValue();
CourseFactory.publishCourse(course, newAccess, members, ureq.getIdentity(), locale);
CourseVO vo = ObjectFactory.get(course);
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class UserTest method resumeCourseAutomatically.
/**
* Set the resume preferences to automatically resume the session,
* open a course, log out, log in and check if the course is resumed.
*
* @param loginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void resumeCourseAutomatically(@InitialPage LoginPage loginPage) throws IOException, URISyntaxException {
// create a random user
UserVO user = new UserRestClient(deploymentUrl).createRandomUser();
// deploy a course
CourseVO course = new RepositoryRestClient(deploymentUrl).deployDemoCourse();
// login
loginPage.assertOnLoginPage().loginAs(user.getLogin(), user.getPassword());
// set the preferences to resume automatically
UserToolsPage userTools = new UserToolsPage(browser);
userTools.openUserToolsMenu().openMySettings().assertOnUserSettings().openPreferences().assertOnUserPreferences().setResume(ResumeOption.auto);
// open a course via REST url
CoursePageFragment coursePage = CoursePageFragment.getCourse(browser, deploymentUrl, course);
coursePage.assertOnCoursePage().clickTree();
// logout
userTools.logout();
// login again
loginPage.assertOnLoginPage().loginAs(user.getLogin(), user.getPassword());
// check the title of the course if any
WebElement courseTitle = browser.findElement(By.tagName("h2"));
Assert.assertNotNull(courseTitle);
Assert.assertTrue(courseTitle.isDisplayed());
Assert.assertTrue(courseTitle.getText().contains(course.getTitle()));
}
Aggregations