Search in sources :

Example 11 with FOCourseNode

use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.

the class NotificationsSubscribersTest method subscribe.

@Test
public void subscribe() throws IOException, URISyntaxException {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-sub-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-sub-2");
    // deploy a course with forums
    URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
    Assert.assertNotNull(courseWithForumsUrl);
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString().replace("-", "");
    RepositoryEntry courseEntry = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(courseEntry);
    // load the course and found the first forum
    ICourse course = CourseFactory.loadCourse(courseEntry);
    // find the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id1, new Roles(false, false, false, false, false, false, false));
    ForumVisitor forumVisitor = new ForumVisitor(course);
    new CourseTreeVisitor(course, ienv).visit(forumVisitor, new VisibleTreeFilter());
    FOCourseNode courseNode = forumVisitor.firstNode;
    Forum forum = forumVisitor.firstForum;
    Assert.assertNotNull(courseNode);
    Assert.assertNotNull(forum);
    // put subscribers
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    PublisherVO subscribersVO = new PublisherVO();
    // publisher data
    subscribersVO.setType("Forum");
    subscribersVO.setData(forum.getKey().toString());
    subscribersVO.setBusinessPath("[RepositoryEntry:" + courseEntry.getKey() + "][CourseNode:" + courseNode.getIdent() + "]");
    // context
    subscribersVO.setResName("CourseModule");
    subscribersVO.setResId(course.getResourceableId());
    subscribersVO.setSubidentifier(courseNode.getIdent());
    subscribersVO.getUsers().add(UserVOFactory.get(id1));
    subscribersVO.getUsers().add(UserVOFactory.get(id2));
    // create the subscribers
    URI subscribersUri = UriBuilder.fromUri(getContextURI()).path("notifications").path("subscribers").build();
    HttpPut putMethod = conn.createPut(subscribersUri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(putMethod, subscribersVO);
    HttpResponse response = conn.execute(putMethod);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // get publisher
    SubscriptionContext subsContext = new SubscriptionContext("CourseModule", course.getResourceableId(), courseNode.getIdent());
    Publisher publisher = notificationsManager.getPublisher(subsContext);
    Assert.assertNotNull(publisher);
    // get subscribers
    List<Subscriber> subscribers = notificationsManager.getSubscribers(publisher);
    Assert.assertNotNull(subscribers);
    Assert.assertEquals(2, subscribers.size());
    conn.shutdown();
}
Also used : VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) Publisher(org.olat.core.commons.services.notifications.Publisher) URI(java.net.URI) URL(java.net.URL) HttpPut(org.apache.http.client.methods.HttpPut) Forum(org.olat.modules.fo.Forum) Subscriber(org.olat.core.commons.services.notifications.Subscriber) PublisherVO(org.olat.core.commons.services.notifications.restapi.vo.PublisherVO) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Test(org.junit.Test)

Example 12 with FOCourseNode

use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.

the class NotificationsSubscribersTest method unsubscribe.

@Test
public void unsubscribe() throws IOException, URISyntaxException {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-sub-3");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-sub-4");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-sub-5");
    // deploy a course with forums
    URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
    Assert.assertNotNull(courseWithForumsUrl);
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString().replace("-", "");
    RepositoryEntry courseEntry = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(courseEntry);
    // load the course and found the first forum
    ICourse course = CourseFactory.loadCourse(courseEntry);
    // find the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id1, new Roles(false, false, false, false, false, false, false));
    ForumVisitor forumVisitor = new ForumVisitor(course);
    new CourseTreeVisitor(course, ienv).visit(forumVisitor, new VisibleTreeFilter());
    FOCourseNode courseNode = forumVisitor.firstNode;
    Forum forum = forumVisitor.firstForum;
    Assert.assertNotNull(courseNode);
    Assert.assertNotNull(forum);
    // the 3 users subscribed to the forum
    PublisherData publisherData = new PublisherData("Forum", forum.getKey().toString(), "[RepositoryEntry:" + courseEntry.getKey() + "][CourseNode:" + courseNode.getIdent() + "]");
    SubscriptionContext subsContext = new SubscriptionContext("CourseModule", course.getResourceableId(), courseNode.getIdent());
    notificationsManager.subscribe(id1, subsContext, publisherData);
    notificationsManager.subscribe(id2, subsContext, publisherData);
    notificationsManager.subscribe(id3, subsContext, publisherData);
    dbInstance.commitAndCloseSession();
    // get the subscriber
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI subscribersUri = UriBuilder.fromUri(getContextURI()).path("notifications").path("subscribers").path(subsContext.getResName()).path(subsContext.getResId().toString()).path(subsContext.getSubidentifier()).build();
    HttpGet getMethod = conn.createGet(subscribersUri, MediaType.APPLICATION_JSON, true);
    HttpResponse getResponse = conn.execute(getMethod);
    Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode());
    List<SubscriberVO> subscriberVOes = parseGroupArray(getResponse.getEntity().getContent());
    Assert.assertNotNull(subscriberVOes);
    Assert.assertEquals(3, subscriberVOes.size());
    SubscriberVO subscriberId2VO = null;
    for (SubscriberVO subscriberVO : subscriberVOes) {
        if (subscriberVO.getIdentityKey().equals(id2.getKey())) {
            subscriberId2VO = subscriberVO;
        }
    }
    // delete id2
    URI deleteSubscriberUri = UriBuilder.fromUri(getContextURI()).path("notifications").path("subscribers").path(subscriberId2VO.getSubscriberKey().toString()).build();
    HttpDelete deleteMethod = conn.createDelete(deleteSubscriberUri, MediaType.APPLICATION_JSON);
    HttpResponse deleteResponse = conn.execute(deleteMethod);
    Assert.assertEquals(200, deleteResponse.getStatusLine().getStatusCode());
    // check
    Publisher publisher = notificationsManager.getPublisher(subsContext);
    List<Subscriber> survivingSubscribers = notificationsManager.getSubscribers(publisher);
    Assert.assertNotNull(survivingSubscribers);
    Assert.assertEquals(2, survivingSubscribers.size());
    for (Subscriber subscriber : survivingSubscribers) {
        Assert.assertNotEquals(id2, subscriber.getIdentity());
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) HttpGet(org.apache.http.client.methods.HttpGet) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) PublisherData(org.olat.core.commons.services.notifications.PublisherData) URI(java.net.URI) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) SubscriberVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriberVO) Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HttpResponse(org.apache.http.HttpResponse) Roles(org.olat.core.id.Roles) Publisher(org.olat.core.commons.services.notifications.Publisher) File(java.io.File) Test(org.junit.Test)

