Search in sources :

Example 56 with CourseVO

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

the class CoursesWebService method getCourseList.

/**
 * Get all courses viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json, application/json;pagingspec=1.0
 * @response.representation.200.doc List of visible courses
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEVOes}
 * @param start
 * @param limit
 * @param externalId Search with an external ID
 * @param externalRef Search with an external reference
 * @param managed (true / false) Search only managed / not managed groups
 * @param httpRequest The HTTP request
 * @param request The REST request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("managed") Boolean managed, @QueryParam("externalId") String externalId, @QueryParam("externalRef") String externalRef, @QueryParam("repositoryEntryKey") String repositoryEntryKey, @Context HttpServletRequest httpRequest, @Context Request request) {
    RepositoryManager rm = RepositoryManager.getInstance();
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
    params.setManaged(managed);
    if (StringHelper.containsNonWhitespace(externalId)) {
        params.setExternalId(externalId);
    }
    if (StringHelper.containsNonWhitespace(externalRef)) {
        params.setExternalRef(externalRef);
    }
    if (StringHelper.containsNonWhitespace(repositoryEntryKey) && StringHelper.isLong(repositoryEntryKey)) {
        try {
            params.setRepositoryEntryKeys(Collections.singletonList(new Long(repositoryEntryKey)));
        } catch (NumberFormatException e) {
            log.error("Cannot parse the following repository entry key: " + repositoryEntryKey);
        }
    }
    if (MediaTypeVariants.isPaged(httpRequest, request)) {
        int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
        CourseVO[] vos = toCourseVo(repoEntries);
        CourseVOes voes = new CourseVOes();
        voes.setCourses(vos);
        voes.setTotalCount(totalCount);
        return Response.ok(voes).build();
    } else {
        List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, 0, -1, false);
        CourseVO[] vos = toCourseVo(repoEntries);
        return Response.ok(vos).build();
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) CourseVO(org.olat.restapi.support.vo.CourseVO) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) CourseVOes(org.olat.restapi.support.vo.CourseVOes) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 57 with CourseVO

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

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

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

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

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

the class CoursesTest method testCopyCourse.

@Test
public void testCopyCourse() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-5");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
    Assert.assertNotNull(entry);
    conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "Course copy").queryParam("title", "Course copy").queryParam("initialAuthor", author.getKey().toString()).queryParam("copyFrom", entry.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    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());
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 60 with CourseVO

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

the class CoursesTest method testGetCourses_notManaged.

@Test
public void testGetCourses_notManaged() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("managed", "false").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<CourseVO> courses = parseCourseArray(body);
    assertNotNull(courses);
    assertTrue(courses.size() >= 1);
    for (CourseVO course : courses) {
        boolean managed = StringHelper.containsNonWhitespace(course.getManagedFlags());
        Assert.assertFalse(managed);
    }
}
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) 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