Search in sources :

Example 36 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HttpGet(org.apache.http.client.methods.HttpGet) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherVO(org.olat.core.commons.services.notifications.restapi.vo.PublisherVO) Identity(org.olat.core.id.Identity) UriBuilder(javax.ws.rs.core.UriBuilder) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Forum(org.olat.modules.fo.Forum) Test(org.junit.Test)

Example 37 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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());
}
Also used : Message(org.olat.modules.fo.Message) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) RepositoryEntry(org.olat.repository.RepositoryEntry) PublisherData(org.olat.core.commons.services.notifications.PublisherData) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) Forum(org.olat.modules.fo.Forum) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 38 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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());
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) RepositoryEntry(org.olat.repository.RepositoryEntry) PublisherData(org.olat.core.commons.services.notifications.PublisherData) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) BCCourseNode(org.olat.course.nodes.BCCourseNode) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 39 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    if (!setup) {
        userSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-1");
        userAndForumSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-2");
        JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-3");
        SubscriptionContext subContext = UsersSubscriptionManager.getInstance().getNewUsersSubscriptionContext();
        PublisherData publisherData = UsersSubscriptionManager.getInstance().getNewUsersPublisherData();
        if (!notificationManager.isSubscribed(userSubscriberId, subContext)) {
            notificationManager.subscribe(userSubscriberId, subContext, publisherData);
        }
        if (!notificationManager.isSubscribed(userAndForumSubscriberId, subContext)) {
            notificationManager.subscribe(userAndForumSubscriberId, subContext, publisherData);
        }
        // create a forum
        forum = ForumManager.getInstance().addAForum();
        Message m1 = createMessage(userSubscriberId, forum);
        Assert.assertNotNull(m1);
        // subscribe
        SubscriptionContext forumSubContext = new SubscriptionContext("NotificationRestCourse", forum.getKey(), "2387");
        PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), "");
        if (!notificationManager.isSubscribed(userAndForumSubscriberId, forumSubContext)) {
            notificationManager.subscribe(userAndForumSubscriberId, forumSubContext, forumPdata);
        }
        notificationManager.markPublisherNews(forumSubContext, userSubscriberId, true);
        // generate one notification
        String randomLogin = UUID.randomUUID().toString().replace("-", "");
        JunitTestHelper.createAndPersistIdentityAsUser(randomLogin);
        setup = true;
    }
    dbInstance.commitAndCloseSession();
}
Also used : Message(org.olat.modules.fo.Message) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Forum(org.olat.modules.fo.Forum) Before(org.junit.Before)

Example 40 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class UsersSubscriptionManagerImpl method subscribe.

/**
 * Subscribe to notifications of new identity created
 */
public void subscribe(Identity identity) {
    PublisherData data = getNewUsersPublisherData();
    SubscriptionContext context = getNewUsersSubscriptionContext();
    NotificationsManager.getInstance().subscribe(identity, context, data);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Aggregations

PublisherData (org.olat.core.commons.services.notifications.PublisherData)100 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)84 Test (org.junit.Test)64 Identity (org.olat.core.id.Identity)60 Publisher (org.olat.core.commons.services.notifications.Publisher)42 RepositoryEntry (org.olat.repository.RepositoryEntry)22 BusinessGroup (org.olat.group.BusinessGroup)20 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)16 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 ArrayList (java.util.ArrayList)14 ContextualSubscriptionController (org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController)12 Forum (org.olat.modules.fo.Forum)12 UriBuilder (javax.ws.rs.core.UriBuilder)10 SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)8 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 ICourse (org.olat.course.ICourse)8 File (java.io.File)6 URI (java.net.URI)6