Search in sources :

Example 41 with CourseVO

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();
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CourseVO(org.olat.restapi.support.vo.CourseVO) ICourse(org.olat.course.ICourse) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 42 with CourseVO

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

Example 43 with CourseVO

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()));
}
Also used : RepositoryRestClient(org.olat.test.rest.RepositoryRestClient) CourseVO(org.olat.restapi.support.vo.CourseVO) UserToolsPage(org.olat.selenium.page.user.UserToolsPage) UserVO(org.olat.user.restapi.UserVO) CoursePageFragment(org.olat.selenium.page.course.CoursePageFragment) WebElement(org.openqa.selenium.WebElement) UserRestClient(org.olat.test.rest.UserRestClient) Test(org.junit.Test)

Example 44 with CourseVO

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()));
}
Also used : RepositoryRestClient(org.olat.test.rest.RepositoryRestClient) CourseVO(org.olat.restapi.support.vo.CourseVO) UserToolsPage(org.olat.selenium.page.user.UserToolsPage) UserVO(org.olat.user.restapi.UserVO) WebElement(org.openqa.selenium.WebElement) UserRestClient(org.olat.test.rest.UserRestClient) Test(org.junit.Test)

Example 45 with CourseVO

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

Aggregations

CourseVO (org.olat.restapi.support.vo.CourseVO)70 Test (org.junit.Test)48 URI (java.net.URI)46 HttpResponse (org.apache.http.HttpResponse)46 RepositoryEntry (org.olat.repository.RepositoryEntry)34 HttpGet (org.apache.http.client.methods.HttpGet)26 ICourse (org.olat.course.ICourse)26 Identity (org.olat.core.id.Identity)20 InputStream (java.io.InputStream)18 Produces (javax.ws.rs.Produces)16 HttpEntity (org.apache.http.HttpEntity)16 HttpPut (org.apache.http.client.methods.HttpPut)16 File (java.io.File)14 HttpPost (org.apache.http.client.methods.HttpPost)14 CourseVOes (org.olat.restapi.support.vo.CourseVOes)14 URL (java.net.URL)12 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 UserRequest (org.olat.core.gui.UserRequest)8 RepositoryManager (org.olat.repository.RepositoryManager)8