Search in sources :

Example 6 with Forum

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

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

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

the class NotificationsTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    if (!setup) {
        userSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-1");
        userAndForumSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-2");
        JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-3");
        SubscriptionContext subContext = UsersSubscriptionManager.getInstance().getNewUsersSubscriptionContext();
        PublisherData publisherData = UsersSubscriptionManager.getInstance().getNewUsersPublisherData();
        if (!notificationManager.isSubscribed(userSubscriberId, subContext)) {
            notificationManager.subscribe(userSubscriberId, subContext, publisherData);
        }
        if (!notificationManager.isSubscribed(userAndForumSubscriberId, subContext)) {
            notificationManager.subscribe(userAndForumSubscriberId, subContext, publisherData);
        }
        // create a forum
        forum = ForumManager.getInstance().addAForum();
        Message m1 = createMessage(userSubscriberId, forum);
        Assert.assertNotNull(m1);
        // subscribe
        SubscriptionContext forumSubContext = new SubscriptionContext("NotificationRestCourse", forum.getKey(), "2387");
        PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), "");
        if (!notificationManager.isSubscribed(userAndForumSubscriberId, forumSubContext)) {
            notificationManager.subscribe(userAndForumSubscriberId, forumSubContext, forumPdata);
        }
        notificationManager.markPublisherNews(forumSubContext, userSubscriberId, true);
        // generate one notification
        String randomLogin = UUID.randomUUID().toString().replace("-", "");
        JunitTestHelper.createAndPersistIdentityAsUser(randomLogin);
        setup = true;
    }
    dbInstance.commitAndCloseSession();
}
Also used : Message(org.olat.modules.fo.Message) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Forum(org.olat.modules.fo.Forum) Before(org.junit.Before)

Example 8 with Forum

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

the class ForumCourseNodeWebService method getForumContent.

@Path("{nodeId}/forum")
public ForumWebService getForumContent(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!CourseWebService.isCourseAccessible(course, false, request)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    CourseNode courseNode = course.getRunStructure().getNode(nodeId);
    if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    }
    UserRequest ureq = getUserRequest(request);
    CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
    if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
        FOCourseNode forumNode = (FOCourseNode) courseNode;
        Forum forum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
        return new ForumWebService(forum);
    } else {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 9 with Forum

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

the class ForumImportWebService method getForumWebservice.

/**
 * Web service to manage a forum
 * @param forumKey The key of the forum
 * @return
 */
@Path("{forumKey}")
public ForumWebService getForumWebservice(@PathParam("forumKey") Long forumKey) {
    ForumManager fom = ForumManager.getInstance();
    Forum forum = fom.loadForum(forumKey);
    return new ForumWebService(forum);
}
Also used : ForumManager(org.olat.modules.fo.manager.ForumManager) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 10 with Forum

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

the class ForumManager method deleteForum.

/**
 * @param forumKey
 */
public void deleteForum(Long forumKey) {
    Forum foToDel = loadForum(forumKey);
    if (foToDel == null)
        throw new AssertException("forum to delete was not found: key=" + forumKey);
    // delete properties, messages and the forum itself
    doDeleteForum(foToDel);
    // delete directory for messages with attachments
    deleteForumContainer(forumKey);
}
Also used : AssertException(org.olat.core.logging.AssertException) 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