Search in sources :

Example 1 with ForumVO

use of org.olat.modules.fo.restapi.ForumVO in project OpenOLAT by OpenOLAT.

the class UserMgmtTest method testUserForums.

@Test
public void testUserForums() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id1.getName(), "A6B7C8"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("forums").queryParam("start", 0).queryParam("limit", 20).build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    ForumVOes forums = conn.parse(response, ForumVOes.class);
    assertNotNull(forums);
    assertNotNull(forums.getForums());
    assertTrue(forums.getForums().length > 0);
    for (ForumVO forum : forums.getForums()) {
        Long groupKey = forum.getGroupKey();
        if (groupKey != null) {
            BusinessGroup bg = businessGroupService.loadBusinessGroup(groupKey);
            assertNotNull(bg);
            CollaborationTools bgCTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
            assertTrue(bgCTSMngr.isToolEnabled(CollaborationTools.TOOL_FORUM));
            assertNotNull(forum.getForumKey());
            assertEquals(bg.getName(), forum.getName());
            assertEquals(bg.getKey(), forum.getGroupKey());
            assertTrue(businessGroupService.isIdentityInBusinessGroup(id1, bg));
        } else {
            assertNotNull(forum.getCourseKey());
        }
    }
    conn.shutdown();
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) BusinessGroup(org.olat.group.BusinessGroup) ForumVOes(org.olat.modules.fo.restapi.ForumVOes) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with ForumVO

use of org.olat.modules.fo.restapi.ForumVO in project openolat by klemens.

the class CoursesForumsTest method testGetForumInfo.

@Test
public void testGetForumInfo() throws IOException, URISyntaxException {
    boolean loggedIN = conn.login("administrator", "openolat");
    assertTrue(loggedIN);
    URI uri = UriBuilder.fromUri(getNodeURI()).build();
    HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(get);
    assertEquals(200, response.getStatusLine().getStatusCode());
    ForumVO forum = conn.parse(response, ForumVO.class);
    assertNotNull(forum);
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ForumVO

use of org.olat.modules.fo.restapi.ForumVO 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;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) 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) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 4 with ForumVO

use of org.olat.modules.fo.restapi.ForumVO 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;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) 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) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 5 with ForumVO

use of org.olat.modules.fo.restapi.ForumVO in project OpenOLAT by OpenOLAT.

the class CoursesForumsTest method testGetForumInfo.

@Test
public void testGetForumInfo() throws IOException, URISyntaxException {
    boolean loggedIN = conn.login("administrator", "openolat");
    assertTrue(loggedIN);
    URI uri = UriBuilder.fromUri(getNodeURI()).build();
    HttpGet get = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(get);
    assertEquals(200, response.getStatusLine().getStatusCode());
    ForumVO forum = conn.parse(response, ForumVO.class);
    assertNotNull(forum);
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ForumVO (org.olat.modules.fo.restapi.ForumVO)6 URI (java.net.URI)4 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 INode (org.olat.core.util.nodes.INode)2 Visitor (org.olat.core.util.tree.Visitor)2 ICourse (org.olat.course.ICourse)2 BCCourseNode (org.olat.course.nodes.BCCourseNode)2 FOCourseNode (org.olat.course.nodes.FOCourseNode)2 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)2 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)2 BusinessGroup (org.olat.group.BusinessGroup)2 ForumVOes (org.olat.modules.fo.restapi.ForumVOes)2 ACService (org.olat.resource.accesscontrol.ACService)2 AccessResult (org.olat.resource.accesscontrol.AccessResult)2 CourseInfoVO (org.olat.restapi.support.vo.CourseInfoVO)2