use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesWebService method createEmptyCourse.
/**
* Creates an empty 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
* @param courseVo The course
* @param request The HTTP request
* @return It returns the newly created course
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(CourseVO courseVo, @Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
UserRequest ureq = getUserRequest(request);
CourseConfigVO configVO = new CourseConfigVO();
ICourse course = createEmptyCourse(ureq.getIdentity(), courseVo.getTitle(), courseVo.getTitle(), courseVo.getTitle(), courseVo.getDescription(), courseVo.getSoftKey(), RepositoryEntry.ACC_OWNERS, false, courseVo.getAuthors(), courseVo.getLocation(), courseVo.getExternalId(), courseVo.getExternalRef(), courseVo.getManagedFlags(), configVO);
CourseVO vo = ObjectFactory.get(course);
return Response.ok(vo).build();
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class ObjectFactory method get.
public static CourseVO get(RepositoryEntry re, ICourse course) {
CourseVO vo = new CourseVO();
vo.setKey(course.getResourceableId());
vo.setDisplayName(re.getDisplayname());
vo.setDescription(re.getDescription());
vo.setTitle(course.getCourseTitle());
vo.setEditorRootNodeId(course.getEditorTreeModel().getRootNode().getIdent());
vo.setSoftKey(re.getSoftkey());
vo.setRepoEntryKey(re.getKey());
OLATResource resource = re.getOlatResource();
if (resource != null) {
vo.setOlatResourceKey(resource.getKey());
vo.setOlatResourceId(resource.getResourceableId());
vo.setOlatResourceTypeName(resource.getResourceableTypeName());
}
vo.setAuthors(re.getAuthors());
vo.setLocation(re.getLocation());
vo.setExternalId(re.getExternalId());
vo.setExternalRef(re.getExternalRef());
vo.setManagedFlags(re.getManagedFlagsString());
if (re.getLifecycle() != null) {
vo.setLifecycle(new RepositoryEntryLifecycleVO(re.getLifecycle()));
}
return vo;
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
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()));
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class UserTest method resumeCourseOnDemand.
/**
* Set the resume preferences to resume the session on request,
* open a course, log out, log in, resume the session and check
* if the course is resumed.
*
* @param loginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void resumeCourseOnDemand(@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.loginAs(user.getLogin(), user.getPassword());
// set the preferences to resume automatically
UserToolsPage userTools = new UserToolsPage(browser);
userTools.openUserToolsMenu().openMySettings().openPreferences().setResume(ResumeOption.ondemand);
// open a course via REST url and click it
CoursePageFragment.getCourse(browser, deploymentUrl, course).clickTree();
// logout
userTools.logout();
// login again
loginPage.assertOnLoginPage().loginAs(user.getLogin(), user.getPassword());
// resume
loginPage.resumeWithAssert();
// 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()));
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
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());
}
Aggregations