Search in sources :

Example 1 with ForumVOes

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

the class CoursesForumsTest method testGetForumsInfo.

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

Example 2 with ForumVOes

use of org.olat.modules.fo.restapi.ForumVOes 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 3 with ForumVOes

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

the class MyForumsTest method myForums.

/**
 * Test retrieve the forum which the user subscribe in a course.
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void myForums() throws IOException, URISyntaxException {
    URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
    Assert.assertNotNull(courseWithForumsUrl);
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString().replace("_", "");
    RepositoryEntry myCourseRe = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(myCourseRe);
    ICourse myCourse = CourseFactory.loadCourse(myCourseRe);
    final Identity id = JunitTestHelper.createAndPersistIdentityAsUser("my-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // load my forums
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id.getName(), "A6B7C8"));
    // subscribed to nothing
    URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("forums").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    ForumVOes forums = conn.parse(body, ForumVOes.class);
    Assert.assertNotNull(forums);
    Assert.assertNotNull(forums.getForums());
    Assert.assertEquals(0, forums.getForums().length);
    // subscribe to the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id, new Roles(false, false, false, false, false, false, false));
    new CourseTreeVisitor(myCourse, ienv).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                FOCourseNode forumNode = (FOCourseNode) node;
                Forum forum = forumNode.loadOrCreateForum(myCourse.getCourseEnvironment());
                String businessPath = "[RepositoryEntry:" + myCourseRe.getKey() + "][CourseNode:" + forumNode.getIdent() + "]";
                SubscriptionContext forumSubContext = new SubscriptionContext("CourseModule", myCourse.getResourceableId(), forumNode.getIdent());
                PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), businessPath);
                NotificationsManager.getInstance().subscribe(id, forumSubContext, forumPdata);
            }
        }
    }, new VisibleTreeFilter());
    dbInstance.commitAndCloseSession();
    // retrieve my forums
    HttpGet method2 = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response2 = conn.execute(method2);
    assertEquals(200, response2.getStatusLine().getStatusCode());
    InputStream body2 = response2.getEntity().getContent();
    ForumVOes forums2 = conn.parse(body2, ForumVOes.class);
    Assert.assertNotNull(forums2);
    Assert.assertNotNull(forums2.getForums());
    Assert.assertEquals(1, forums2.getForums().length);
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) InputStream(java.io.InputStream) ForumVOes(org.olat.modules.fo.restapi.ForumVOes) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) HttpGet(org.apache.http.client.methods.HttpGet) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) PublisherData(org.olat.core.commons.services.notifications.PublisherData) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 4 with ForumVOes

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

the class MyForumsTest method myForums.

/**
 * Test retrieve the forum which the user subscribe in a course.
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void myForums() throws IOException, URISyntaxException {
    URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
    Assert.assertNotNull(courseWithForumsUrl);
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString().replace("_", "");
    RepositoryEntry myCourseRe = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(myCourseRe);
    ICourse myCourse = CourseFactory.loadCourse(myCourseRe);
    final Identity id = JunitTestHelper.createAndPersistIdentityAsUser("my-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // load my forums
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id.getName(), "A6B7C8"));
    // subscribed to nothing
    URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("forums").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    ForumVOes forums = conn.parse(body, ForumVOes.class);
    Assert.assertNotNull(forums);
    Assert.assertNotNull(forums.getForums());
    Assert.assertEquals(0, forums.getForums().length);
    // subscribe to the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id, new Roles(false, false, false, false, false, false, false));
    new CourseTreeVisitor(myCourse, ienv).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                FOCourseNode forumNode = (FOCourseNode) node;
                Forum forum = forumNode.loadOrCreateForum(myCourse.getCourseEnvironment());
                String businessPath = "[RepositoryEntry:" + myCourseRe.getKey() + "][CourseNode:" + forumNode.getIdent() + "]";
                SubscriptionContext forumSubContext = new SubscriptionContext("CourseModule", myCourse.getResourceableId(), forumNode.getIdent());
                PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), businessPath);
                NotificationsManager.getInstance().subscribe(id, forumSubContext, forumPdata);
            }
        }
    }, new VisibleTreeFilter());
    dbInstance.commitAndCloseSession();
    // retrieve my forums
    HttpGet method2 = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response2 = conn.execute(method2);
    assertEquals(200, response2.getStatusLine().getStatusCode());
    InputStream body2 = response2.getEntity().getContent();
    ForumVOes forums2 = conn.parse(body2, ForumVOes.class);
    Assert.assertNotNull(forums2);
    Assert.assertNotNull(forums2.getForums());
    Assert.assertEquals(1, forums2.getForums().length);
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) InputStream(java.io.InputStream) ForumVOes(org.olat.modules.fo.restapi.ForumVOes) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) HttpGet(org.apache.http.client.methods.HttpGet) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) PublisherData(org.olat.core.commons.services.notifications.PublisherData) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 5 with ForumVOes

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

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)

Aggregations

URI (java.net.URI)6 HttpResponse (org.apache.http.HttpResponse)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Test (org.junit.Test)6 ForumVOes (org.olat.modules.fo.restapi.ForumVOes)6 File (java.io.File)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 PublisherData (org.olat.core.commons.services.notifications.PublisherData)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 Identity (org.olat.core.id.Identity)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 Roles (org.olat.core.id.Roles)2 INode (org.olat.core.util.nodes.INode)2 Visitor (org.olat.core.util.tree.Visitor)2 ICourse (org.olat.course.ICourse)2 FOCourseNode (org.olat.course.nodes.FOCourseNode)2 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)2 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)2