use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class RepositoryEntryMembershipProcessorTest method testRemoveCoach_withBusinessGroups.
@Test
public void testRemoveCoach_withBusinessGroups() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// create a group with members
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-1");
Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("remp-proc-2");
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
repositoryEntryRelationDao.addRole(owner, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(member, re, GroupRoles.coach.name());
repositoryEntryRelationDao.addRole(coach, re, GroupRoles.coach.name());
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRelationToResource(businessGroup, re);
// create a publisher
SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
Assert.assertNotNull(publisher);
dbInstance.commitAndCloseSession();
// subscribe
notificationManager.subscribe(owner, context, publisherData);
notificationManager.subscribe(member, context, publisherData);
notificationManager.subscribe(coach, context, publisherData);
dbInstance.commitAndCloseSession();
// remove member and coach as coach of the repo entry
List<Identity> removeIdentities = new ArrayList<>(2);
removeIdentities.add(member);
removeIdentities.add(coach);
repositoryManager.removeTutors(owner, removeIdentities, re, new MailPackage(false));
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(member, context, dbInstance, notificationManager), 5000);
sleep(1000);
// check that subscription of id1 was deleted but not the ones of id2 and coach
boolean subscribedMember = notificationManager.isSubscribed(member, context);
Assert.assertFalse(subscribedMember);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
boolean subscribedOwner = notificationManager.isSubscribed(owner, context);
Assert.assertTrue(subscribedOwner);
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetBusinessGroupFolderNotifications.
@Test
public void testGetBusinessGroupFolderNotifications() throws IOException, URISyntaxException {
// create a business group with folder notifications
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-not-5-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupService.createBusinessGroup(id, "Notifications 2", "REST folder notifications for group", null, null, false, false, null);
CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
tools.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
String relPath = tools.getFolderRelPath();
dbInstance.commitAndCloseSession();
// publish
String businessPath = "[BusinessGroup:" + group.getKey() + "][toolfolder:0]";
SubscriptionContext folderSubContext = new SubscriptionContext("BusinessGroup", group.getKey(), "toolfolder");
PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
notificationManager.subscribe(id, folderSubContext, folderPdata);
// add a file
OlatRootFolderImpl folder = tools.getSecuredFolder(group, folderSubContext, id, true);
String filename = addFile(folder);
// mark as published
notificationManager.markPublisherNews(folderSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(group.getKey(), itemVO.getGroupKey());
Assert.assertEquals("/" + filename, itemVO.getPath());
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetBusinessGroupForumNotifications.
@Test
public void testGetBusinessGroupForumNotifications() throws IOException, URISyntaxException {
// create a business group with forum notifications
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("rest-not-4-" + UUID.randomUUID().toString());
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);
Message message = createMessage(id, groupForum);
notificationManager.markPublisherNews(forumSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(group.getKey(), itemVO.getGroupKey());
Assert.assertEquals(message.getKey(), itemVO.getMessageKey());
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetCourseForumNotifications.
@Test
public void testGetCourseForumNotifications() throws IOException, URISyntaxException {
// create a course with a forum
Identity id = JunitTestHelper.createAndPersistIdentityAsAuthor("rest-not-6-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(id, "Course forum not", "Course forum with notification", null);
dbInstance.intermediateCommit();
// create the forum
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration("fo");
FOCourseNode forumNode = (FOCourseNode) newNodeConfig.getInstance();
forumNode.setShortTitle("Forum");
forumNode.setLearningObjectives("forum objectives");
forumNode.setNoAccessExplanation("You don't have access");
Forum courseForum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
course.getEditorTreeModel().addCourseNode(forumNode, course.getRunStructure().getRootNode());
CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false, id, Locale.ENGLISH);
dbInstance.intermediateCommit();
// add message and publisher
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(course.getCourseEnvironment().getCourseGroupManager().getCourseResource(), true);
String businessPath = "[RepositoryEntry:" + re.getKey() + "][CourseNode:" + forumNode.getIdent() + "]";
SubscriptionContext forumSubContext = new SubscriptionContext("CourseModule", course.getResourceableId(), forumNode.getIdent());
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), courseForum.getKey().toString(), businessPath);
notificationManager.subscribe(id, forumSubContext, forumPdata);
Message message = createMessage(id, courseForum);
notificationManager.markPublisherNews(forumSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(course.getResourceableId(), itemVO.getCourseKey());
Assert.assertEquals(forumNode.getIdent(), itemVO.getCourseNodeId());
Assert.assertEquals(message.getKey(), itemVO.getMessageKey());
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class NotificationsTest method testGetCourseFolderNotifications.
@Test
public void testGetCourseFolderNotifications() throws IOException, URISyntaxException {
// create a course with a forum
Identity id = JunitTestHelper.createAndPersistIdentityAsAuthor("rest-not-7-" + UUID.randomUUID().toString());
ICourse course = CoursesWebService.createEmptyCourse(id, "Course folder not", "Course with folder and notification", null);
dbInstance.intermediateCommit();
// create the folder
CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration("bc");
BCCourseNode folderNode = (BCCourseNode) newNodeConfig.getInstance();
folderNode.setShortTitle("Folder");
folderNode.setLearningObjectives("folder objectives");
folderNode.setNoAccessExplanation("You don't have access");
String relPath = BCCourseNode.getFoldernodePathRelToFolderBase(course.getCourseEnvironment(), folderNode);
VFSContainer folder = BCCourseNode.getNodeFolderContainer(folderNode, course.getCourseEnvironment());
course.getEditorTreeModel().addCourseNode(folderNode, course.getRunStructure().getRootNode());
CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false, id, Locale.ENGLISH);
dbInstance.intermediateCommit();
// add message and publisher
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(course.getCourseEnvironment().getCourseGroupManager().getCourseResource(), true);
String businessPath = "[RepositoryEntry:" + re.getKey() + "][CourseNode:" + folderNode.getIdent() + "]";
SubscriptionContext folderSubContext = new SubscriptionContext("CourseModule", course.getResourceableId(), folderNode.getIdent());
PublisherData folderPdata = new PublisherData("FolderModule", relPath, businessPath);
notificationManager.subscribe(id, folderSubContext, folderPdata);
String filename = addFile(folder);
notificationManager.markPublisherNews(folderSubContext, null, true);
dbInstance.commitAndCloseSession();
// get the notification
RestConnection conn = new RestConnection();
assertTrue(conn.login(id.getName(), "A6B7C8"));
UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications");
HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<SubscriptionInfoVO> infos = parseUserArray(response.getEntity().getContent());
Assert.assertNotNull(infos);
Assert.assertEquals(1, infos.size());
SubscriptionInfoVO infoVO = infos.get(0);
Assert.assertNotNull(infoVO.getItems());
Assert.assertEquals(1, infoVO.getItems().size());
SubscriptionListItemVO itemVO = infoVO.getItems().get(0);
Assert.assertNotNull(itemVO);
Assert.assertEquals(course.getResourceableId(), itemVO.getCourseKey());
Assert.assertEquals(folderNode.getIdent(), itemVO.getCourseNodeId());
Assert.assertEquals("/" + filename, itemVO.getPath());
}
Aggregations