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);
}
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();
}
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);
}
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);
}
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();
}
Aggregations