Search in sources :

Example 16 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.

the class UserCoursesWebService method getMyCourses.

/**
 * Retrieves the list of "My entries" but limited to courses.
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param start The first result
 * @param limit Max result
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return The list of my entries
 */
@GET
@Path("my")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getMyCourses(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsStudent(identity, null, start, limit, RepositoryEntryOrder.nameAsc);
        int totalCount = rm.countLearningResourcesAsStudent(identity);
        CourseVO[] vos = toCourseVo(repoEntries);
        CourseVOes voes = new CourseVOes();
        voes.setCourses(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsStudent(identity, null, 0, -1, RepositoryEntryOrder.nameAsc);
        CourseVO[] vos = toCourseVo(repoEntries);
        return Response.ok(vos).build();
    }
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.

the class UserCoursesWebService method getTeachedCourses.

/**
 * Retrieves the list of "My supervised courses" but limited to courses.
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param start The first result
 * @param limit Max result
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return The list of my supervised entries
 */
@GET
@Path("teached")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTeachedCourses(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsTeacher(identity, start, limit, RepositoryEntryOrder.nameAsc);
        int totalCount = rm.countLearningResourcesAsTeacher(identity);
        CourseVO[] vos = toCourseVo(repoEntries);
        CourseVOes voes = new CourseVOes();
        voes.setCourses(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        List<RepositoryEntry> repoEntries = rm.getLearningResourcesAsTeacher(identity, 0, -1);
        CourseVO[] vos = toCourseVo(repoEntries);
        return Response.ok(vos).build();
    }
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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 19 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

the class UserCoursesTest method testMyCourses.

@Test
public void testMyCourses() throws IOException, URISyntaxException {
    // prepare a course with a participant
    Identity user = JunitTestHelper.createAndPersistIdentityAsUser("My-course-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(user, "My course 1", "My course", null);
    RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(course, true);
    repositoryManager.setAccess(courseRe, RepositoryEntry.ACC_OWNERS, true);
    repositoryService.addRole(user, courseRe, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login(user.getName(), JunitTestHelper.PWD));
    // without paging
    URI request = UriBuilder.fromUri(getContextURI()).path("/users").path(user.getKey().toString()).path("/courses/my").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<CourseVO> courses = parseCourseArray(body);
    Assert.assertNotNull(courses);
    Assert.assertEquals(1, courses.size());
    // with paging
    URI pagedRequest = UriBuilder.fromUri(getContextURI()).path("/users").path(user.getKey().toString()).path("/courses/my").queryParam("start", "0").queryParam("limit", "10").build();
    HttpGet pagedMethod = conn.createGet(pagedRequest, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse pagedResponse = conn.execute(pagedMethod);
    Assert.assertEquals(200, pagedResponse.getStatusLine().getStatusCode());
    InputStream pagedBody = pagedResponse.getEntity().getContent();
    CourseVOes pagedCourses = conn.parse(pagedBody, CourseVOes.class);
    Assert.assertNotNull(pagedCourses);
    Assert.assertEquals(1, pagedCourses.getTotalCount());
    Assert.assertNotNull(pagedCourses.getCourses());
    Assert.assertEquals(1, pagedCourses.getCourses().length);
    conn.shutdown();
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 20 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

the class UserCoursesTest method testFavoritCourses.

@Test
public void testFavoritCourses() throws IOException, URISyntaxException {
    // prepare a course with a tutor
    Identity me = JunitTestHelper.createAndPersistIdentityAsUser("Course-teacher-" + UUID.randomUUID().toString());
    ICourse course = CoursesWebService.createEmptyCourse(me, "A course to teach", "A course to teach", null);
    RepositoryEntry courseRe = repositoryManager.lookupRepositoryEntry(course, true);
    repositoryManager.setAccess(courseRe, RepositoryEntry.ACC_USERS, false);
    markManager.setMark(courseRe, me, null, "[RepositoryEntry:" + courseRe.getKey() + "]");
    dbInstance.commitAndCloseSession();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login(me.getName(), JunitTestHelper.PWD));
    // without paging
    URI request = UriBuilder.fromUri(getContextURI()).path("/users").path(me.getKey().toString()).path("/courses/favorite").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<CourseVO> courses = parseCourseArray(body);
    Assert.assertNotNull(courses);
    Assert.assertEquals(1, courses.size());
    // with paging
    URI pagedRequest = UriBuilder.fromUri(getContextURI()).path("/users").path(me.getKey().toString()).path("/courses/favorite").queryParam("start", "0").queryParam("limit", "10").build();
    HttpGet pagedMethod = conn.createGet(pagedRequest, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse pagedResponse = conn.execute(pagedMethod);
    Assert.assertEquals(200, pagedResponse.getStatusLine().getStatusCode());
    InputStream pagedBody = pagedResponse.getEntity().getContent();
    CourseVOes pagedCourses = conn.parse(pagedBody, CourseVOes.class);
    Assert.assertNotNull(pagedCourses);
    Assert.assertEquals(1, pagedCourses.getTotalCount());
    Assert.assertNotNull(pagedCourses.getCourses());
    Assert.assertEquals(1, pagedCourses.getCourses().length);
    conn.shutdown();
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) 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