Search in sources :

Example 6 with SubscriptionListItemVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO 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 7 with SubscriptionListItemVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO in project OpenOLAT by OpenOLAT.

the class NotificationsWebService method createSubscriptionInfoVO.

private SubscriptionInfoVO createSubscriptionInfoVO(Publisher publisher, SubscriptionInfo info) {
    SubscriptionInfoVO infoVO = new SubscriptionInfoVO(info);
    if (info.getSubscriptionListItems() != null && !info.getSubscriptionListItems().isEmpty()) {
        List<SubscriptionListItemVO> itemVOes = new ArrayList<SubscriptionListItemVO>(info.getSubscriptionListItems().size());
        String publisherType = publisher.getType();
        String resourceType = publisher.getResName();
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            SubscriptionListItemVO itemVO = new SubscriptionListItemVO(item);
            // resource specific
            if ("BusinessGroup".equals(resourceType)) {
                itemVO.setGroupKey(publisher.getResId());
            } else if ("CourseModule".equals(resourceType)) {
                itemVO.setCourseKey(publisher.getResId());
                itemVO.setCourseNodeId(publisher.getSubidentifier());
            }
            // publisher specififc
            if ("Forum".equals(publisherType)) {
                // extract the message id
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if ("Message".equals(lastCe.getOLATResourceable().getResourceableTypeName())) {
                        itemVO.setMessageKey(lastCe.getOLATResourceable().getResourceableId());
                    }
                }
            } else if ("FolderModule".equals(publisherType)) {
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if (lastCe.getOLATResourceable().getResourceableTypeName().startsWith("path=")) {
                        String path = BusinessControlFactory.getInstance().getPath(lastCe);
                        itemVO.setPath(path);
                    }
                }
            }
            itemVOes.add(itemVO);
        }
        infoVO.setItems(itemVOes);
    }
    return infoVO;
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 8 with SubscriptionListItemVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO 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 9 with SubscriptionListItemVO

use of org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO 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)

Example 10 with SubscriptionListItemVO

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

the class NotificationsWebService method createSubscriptionInfoVO.

private SubscriptionInfoVO createSubscriptionInfoVO(Publisher publisher, SubscriptionInfo info) {
    SubscriptionInfoVO infoVO = new SubscriptionInfoVO(info);
    if (info.getSubscriptionListItems() != null && !info.getSubscriptionListItems().isEmpty()) {
        List<SubscriptionListItemVO> itemVOes = new ArrayList<SubscriptionListItemVO>(info.getSubscriptionListItems().size());
        String publisherType = publisher.getType();
        String resourceType = publisher.getResName();
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            SubscriptionListItemVO itemVO = new SubscriptionListItemVO(item);
            // resource specific
            if ("BusinessGroup".equals(resourceType)) {
                itemVO.setGroupKey(publisher.getResId());
            } else if ("CourseModule".equals(resourceType)) {
                itemVO.setCourseKey(publisher.getResId());
                itemVO.setCourseNodeId(publisher.getSubidentifier());
            }
            // publisher specififc
            if ("Forum".equals(publisherType)) {
                // extract the message id
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if ("Message".equals(lastCe.getOLATResourceable().getResourceableTypeName())) {
                        itemVO.setMessageKey(lastCe.getOLATResourceable().getResourceableId());
                    }
                }
            } else if ("FolderModule".equals(publisherType)) {
                List<ContextEntry> ces = BusinessControlFactory.getInstance().createCEListFromString(item.getBusinessPath());
                if (ces.size() > 0) {
                    ContextEntry lastCe = ces.get(ces.size() - 1);
                    if (lastCe.getOLATResourceable().getResourceableTypeName().startsWith("path=")) {
                        String path = BusinessControlFactory.getInstance().getPath(lastCe);
                        itemVO.setPath(path);
                    }
                }
            }
            itemVOes.add(itemVO);
        }
        infoVO.setItems(itemVOes);
    }
    return infoVO;
}
Also used : SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionListItemVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO) ContextEntry(org.olat.core.id.context.ContextEntry)

Aggregations

SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)10 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)10 UriBuilder (javax.ws.rs.core.UriBuilder)8 HttpResponse (org.apache.http.HttpResponse)8 HttpGet (org.apache.http.client.methods.HttpGet)8 Test (org.junit.Test)8 PublisherData (org.olat.core.commons.services.notifications.PublisherData)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)8 Identity (org.olat.core.id.Identity)8 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 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2