Search in sources :

Example 21 with Forum

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

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

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

the class FOCourseNodeIndexer method doIndexForum.

/**
 * Index a forum in a course.
 * @param parentResourceContext
 * @param course
 * @param courseNode
 * @param indexWriter
 * @throws IOException
 */
private void doIndexForum(SearchResourceContext parentResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
    if (log.isDebug())
        log.debug("Index Course Forum...");
    ForumManager fom = ForumManager.getInstance();
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    Property forumKeyProperty = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
        Long forumKey = forumKeyProperty.getLongValue();
        Forum forum = fom.loadForum(forumKey);
        parentResourceContext.setDocumentType(TYPE);
        doIndexAllMessages(parentResourceContext, forum, indexWriter);
    }
}
Also used : ForumManager(org.olat.modules.fo.manager.ForumManager) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) Forum(org.olat.modules.fo.Forum)

Example 23 with Forum

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

the class CourseGroupWebService 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 = bgs.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 24 with Forum

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

the class OLATUpgrade_12_3_0 method createDialogElement.

private void createDialogElement(DialogElement element, RepositoryEntry entry, String nodeIdent) {
    try {
        Identity author = null;
        if (StringHelper.isLong(element.getAuthor())) {
            author = securityManager.loadIdentityByKey(Long.valueOf(element.getAuthor()));
        } else if (StringHelper.containsNonWhitespace(element.getAuthor())) {
            author = securityManager.findIdentityByName(element.getAuthor());
        }
        Forum forum = forumManager.loadForum(element.getForumKey());
        if (forum == null) {
            log.error("Missing forum", null);
            return;
        }
        Object currentElement = dialogElementsManager.getDialogElementByForum(forum.getKey());
        if (currentElement != null) {
            return;
        }
        Date date = element.getDate() == null ? new Date() : element.getDate();
        DialogElementImpl el = new DialogElementImpl();
        el.setCreationDate(date);
        el.setLastModified(date);
        el.setFilename(element.getFilename());
        el.setSize(getFileSize(forum.getKey()));
        el.setEntry(entry);
        el.setSubIdent(nodeIdent);
        el.setAuthor(author);
        el.setForum(forum);
        dbInstance.getCurrentEntityManager().persist(el);
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : DialogElementImpl(org.olat.course.nodes.dialog.model.DialogElementImpl) Identity(org.olat.core.id.Identity) Date(java.util.Date) ConversionException(com.thoughtworks.xstream.converters.ConversionException) Forum(org.olat.modules.fo.Forum)

Example 25 with Forum

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

the class ForumNodeForumCallback method loadForum.

private Forum loadForum(CourseEnvironment courseEnv, Property prop) {
    final ForumManager fom = CoreSpringFactory.getImpl(ForumManager.class);
    Long forumKey = prop.getLongValue();
    Forum forum = fom.loadForum(forumKey);
    if (forum == null) {
        throw new OLATRuntimeException(FOCourseNode.class, "Tried to load forum with key " + forumKey.longValue() + " in course " + courseEnv.getCourseResourceableId() + " for node " + getIdent() + " as defined in course node property but forum manager could not load forum.", null);
    }
    return forum;
}
Also used : ForumManager(org.olat.modules.fo.manager.ForumManager) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) 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