Discussions tasks

Retrieving the discussions from a forum

Example of browsing the discussions of a forum.

public void forum_getDiscussions( IForumModule module, IContext context, IForum forum ) throws Exception
{
        // retrieving all the discussions of a forum
        Collection discussions = module.getDiscussions( context, forum );
        for ( Iterator iterator = discussions.iterator() ; iterator.hasNext() ; )
        {
                IDiscussion discussion = (IDiscussion)iterator.next();
        }
}

Retrieving a discussion from a forum

Example of browsing a discussion of a forum.

public void forum_getDiscussion( IForumModule module, IContext context, IForum forum ) throws Exception
{
        IDiscussion discussion = module.getDiscussion( context, forum, "Cas d'intégration avec les forums" );
}

Creating a discussion

Example of creating a new discussion.

public class BaseTestCase extends TestCase
{
        public void forum_createDiscussion( IForumModule module, IContext context, IForum forum ) throws Exception
        {
                IDiscussion discussion = module.createDiscussion( context, forum, "Cas d'intégration avec les forums", "Comment peut-on intégrer les forums dans les documents processus ?" );
        }
}       

Retrieving the discussion posts

Example of retrieving the discussion answers.

public void forum_getPosts( IForumModule module, IContext context, IDiscussion discussion ) throws Exception
{
        Collection posts = module.getPosts( context, discussion );
        for ( Iterator iterator = posts.iterator() ; iterator.hasNext() ; )
        {
                IPost post = (IPost)iterator.next();
                System.out.println( "Post : " + post.getLabel() );
        }
}
        

Answering a discussion

Example of answering to a discussion or a post. This example presents the method getFirstPost() and the possibility to specify a private answer.

public void forum_reply( IForumModule module, IContext context, IDiscussion discussion ) throws Exception
{
        // answer to a discussion start
        IPost post = module.replyTo( context, discussion, discussion.getFirstPost().getLabel(), "Pourquoi pas, très bonne idée." );

        // answer a discussion in private
        IPost repliedPost = module.replyTo( context, post, post.getLabel(), "Oui, mais c'est peut-être un peu chaud, non ?" );

        repliedPost.setPrivate( true );
}
        

Pining a discussion

Example enabling to manage pins on discussions.

public void forum_pinDiscussion( IForumModule module, IContext context, IDiscussion discussion ) throws Exception
{
        module.pin( context, discussion );
        if ( discussion.isPinned() )
        {
                module.unPin( context, discussion );
        }       
}
        

Locking a discussion

Example enabling to manage locks on discussions.

public void forum_lockDiscussion( IForumModule module, IContext context, IDiscussion discussion ) throws Exception
{
        module.lock( context, discussion );
        if ( discussion.isLocked() )
        {
                module.unLock( context, discussion );
        }
}