Search in sources :

Example 16 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.

the class NotificationsTest method testGetUserForumNotifications.

@Test
public void testGetUserForumNotifications() throws URISyntaxException, IOException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(userAndForumSubscriberId.getName(), "A6B7C8"));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.HOUR, -2);
    String date = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.S").format(cal.getTime());
    URI uri = conn.getContextURI().path("notifications").queryParam("date", date).build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<SubscriptionInfoVO> infos = parseUserArray(response);
    assertNotNull(infos);
    assertTrue(2 <= infos.size());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) SimpleDateFormat(java.text.SimpleDateFormat) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 17 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.

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());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) PublisherData(org.olat.core.commons.services.notifications.PublisherData) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) CollaborationTools(org.olat.collaboration.CollaborationTools) 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 18 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.

the class NotificationsTest method testGetNotifications.

@Test
public void testGetNotifications() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("rest-notifications-test-1", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("notifications").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<SubscriptionInfoVO> infos = parseUserArray(body);
    assertNotNull(infos);
    assertFalse(infos.isEmpty());
    SubscriptionInfoVO infoVO = infos.get(0);
    assertNotNull(infoVO);
    assertNotNull(infoVO.getKey());
    assertNotNull("User", infoVO.getType());
    assertNotNull(infoVO.getTitle());
    assertNotNull(infoVO.getItems());
    assertFalse(infoVO.getItems().isEmpty());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 19 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.

the class NotificationsTest method testGetUserNotifications.

@Test
public void testGetUserNotifications() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("rest-notifications-test-1", "A6B7C8"));
    UriBuilder request = UriBuilder.fromUri(getContextURI()).path("notifications").queryParam("type", "User");
    HttpGet method = conn.createGet(request.build(), MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<SubscriptionInfoVO> infos = parseUserArray(body);
    assertNotNull(infos);
    assertFalse(infos.isEmpty());
    SubscriptionInfoVO infoVO = infos.get(0);
    assertNotNull(infoVO);
    assertNotNull(infoVO.getKey());
    assertNotNull("User", infoVO.getType());
    assertNotNull(infoVO.getTitle());
    assertNotNull(infoVO.getItems());
    assertFalse(infoVO.getItems().isEmpty());
    conn.shutdown();
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 20 with SubscriptionInfoVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO in project openolat by klemens.

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

Aggregations

SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)22 HttpResponse (org.apache.http.HttpResponse)18 HttpGet (org.apache.http.client.methods.HttpGet)18 Test (org.junit.Test)18 UriBuilder (javax.ws.rs.core.UriBuilder)12 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)10 Identity (org.olat.core.id.Identity)10 InputStream (java.io.InputStream)8 PublisherData (org.olat.core.commons.services.notifications.PublisherData)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CollaborationTools (org.olat.collaboration.CollaborationTools)4 ICourse (org.olat.course.ICourse)4 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)4 BusinessGroup (org.olat.group.BusinessGroup)4 Forum (org.olat.modules.fo.Forum)4 Message (org.olat.modules.fo.Message)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4