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();
}
}
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;
}
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();
}
}
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());
}
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);
}
}
Aggregations