Search in sources :

Example 36 with VisibleTreeFilter

use of org.olat.course.run.userview.VisibleTreeFilter in project openolat by klemens.

the class BCWebService method getFolders.

/**
 * Retrieves metadata of the course node
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param nodeId The node's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolders(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
    final ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final UserRequest ureq = getUserRequest(httpRequest);
    RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, ureq.getIdentity(), false);
    if (!result.isAccessible()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final Set<String> subscribed = new HashSet<String>();
    NotificationsManager man = NotificationsManager.getInstance();
    List<String> notiTypes = Collections.singletonList("FolderModule");
    List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
    for (Subscriber sub : subs) {
        Long courseKey = sub.getPublisher().getResId();
        if (courseId.equals(courseKey)) {
            subscribed.add(sub.getPublisher().getSubidentifier());
            break;
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) node;
                FolderVO folder = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, bcNode, subscribed);
                folderVOs.add(folder);
            }
        }
    }, new VisibleTreeFilter());
    FolderVOes voes = new FolderVOes();
    voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
    voes.setTotalCount(folderVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BCCourseNode(org.olat.course.nodes.BCCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with VisibleTreeFilter

use of org.olat.course.run.userview.VisibleTreeFilter in project openolat by klemens.

the class ForumCourseNodeWebService method getForums.

/**
 * Retrieves metadata of the published course node
 * @response.representation.200.qname {http://www.example.com}forumVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForums(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
    final ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    UserRequest ureq = getUserRequest(httpRequest);
    final Set<Long> subcribedForums = new HashSet<Long>();
    NotificationsManager man = NotificationsManager.getInstance();
    List<String> notiTypes = Collections.singletonList("Forum");
    List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
    for (Subscriber sub : subs) {
        Long forumKey = Long.parseLong(sub.getPublisher().getData());
        subcribedForums.add(forumKey);
    }
    final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
    new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                FOCourseNode forumNode = (FOCourseNode) node;
                ForumVO forum = createForumVO(course, forumNode, subcribedForums);
                forumVOs.add(forum);
            }
        }
    }, new VisibleTreeFilter());
    ForumVOes voes = new ForumVOes();
    voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
    voes.setTotalCount(forumVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with VisibleTreeFilter

use of org.olat.course.run.userview.VisibleTreeFilter in project openolat by klemens.

the class ForumCourseNodeWebService method getForum.

/**
 * Retrieves metadata of the published course node
 * @response.representation.200.qname {http://www.example.com}forumVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param nodeId The node's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getForum(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CourseNode courseNode = course.getRunStructure().getNode(nodeId);
    if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    UserRequest ureq = getUserRequest(httpRequest);
    CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
    if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
        FOCourseNode forumNode = (FOCourseNode) courseNode;
        Set<Long> subscriptions = new HashSet<Long>();
        NotificationsManager man = NotificationsManager.getInstance();
        List<String> notiTypes = Collections.singletonList("Forum");
        List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
        for (Subscriber sub : subs) {
            Long forumKey = Long.parseLong(sub.getPublisher().getData());
            subscriptions.add(forumKey);
        }
        ForumVO forumVo = createForumVO(course, forumNode, subscriptions);
        return Response.ok(forumVo).build();
    } else {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
}
Also used : VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)38 ICourse (org.olat.course.ICourse)28 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)26 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 Roles (org.olat.core.id.Roles)16 FOCourseNode (org.olat.course.nodes.FOCourseNode)16 Identity (org.olat.core.id.Identity)14 INode (org.olat.core.util.nodes.INode)14 Visitor (org.olat.core.util.tree.Visitor)14 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)12 UserRequest (org.olat.core.gui.UserRequest)12 BCCourseNode (org.olat.course.nodes.BCCourseNode)12 CourseNode (org.olat.course.nodes.CourseNode)12 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)12 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)12 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)12