use of org.olat.core.commons.services.notifications.PublisherData in project OpenOLAT by OpenOLAT.
the class InfoMessageFrontendManagerTest method getInfoSubscribers.
@Test
public void getInfoSubscribers() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-2");
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup businessGroup = groupService.createBusinessGroup(null, "gdao", "gdao-desc", -1, -1, false, false, resource);
final OLATResourceable ores = new OLATResourceable() {
@Override
public String getResourceableTypeName() {
return businessGroup.getResourceableTypeName();
}
@Override
public Long getResourceableId() {
return businessGroup.getResourceableId();
}
};
// create publisher data
String identifier = InfoMessageFrontendManager.businessGroupResSubPath;
SubscriptionContext context = new SubscriptionContext(businessGroup.getResourceableTypeName(), businessGroup.getResourceableId(), identifier);
PublisherData publisherData = new PublisherData("testGetSubscriberIdentities", "e.g. data=infomessage", null);
dbInstance.commitAndCloseSession();
// add subscribers
notificationManager.subscribe(id1, context, publisherData);
notificationManager.subscribe(id2, context, publisherData);
dbInstance.commitAndCloseSession();
// get identities
List<Identity> identities = infoManager.getInfoSubscribers(ores, identifier);
Assert.assertNotNull(identities);
Assert.assertEquals(2, identities.size());
Assert.assertTrue(identities.contains(id1));
Assert.assertTrue(identities.contains(id2));
}
use of org.olat.core.commons.services.notifications.PublisherData 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.core.commons.services.notifications.PublisherData in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetPublisher.
@Test
public void testGetPublisher() throws IOException, URISyntaxException {
// create a business group with forum notifications
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-not-9");
BusinessGroup group = businessGroupService.createBusinessGroup(id, "Notifications 1", "REST forum notifications for group", null, null, false, false, null);
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
tools.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
Forum groupForum = tools.getForum();
dbInstance.commitAndCloseSession();
// publish
String businessPath = "[BusinessGroup:" + group.getKey() + "][toolforum:0]";
SubscriptionContext forumSubContext = new SubscriptionContext("BusinessGroup", group.getKey(), "toolforum");
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), groupForum.getKey().toString(), businessPath);
notificationManager.subscribe(id, forumSubContext, forumPdata);
dbInstance.commitAndCloseSession();
// GET publisher
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications/publisher/BusinessGroup/" + group.getKey() + "/toolforum");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
PublisherVO publisher = conn.parse(response, PublisherVO.class);
Assert.assertNotNull(publisher);
Assert.assertEquals("BusinessGroup", publisher.getResName());
Assert.assertEquals(group.getKey(), publisher.getResId());
Assert.assertEquals("toolforum", publisher.getSubidentifier());
Assert.assertEquals("Forum", publisher.getType());
Assert.assertEquals(groupForum.getKey().toString(), publisher.getData());
}
use of org.olat.core.commons.services.notifications.PublisherData in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testCreatePublisher.
@Test
public void testCreatePublisher() {
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("PS", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testPublisherSubscriber", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
// check values
Assert.assertNotNull(publisher);
Assert.assertNotNull(publisher.getKey());
Assert.assertNotNull(publisher.getCreationDate());
Assert.assertNotNull(publisher.getLatestNewsDate());
Assert.assertEquals("PS", publisher.getResName());
Assert.assertEquals(new Long(123), publisher.getResId());
Assert.assertEquals(identifier, publisher.getSubidentifier());
// check if exists
Publisher reloadedPublisher = notificationManager.getPublisher(context);
Assert.assertNotNull(reloadedPublisher);
Assert.assertEquals(publisher, reloadedPublisher);
}
use of org.olat.core.commons.services.notifications.PublisherData in project OpenOLAT by OpenOLAT.
the class NotificationsManagerTest method testUnsubscribe_v1.
@Test
public void testUnsubscribe_v1() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("unsubs-" + UUID.randomUUID().toString());
// create a publisher
String identifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
PublisherData publisherData = new PublisherData("testUnsubscribe", "e.g. forumdata=keyofforum", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(publisher);
// subscribe
notificationManager.subscribe(id, context, publisherData);
dbInstance.commitAndCloseSession();
// check
Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
Assert.assertNotNull(subscriber);
// unsubscribe
notificationManager.unsubscribe(subscriber);
dbInstance.commitAndCloseSession();
// check
boolean subscribed = notificationManager.isSubscribed(id, context);
Assert.assertFalse(subscribed);
}
Aggregations