Example 13 with FOCourseNode

use of org.olat.course.nodes.FOCourseNode 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 14 with FOCourseNode

use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.

the class CoursesInfosWebService method collect.

private CourseInfoVO collect(final Identity identity, final Roles roles, final RepositoryEntry entry, final Set<Long> forumNotified, final Map<Long, Set<String>> courseNotified) {
    CourseInfoVO info = new CourseInfoVO();
    info.setRepoEntryKey(entry.getKey());
    info.setSoftKey(entry.getSoftkey());
    info.setDisplayName(entry.getDisplayname());
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, identity, false);
    if (result.isAccessible()) {
        try {
            final ICourse course = CourseFactory.loadCourse(entry);
            final List<FolderVO> folders = new ArrayList<FolderVO>();
            final List<ForumVO> forums = new ArrayList<ForumVO>();
            final IdentityEnvironment ienv = new IdentityEnvironment(identity, roles);
            new CourseTreeVisitor(course, ienv).visit(new Visitor() {

                @Override
                public void visit(INode node) {
                    if (node instanceof BCCourseNode) {
                        BCCourseNode bcNode = (BCCourseNode) node;
                        folders.add(BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId())));
                    } else if (node instanceof FOCourseNode) {
                        FOCourseNode forumNode = (FOCourseNode) node;
                        forums.add(ForumCourseNodeWebService.createForumVO(course, forumNode, forumNotified));
                    }
                }
            }, new VisibleTreeFilter());
            info.setKey(course.getResourceableId());
            info.setTitle(course.getCourseTitle());
            info.setFolders(folders.toArray(new FolderVO[folders.size()]));
            info.setForums(forums.toArray(new ForumVO[forums.size()]));
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return info;
}
Also used : ForumVO(org.olat.modules.fo.restapi.ForumVO) INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 15 with FOCourseNode

use of org.olat.course.nodes.FOCourseNode in project openolat by klemens.

the class ArchiverMainController method launchArchiveControllers.

private void launchArchiveControllers(UserRequest ureq, String menuCommand) {
    if (menuCommand.equals(CMD_INDEX)) {
        main.setContent(intro);
    } else {
        removeAsListenerAndDispose(contentCtr);
        if (menuCommand.equals(CMD_QTISURVRESULTS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new IQSURVCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_QTITESTRESULTS)) {
            contentCtr = new TestArchiveController(ureq, getWindowControl(), ores, new IQTESTCourseNode(), new IQSELFCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_SCOREACCOUNTING)) {
            contentCtr = new ScoreAccountingArchiveController(ureq, getWindowControl(), ores);
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_ARCHIVELOGFILES)) {
            contentCtr = new CourseLogsArchiveController(ureq, getWindowControl(), ores);
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_HANDEDINTASKS)) {
            // TACourseNode
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new TACourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_GROUPTASKS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new GTACourseNode(), new GTACourseNode(GTACourseNode.TYPE_INDIVIDUAL));
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_PROJECTBROKER)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new ProjectBrokerCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_FORUMS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new FOCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_DIALOGS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new DialogCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_WIKIS)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new WikiCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_SCORM)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new ScormCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_CHECKLIST)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new CheckListCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        } else if (menuCommand.equals(CMD_PARTICIPANTFOLDER)) {
            contentCtr = new GenericArchiveController(ureq, getWindowControl(), ores, new PFCourseNode());
            main.setContent(contentCtr.getInitialComponent());
        }
        listenTo(contentCtr);
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) IQSURVCourseNode(org.olat.course.nodes.IQSURVCourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) DialogCourseNode(org.olat.course.nodes.DialogCourseNode) WikiCourseNode(org.olat.course.nodes.WikiCourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode)

Aggregations

FOCourseNode (org.olat.course.nodes.FOCourseNode)30 ICourse (org.olat.course.ICourse)22 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)16 Forum (org.olat.modules.fo.Forum)14 Identity (org.olat.core.id.Identity)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 File (java.io.File)10 URL (java.net.URL)10 ArrayList (java.util.ArrayList)10 HttpResponse (org.apache.http.HttpResponse)10 Test (org.junit.Test)10 Subscriber (org.olat.core.commons.services.notifications.Subscriber)10 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)10 INode (org.olat.core.util.nodes.INode)10 Visitor (org.olat.core.util.tree.Visitor)10 CourseNode (org.olat.course.nodes.CourseNode)10 URI (java.net.URI)8 HttpGet (org.apache.http.client.methods.HttpGet)8 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)8