Search in sources :

Example 46 with Forum

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

the class ForumCourseNodeWebService method createForumVO.

public static ForumVO createForumVO(ICourse course, FOCourseNode forumNode, Set<Long> subscribed) {
    Forum forum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
    ForumVO forumVo = new ForumVO();
    forumVo.setName(course.getCourseTitle());
    forumVo.setDetailsName(forumNode.getShortTitle());
    if (subscribed != null && subscribed.contains(forum.getKey())) {
        forumVo.setSubscribed(true);
    } else {
        forumVo.setSubscribed(false);
    }
    forumVo.setCourseKey(course.getResourceableId());
    forumVo.setCourseNodeId(forumNode.getIdent());
    forumVo.setForumKey(forum.getKey());
    return forumVo;
}
Also used : Forum(org.olat.modules.fo.Forum)

Example 47 with Forum

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

the class GroupMgmtTest method setUp.

/**
 * Set up a course with learn group and group area
 * @see org.olat.test.OlatJerseyTestCase#setUp()
 */
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    conn = new RestConnection();
    // create a course with learn group
    owner1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-one");
    owner2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-two");
    owner3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-three");
    part1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-four");
    part2 = JunitTestHelper.createAndPersistIdentityAsUser("rest-five");
    part3 = JunitTestHelper.createAndPersistIdentityAsUser("rest-six");
    OLATResourceManager rm = OLATResourceManager.getInstance();
    // create course and persist as OLATResourceImpl
    OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
    course = rm.findOrPersistResourceable(resourceable);
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
    DBFactory.getInstance().commit();
    assertNotNull(re);
    // create learn group
    // 1) context one: learning groups
    RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create groups without waiting list
    g1 = businessGroupService.createBusinessGroup(null, "rest-g1", null, 0, 10, false, false, c1);
    g2 = businessGroupService.createBusinessGroup(null, "rest-g2", null, 0, 10, false, false, c1);
    DBFactory.getInstance().commit();
    // permission to see owners and participants
    businessGroupService.updateDisplayMembers(g1, false, false, false, false, false, false, false);
    businessGroupService.updateDisplayMembers(g2, true, true, false, false, false, false, false);
    // members g1
    businessGroupRelationDao.addRole(owner1, g1, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(owner2, g1, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(part1, g1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(part2, g1, GroupRoles.participant.name());
    // members g2
    businessGroupRelationDao.addRole(owner1, g2, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(part1, g2, GroupRoles.participant.name());
    // 2) context two: right groups
    RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
    // groups
    g3 = businessGroupService.createBusinessGroup(null, "rest-g3", null, -1, -1, false, false, c2);
    g4 = businessGroupService.createBusinessGroup(null, "rest-g4", null, -1, -1, false, false, c2);
    DBFactory.getInstance().commit();
    // members
    businessGroupRelationDao.addRole(owner1, g3, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(owner2, g4, GroupRoles.participant.name());
    // 3) collaboration tools
    CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
    collabTools1.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    collabTools1.setToolEnabled(CollaborationTools.TOOL_WIKI, true);
    collabTools1.saveNews("<p>Hello world</p>");
    try {
        collabTools1.createForumController(null, null, true, false, null);
    } catch (Exception e) {
    // will fail but generate the forum key
    }
    CollaborationTools collabTools2 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    collabTools2.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    // simulate user clicks
    DBFactory.getInstance().closeSession();
    // 4) fill forum for g1
    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(g1);
    Property forumKeyProperty = npm.findProperty(null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    ForumManager fm = ForumManager.getInstance();
    Forum forum = fm.loadForum(forumKeyProperty.getLongValue());
    m1 = fm.createMessage(forum, owner1, false);
    m1.setTitle("Thread-1");
    m1.setBody("Body of Thread-1");
    fm.addTopMessage(m1);
    m2 = fm.createMessage(forum, owner2, false);
    m2.setTitle("Thread-2");
    m2.setBody("Body of Thread-2");
    fm.addTopMessage(m2);
    DBFactory.getInstance().intermediateCommit();
    m3 = fm.createMessage(forum, owner3, false);
    m3.setTitle("Message-1.1");
    m3.setBody("Body of Message-1.1");
    fm.replyToMessage(m3, m1);
    m4 = fm.createMessage(forum, part1, false);
    m4.setTitle("Message-1.1.1");
    m4.setBody("Body of Message-1.1.1");
    fm.replyToMessage(m4, m3);
    m5 = fm.createMessage(forum, part2, false);
    m5.setTitle("Message-1.2");
    m5.setBody("Body of Message-1.2");
    fm.replyToMessage(m5, m1);
    DBFactory.getInstance().intermediateCommit();
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ForumManager(org.olat.modules.fo.manager.ForumManager) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) RepositoryEntry(org.olat.repository.RepositoryEntry) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) Property(org.olat.properties.Property) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryService(org.olat.repository.RepositoryService) Forum(org.olat.modules.fo.Forum) Before(org.junit.Before)

Example 48 with Forum

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

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

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

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

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

the class CollaborationTools method getForum.

public Forum getForum() {
    final ForumManager fom = ForumManager.getInstance();
    final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
    Property forumProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    Forum forum;
    if (forumProperty != null) {
        forum = fom.loadForum(forumProperty.getLongValue());
    } else {
        forum = coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerCallback<Forum>() {

            @Override
            public Forum execute() {
                Forum aforum;
                Long forumKey;
                Property forumKeyProperty = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
                if (forumKeyProperty == null) {
                    // First call of forum, create new forum and save
                    aforum = fom.addAForum();
                    forumKey = aforum.getKey();
                    if (log.isDebug()) {
                        log.debug("created new forum in collab tools: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
                    }
                    forumKeyProperty = npm.createPropertyInstance(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM, null, forumKey, null, null);
                    npm.saveProperty(forumKeyProperty);
                } else {
                    // Forum does already exist, load forum with key from properties
                    forumKey = forumKeyProperty.getLongValue();
                    aforum = fom.loadForum(forumKey);
                    if (aforum == null) {
                        throw new AssertException("Unable to load forum with key " + forumKey.longValue() + " for ores " + ores.getResourceableTypeName() + " with key " + ores.getResourceableId());
                    }
                    if (log.isDebug()) {
                        log.debug("loading forum in collab tools from properties: foid::" + forumKey.longValue() + " for ores::" + ores.getResourceableTypeName() + "/" + ores.getResourceableId());
                    }
                }
                return aforum;
            }
        });
    }
    return forum;
}
Also used : AssertException(org.olat.core.logging.AssertException) ForumManager(org.olat.modules.fo.manager.ForumManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) SyncerCallback(org.olat.core.util.coordinate.SyncerCallback) 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