use of org.olat.restapi.support.vo.CourseInfoVO in project OpenOLAT by OpenOLAT.
the class CoursesInfosWebService method getCourseInfoList.
/**
* Get courses informations 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_COURSEINFOVOes}
* @param start
* @param limit
* @param httpRequest The HTTP request
* @param request The REST request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfoList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
RepositoryManager rm = RepositoryManager.getInstance();
// fxdiff VCRP-1,2: access control of resources
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
if (MediaTypeVariants.isPaged(httpRequest, request)) {
int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>();
final Set<Long> forumNotified = new HashSet<Long>();
final Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
collectSubscriptions(identity, forumNotified, courseNotified);
for (RepositoryEntry entry : repoEntries) {
CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
if (info != null) {
infos.add(info);
}
}
CourseInfoVO[] vos = infos.toArray(new CourseInfoVO[infos.size()]);
CourseInfoVOes voes = new CourseInfoVOes();
voes.setInfos(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
return Response.serverError().status(Status.FORBIDDEN).build();
}
}
use of org.olat.restapi.support.vo.CourseInfoVO in project OpenOLAT by OpenOLAT.
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 getCourseInfoList.
/**
* Get courses informations 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_COURSEINFOVOes}
* @param start
* @param limit
* @param httpRequest The HTTP request
* @param request The REST request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfoList(@QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @Context HttpServletRequest httpRequest, @Context Request request) {
RepositoryManager rm = RepositoryManager.getInstance();
// fxdiff VCRP-1,2: access control of resources
Roles roles = getRoles(httpRequest);
Identity identity = getIdentity(httpRequest);
SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(identity, roles, CourseModule.getCourseTypeName());
if (MediaTypeVariants.isPaged(httpRequest, request)) {
int totalCount = rm.countGenericANDQueryWithRolesRestriction(params);
List<RepositoryEntry> repoEntries = rm.genericANDQueryWithRolesRestriction(params, start, limit, true);
List<CourseInfoVO> infos = new ArrayList<CourseInfoVO>();
final Set<Long> forumNotified = new HashSet<Long>();
final Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
collectSubscriptions(identity, forumNotified, courseNotified);
for (RepositoryEntry entry : repoEntries) {
CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
if (info != null) {
infos.add(info);
}
}
CourseInfoVO[] vos = infos.toArray(new CourseInfoVO[infos.size()]);
CourseInfoVOes voes = new CourseInfoVOes();
voes.setInfos(vos);
voes.setTotalCount(totalCount);
return Response.ok(voes).build();
} else {
return Response.serverError().status(Status.FORBIDDEN).build();
}
}
Aggregations