Search in sources :

Example 36 with Forum

use of org.olat.modules.fo.Forum in project OpenOLAT by OpenOLAT.

the class LearningGroupWebService method getForum.

/**
 * Return the Forum web service
 * @param groupKey The key of the group
 * @param request The HTTP Request
 * @return
 */
@Path("{groupKey}/forum")
public ForumWebService getForum(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
    if (bg == null) {
        return null;
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return null;
        }
    }
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (collabTools.isToolEnabled(CollaborationTools.TOOL_FORUM)) {
        Forum forum = collabTools.getForum();
        return new ForumWebService(forum);
    }
    return null;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) ForumWebService(org.olat.modules.fo.restapi.ForumWebService) CollaborationTools(org.olat.collaboration.CollaborationTools) Identity(org.olat.core.id.Identity) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 37 with Forum

use of org.olat.modules.fo.Forum in project OpenOLAT by OpenOLAT.

the class MyForumsTest method myForums.

/**
 * Test retrieve the forum which the user subscribe in a course.
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void myForums() throws IOException, URISyntaxException {
    URL courseWithForumsUrl = MyForumsTest.class.getResource("myCourseWS.zip");
    Assert.assertNotNull(courseWithForumsUrl);
    File courseWithForums = new File(courseWithForumsUrl.toURI());
    String softKey = UUID.randomUUID().toString().replace("_", "");
    RepositoryEntry myCourseRe = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
    Assert.assertNotNull(myCourseRe);
    ICourse myCourse = CourseFactory.loadCourse(myCourseRe);
    final Identity id = JunitTestHelper.createAndPersistIdentityAsUser("my-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // load my forums
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(id.getName(), "A6B7C8"));
    // subscribed to nothing
    URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id.getKey().toString()).path("forums").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    ForumVOes forums = conn.parse(body, ForumVOes.class);
    Assert.assertNotNull(forums);
    Assert.assertNotNull(forums.getForums());
    Assert.assertEquals(0, forums.getForums().length);
    // subscribe to the forum
    IdentityEnvironment ienv = new IdentityEnvironment(id, new Roles(false, false, false, false, false, false, false));
    new CourseTreeVisitor(myCourse, ienv).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                FOCourseNode forumNode = (FOCourseNode) node;
                Forum forum = forumNode.loadOrCreateForum(myCourse.getCourseEnvironment());
                String businessPath = "[RepositoryEntry:" + myCourseRe.getKey() + "][CourseNode:" + forumNode.getIdent() + "]";
                SubscriptionContext forumSubContext = new SubscriptionContext("CourseModule", myCourse.getResourceableId(), forumNode.getIdent());
                PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), businessPath);
                NotificationsManager.getInstance().subscribe(id, forumSubContext, forumPdata);
            }
        }
    }, new VisibleTreeFilter());
    dbInstance.commitAndCloseSession();
    // retrieve my forums
    HttpGet method2 = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response2 = conn.execute(method2);
    assertEquals(200, response2.getStatusLine().getStatusCode());
    InputStream body2 = response2.getEntity().getContent();
    ForumVOes forums2 = conn.parse(body2, ForumVOes.class);
    Assert.assertNotNull(forums2);
    Assert.assertNotNull(forums2.getForums());
    Assert.assertEquals(1, forums2.getForums().length);
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) InputStream(java.io.InputStream) ForumVOes(org.olat.modules.fo.restapi.ForumVOes) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) HttpGet(org.apache.http.client.methods.HttpGet) 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) URI(java.net.URI) PublisherData(org.olat.core.commons.services.notifications.PublisherData) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) 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 38 with Forum

use of org.olat.modules.fo.Forum in project OpenOLAT by OpenOLAT.

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 39 with Forum

use of org.olat.modules.fo.Forum in project OpenOLAT by OpenOLAT.

the class WikiMainController method selectTab.

private void selectTab(UserRequest ureq, String command, String compName, WikiPage page, Wiki wiki) {
    // first release a potential lock on this page. only when the edit tab
    // is acitve
    // a lock will be created. in all other cases it is save to release an
    // existing lock
    doReleaseEditLock();
    if (command.equals(TabbedPaneChangedEvent.TAB_CHANGED)) {
        updatePageContext(ureq, page);
    }
    if (command.equals(TabbedPaneChangedEvent.TAB_CHANGED) && compName.equals("vc_article")) {
    /**
     *********************************************************************
     * tabbed pane change to article
     *********************************************************************
     */
    // if(page.getContent().equals(""))
    // wikiArticleComp.setVisible(false);
    // FIXME:guido: ... && comp == articleContent)) etc.
    } else if (command.equals(TabbedPaneChangedEvent.TAB_CHANGED) && compName.equals("vc_edit")) {
        /**
         *********************************************************************
         * tabbed pane change to edit tab
         *********************************************************************
         */
        wikiEditForm.resetUpdateComment();
        updateFileAndLinkList(wiki);
        // try to edit acquire lock for this page
        tryToSetEditLock(page, ureq, ores);
    } else if (command.equals(TabbedPaneChangedEvent.TAB_CHANGED) && compName.equals("vc_versions")) {
        /**
         *********************************************************************
         * tabbed pane change to versioning tab
         *********************************************************************
         */
        versioningTableModel = new HistoryTableDateModel(wiki.getHistory(page), getTranslator());
        removeAsListenerAndDispose(versioningTableCtr);
        versioningTableCtr = new TableController(tableConfig, ureq, getWindowControl(), getTranslator());
        listenTo(versioningTableCtr);
        versioningTableModel.addColumnDescriptors(versioningTableCtr);
        versioningTableCtr.setTableDataModel(versioningTableModel);
        versioningTableCtr.modelChanged();
        versioningTableCtr.setSortColumn(1, false);
        versioningContent.put("versions", versioningTableCtr.getInitialComponent());
        versioningContent.contextPut("diffs", diffs);
    } else if (command.equals(TabbedPaneChangedEvent.TAB_CHANGED) && compName.equals("vc_discuss")) {
        /**
         *********************************************************************
         * tabbed pane change to discussion tab
         *********************************************************************
         */
        Forum forum = null;
        if (page.getForumKey() > 0) {
            forum = ForumManager.getInstance().loadForum(Long.valueOf(page.getForumKey()));
        }
        if (forum == null) {
            forum = ForumManager.getInstance().addAForum();
            page.setForumKey(forum.getKey().longValue());
            WikiManager.getInstance().updateWikiPageProperties(ores, page);
        }
        ForumCallback forumCallback = securityCallback.getForumCallback();
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(forum);
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, getWindowControl());
        removeAsListenerAndDispose(forumController);
        forumController = new ForumController(ureq, bwControl, forum, forumCallback, false);
        listenTo(forumController);
        discussionContent.put("articleforum", forumController.getInitialComponent());
    }
    OLATResourceable pageRes = OresHelper.createOLATResourceableTypeWithoutCheck("path=" + page.getPageName());
    WindowControl wc = addToHistory(ureq, pageRes, null);
    OLATResourceable tabOres = tabs.getTabResource();
    addToHistory(ureq, tabOres, null, wc, true);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) TableController(org.olat.core.gui.components.table.TableController) ForumCallback(org.olat.modules.fo.ForumCallback) HistoryTableDateModel(org.olat.modules.wiki.versioning.HistoryTableDateModel) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) ForumController(org.olat.modules.fo.ui.ForumController) Forum(org.olat.modules.fo.Forum)

