Search in sources :

Example 56 with Forum

use of org.olat.modules.fo.Forum in project openolat by klemens.

the class UserMgmtTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    if (setuped)
        return;
    // create identities
    owner1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-zero");
    assertNotNull(owner1);
    id1 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-one-" + UUID.randomUUID().toString());
    id2 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-two");
    dbInstance.intermediateCommit();
    id2.getUser().setProperty("telMobile", "39847592");
    id2.getUser().setProperty("gender", "female");
    id2.getUser().setProperty("birthDay", "20091212");
    dbInstance.updateObject(id2.getUser());
    dbInstance.intermediateCommit();
    id3 = JunitTestHelper.createAndPersistIdentityAsUser("user-rest-three");
    OlatRootFolderImpl id3HomeFolder = new OlatRootFolderImpl(FolderConfig.getUserHome(id3.getName()), null);
    VFSContainer id3PublicFolder = (VFSContainer) id3HomeFolder.resolve("public");
    if (id3PublicFolder == null) {
        id3PublicFolder = id3HomeFolder.createChildContainer("public");
    }
    VFSItem portrait = id3PublicFolder.resolve("portrait.jpg");
    if (portrait == null) {
        URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
        File ioPortrait = new File(portraitUrl.toURI());
        FileUtils.copyFileToDirectory(ioPortrait, ((LocalImpl) id3PublicFolder).getBasefile(), false);
    }
    OLATResourceManager rm = OLATResourceManager.getInstance();
    // create course and persist as OLATResourceImpl
    OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", System.currentTimeMillis());
    OLATResource course = rm.createOLATResourceInstance(resourceable);
    dbInstance.saveObject(course);
    dbInstance.intermediateCommit();
    // create learn group
    // 1) context one: learning groups
    RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create groups without waiting list
    g1externalId = UUID.randomUUID().toString();
    g1 = businessGroupService.createBusinessGroup(null, "user-rest-g1", null, g1externalId, "all", 0, 10, false, false, c1);
    g2 = businessGroupService.createBusinessGroup(null, "user-rest-g2", null, 0, 10, false, false, c1);
    // members g1
    businessGroupRelationDao.addRole(id1, g1, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(id2, g1, GroupRoles.participant.name());
    // members g2
    businessGroupRelationDao.addRole(id2, g2, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(id1, g2, GroupRoles.participant.name());
    // 2) context two: right groups
    RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
    // groups
    g3ExternalId = UUID.randomUUID().toString();
    g3 = businessGroupService.createBusinessGroup(null, "user-rest-g3", null, g3ExternalId, "all", -1, -1, false, false, c2);
    g4 = businessGroupService.createBusinessGroup(null, "user-rest-g4", null, -1, -1, false, false, c2);
    // members
    businessGroupRelationDao.addRole(id1, g3, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, g4, GroupRoles.participant.name());
    dbInstance.closeSession();
    // add some collaboration tools
    CollaborationTools g1CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
    g1CTSMngr.setToolEnabled(CollaborationTools.TOOL_FORUM, true);
    // create the forum
    Forum g1Forum = g1CTSMngr.getForum();
    Message m1 = ForumManager.getInstance().createMessage(g1Forum, id1, false);
    m1.setTitle("Thread-1");
    m1.setBody("Body of Thread-1");
    ForumManager.getInstance().addTopMessage(m1);
    dbInstance.commitAndCloseSession();
    // add some folder tool
    CollaborationTools g2CTSMngr = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g2);
    g2CTSMngr.setToolEnabled(CollaborationTools.TOOL_FOLDER, true);
    OlatRootFolderImpl g2Folder = new OlatRootFolderImpl(g2CTSMngr.getFolderRelPath(), null);
    g2Folder.getBasefile().mkdirs();
    VFSItem groupPortrait = g2Folder.resolve("portrait.jpg");
    if (groupPortrait == null) {
        URL portraitUrl = UserMgmtTest.class.getResource("portrait.jpg");
        File ioPortrait = new File(portraitUrl.toURI());
        FileUtils.copyFileToDirectory(ioPortrait, g2Folder.getBasefile(), false);
    }
    dbInstance.commitAndCloseSession();
    // prepare some courses
    Identity author = JunitTestHelper.createAndPersistIdentityAsUser("auth-" + UUID.randomUUID().toString());
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(author);
    if (!repositoryService.hasRole(id1, entry, GroupRoles.participant.name())) {
        repositoryService.addRole(id1, entry, GroupRoles.participant.name());
    }
    demoCourse = CourseFactory.loadCourse(entry);
    TreeVisitor visitor = new TreeVisitor(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof FOCourseNode) {
                if (demoForumNode == null) {
                    demoForumNode = (FOCourseNode) node;
                    Forum courseForum = demoForumNode.loadOrCreateForum(demoCourse.getCourseEnvironment());
                    Message message1 = ForumManager.getInstance().createMessage(courseForum, id1, false);
                    message1.setTitle("Thread-1");
                    message1.setBody("Body of Thread-1");
                    ForumManager.getInstance().addTopMessage(message1);
                }
            } else if (node instanceof BCCourseNode) {
                if (demoBCCourseNode == null) {
                    demoBCCourseNode = (BCCourseNode) node;
                    OlatNamedContainerImpl container = BCCourseNode.getNodeFolderContainer(demoBCCourseNode, demoCourse.getCourseEnvironment());
                    VFSItem example = container.resolve("singlepage.html");
                    if (example == null) {
                        try {
                            InputStream htmlUrl = UserMgmtTest.class.getResourceAsStream("singlepage.html");
                            VFSLeaf htmlLeaf = container.createChildLeaf("singlepage.html");
                            IOUtils.copy(htmlUrl, htmlLeaf.getOutputStream(false));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }, demoCourse.getRunStructure().getRootNode(), false);
    visitor.visitAll();
    dbInstance.commitAndCloseSession();
    setuped = true;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) INode(org.olat.core.util.nodes.INode) Message(org.olat.modules.fo.Message) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResourceable(org.olat.core.id.OLATResourceable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) OLATResource(org.olat.resource.OLATResource) FOCourseNode(org.olat.course.nodes.FOCourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) URL(java.net.URL) Forum(org.olat.modules.fo.Forum) TreeVisitor(org.olat.core.util.tree.TreeVisitor) OlatNamedContainerImpl(org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BCCourseNode(org.olat.course.nodes.BCCourseNode) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceManager(org.olat.resource.OLATResourceManager) Identity(org.olat.core.id.Identity) File(java.io.File) Before(org.junit.Before)

Example 57 with Forum

use of org.olat.modules.fo.Forum in project openolat by klemens.

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

use of org.olat.modules.fo.Forum 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 59 with Forum

use of org.olat.modules.fo.Forum in project openolat by klemens.

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)

Example 60 with Forum

use of org.olat.modules.fo.Forum in project openolat by klemens.

the class DialogCourseNodeIndexer method doIndex.

@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, null);
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexWriter.addDocument(document);
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    DialogElementsManager dialogElmsMgr = CoreSpringFactory.getImpl(DialogElementsManager.class);
    List<DialogElement> elements = dialogElmsMgr.getDialogElements(entry, courseNode.getIdent());
    for (DialogElement element : elements) {
        Forum forum = element.getForum();
        doIndexAllMessages(courseNodeResourceContext, forum, indexWriter);
        doIndexFile(element, courseNodeResourceContext, indexWriter);
    }
}
Also used : SearchResourceContext(org.olat.search.service.SearchResourceContext) DialogElement(org.olat.course.nodes.dialog.DialogElement) RepositoryEntry(org.olat.repository.RepositoryEntry) Document(org.apache.lucene.document.Document) ForumMessageDocument(org.olat.search.service.document.ForumMessageDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) DialogElementsManager(org.olat.course.nodes.dialog.DialogElementsManager) 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