use of org.olat.restapi.support.vo.CourseInfoVO in project OpenOLAT by OpenOLAT.
the class CoursesInfosTest method testGetCourseInfos_byId.
@Test
public void testGetCourseInfos_byId() throws IOException, URISyntaxException {
Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
ICourse course = CoursesWebService.createEmptyCourse(admin, "course-info 1", "course long name", null);
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = conn.getContextURI().path("repo").path("courses").path("infos").path(course.getResourceableId().toString()).build();
HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseInfoVO infos = conn.parse(response, CourseInfoVO.class);
Assert.assertNotNull(infos);
Assert.assertEquals("course-info 1", infos.getTitle());
Assert.assertEquals("course-info 1", infos.getDisplayName());
conn.shutdown();
}
use of org.olat.restapi.support.vo.CourseInfoVO in project OpenOLAT by OpenOLAT.
the class CoursesInfosWebService method getCourseInfo.
/**
* Get course informations viewable by the authenticated user
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Course informations
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVO}
* @param courseId The course id
* @param httpRequest The HTTP request
* @return
*/
@GET
@Path("{courseId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfo(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
if (identity != null && roles != null) {
Set<Long> forumNotified = new HashSet<Long>();
Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
collectSubscriptions(identity, forumNotified, courseNotified);
ICourse course = CourseFactory.loadCourse(courseId);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
return Response.ok(info).build();
} else {
return Response.serverError().status(Status.FORBIDDEN).build();
}
}
use of org.olat.restapi.support.vo.CourseInfoVO in project openolat by klemens.
the class CoursesInfosTest method testGetCourseInfos_byId.
@Test
public void testGetCourseInfos_byId() throws IOException, URISyntaxException {
Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
ICourse course = CoursesWebService.createEmptyCourse(admin, "course-info 1", "course long name", null);
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI uri = conn.getContextURI().path("repo").path("courses").path("infos").path(course.getResourceableId().toString()).build();
HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(get);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseInfoVO infos = conn.parse(response, CourseInfoVO.class);
Assert.assertNotNull(infos);
Assert.assertEquals("course-info 1", infos.getTitle());
Assert.assertEquals("course-info 1", infos.getDisplayName());
conn.shutdown();
}
use of org.olat.restapi.support.vo.CourseInfoVO in project openolat by klemens.
the class CoursesInfosWebService method collect.
private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
CourseInfoVO info = new CourseInfoVO();
info.setRepoEntryKey(entry.getKey());
info.setSoftKey(entry.getSoftkey());
info.setDisplayName(entry.getDisplayname());
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
AccessResult result = acManager.isAccessible(entry, identity, false);
if (result.isAccessible()) {
try {
final ICourse course = CourseFactory.loadCourse(entry);
final List<FolderVO> folders = new ArrayList<FolderVO>();
final List<ForumVO> forums = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
} else if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
}
}
}, new VisibleTreeFilter());
info.setKey(course.getResourceableId());
info.setTitle(course.getCourseTitle());
info.setFolders(folders.toArray(new FolderVO[folders.size()]));
info.setForums(forums.toArray(new ForumVO[forums.size()]));
} catch (Exception e) {
log.error("", e);
}
}
return info;
}
use of org.olat.restapi.support.vo.CourseInfoVO in project openolat by klemens.
the class CoursesInfosWebService method getCourseInfo.
/**
* Get course informations viewable by the authenticated user
* @response.representation.200.qname {http://www.example.com}courseVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Course informations
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVO}
* @param courseId The course id
* @param httpRequest The HTTP request
* @return
*/
@GET
@Path("{courseId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfo(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
if (identity != null && roles != null) {
Set<Long> forumNotified = new HashSet<Long>();
Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
collectSubscriptions(identity, forumNotified, courseNotified);
ICourse course = CourseFactory.loadCourse(courseId);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
return Response.ok(info).build();
} else {
return Response.serverError().status(Status.FORBIDDEN).build();
}
}
Aggregations