Example 40 with Forum

use of org.olat.modules.fo.Forum in project OpenOLAT by OpenOLAT.

the class GroupForumIndexer method doIndex.

/**
 * Index a forum in a group.
 * @param parentResourceContext
 * @param businessGroup
 * @param indexWriter
 * @throws IOException
 */
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (!(businessObj instanceof BusinessGroup))
        throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    ForumManager fom = ForumManager.getInstance();
    Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
        Long forumKey = forumKeyProperty.getLongValue();
        Forum forum = fom.loadForum(forumKey);
        SearchResourceContext forumSearchResourceContext = new SearchResourceContext(parentResourceContext);
        forumSearchResourceContext.setBusinessControlFor(BusinessGroupMainRunController.ORES_TOOLFORUM);
        forumSearchResourceContext.setDocumentType(TYPE);
        forumSearchResourceContext.setParentContextType(GroupDocument.TYPE);
        forumSearchResourceContext.setParentContextName(businessGroup.getName());
        if (forum == null) {
            // fxdiff: FXOLAT-104 warn about missing forums
            logError("found a forum-key " + forumKey + " for businessgroup " + businessGroup.getName() + " [" + businessGroup.getKey() + "] to index a forum that could not be " + "found by key! skip indexing, check if forum should still be enabled. context: " + forumSearchResourceContext.getResourceUrl(), null);
            return;
        }
        doIndexAllMessages(forumSearchResourceContext, forum, indexWriter);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) ForumManager(org.olat.modules.fo.manager.ForumManager) SearchResourceContext(org.olat.search.service.SearchResourceContext) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) Forum(org.olat.modules.fo.Forum)

Aggregations

Forum (org.olat.modules.fo.Forum)70 Identity (org.olat.core.id.Identity)24 ForumManager (org.olat.modules.fo.manager.ForumManager)20 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 FOCourseNode (org.olat.course.nodes.FOCourseNode)16 Test (org.junit.Test)14 ICourse (org.olat.course.ICourse)14 Message (org.olat.modules.fo.Message)14 Property (org.olat.properties.Property)14 HttpResponse (org.apache.http.HttpResponse)12 CollaborationTools (org.olat.collaboration.CollaborationTools)12 PublisherData (org.olat.core.commons.services.notifications.PublisherData)12 HttpGet (org.apache.http.client.methods.HttpGet)10 BusinessGroup (org.olat.group.BusinessGroup)10 File (java.io.File)8 URL (java.net.URL)8 Path (javax.ws.rs.Path)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 Roles (org.olat.core.id.Roles)8