Search in sources :

Example 6 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericModerationDAO method getPost.

protected Post getPost(ResultSet rs) throws SQLException {
    Post p = new Post();
    p.setPostUsername(rs.getString("username"));
    p.setId(rs.getInt("post_id"));
    p.setUserId(rs.getInt("user_id"));
    p.setBbCodeEnabled(rs.getInt("enable_bbcode") == 1);
    p.setHtmlEnabled(rs.getInt("enable_html") == 1);
    p.setSmiliesEnabled(rs.getInt("enable_smilies") == 1);
    p.setSubject(rs.getString("post_subject"));
    p.setText(this.getPostTextFromResultSet(rs));
    return p;
}
Also used : Post(net.jforum.entities.Post)

Example 7 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class GenericPrivateMessageDAO method getPm.

protected PrivateMessage getPm(ResultSet rs, boolean full) throws SQLException {
    PrivateMessage pm = new PrivateMessage();
    Post p = new Post();
    pm.setId(rs.getInt("privmsgs_id"));
    pm.setType(rs.getInt("privmsgs_type"));
    p.setTime(new Date(rs.getTimestamp("privmsgs_date").getTime()));
    p.setSubject(rs.getString("privmsgs_subject"));
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    pm.setFormatedDate(df.format(p.getTime()));
    if (full) {
        UserDAO um = DataAccessDriver.getInstance().newUserDAO();
        pm.setFromUser(um.selectById(rs.getInt("privmsgs_from_userid")));
        pm.setToUser(um.selectById(rs.getInt("privmsgs_to_userid")));
        p.setBbCodeEnabled(rs.getInt("privmsgs_enable_bbcode") == 1);
        p.setSignatureEnabled(rs.getInt("privmsgs_attach_sig") == 1);
        p.setHtmlEnabled(rs.getInt("privmsgs_enable_html") == 1);
        p.setSmiliesEnabled(rs.getInt("privmsgs_enable_smilies") == 1);
        p.setText(this.getPmText(rs));
    }
    pm.setPost(p);
    return pm;
}
Also used : UserDAO(net.jforum.dao.UserDAO) Post(net.jforum.entities.Post) PrivateMessage(net.jforum.entities.PrivateMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 8 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class TopicRSS method prepareRSS.

protected void prepareRSS() {
    for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
        Post post = (Post) iter.next();
        post.setBbCodeEnabled(false);
        post.setSmiliesEnabled(false);
        RSSItem item = new RSSItem();
        item.setAuthor(post.getPostUsername());
        item.setPublishDate(RSSUtils.formatDate(post.getTime()));
        item.setLink(this.forumLink + "posts/preList/" + post.getTopicId() + "/" + post.getId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
        item.setTitle(post.getSubject());
        item.setContentType(RSSAware.CONTENT_HTML);
        item.setDescription(PostCommon.preparePostForDisplay(post).getText());
        this.rss.addItem(item);
    }
    super.setRSS(this.rss);
}
Also used : Post(net.jforum.entities.Post) Iterator(java.util.Iterator)

Example 9 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class SummaryTest method testListPosts.

public void testListPosts() throws Exception {
    SummaryModel model = new SummaryModel();
    //      Gets a Date seven days before now
    long weekBefore = Calendar.getInstance().getTimeInMillis() - (7 * 1000 * 60 * 60 * 24);
    Date firstDate = new Date(weekBefore);
    System.out.println(firstDate);
    Collection posts = model.listPosts(firstDate, new Date());
    Iterator iter = posts.iterator();
    while (iter.hasNext()) {
        Post post = (Post) iter.next();
        System.out.println(post.getSubject());
    }
    assertTrue(posts.size() > 0);
}
Also used : Post(net.jforum.entities.Post) Iterator(java.util.Iterator) Collection(java.util.Collection) Date(java.util.Date)

Example 10 with Post

use of net.jforum.entities.Post in project jforum2 by rafaelsteil.

the class POPListenerTestCase method testInReplyToCreateNewTopicThenReply.

/**
	 * Create a new topic, then send a message with the In-Reply-To header, 
	 * which should create an answer to the previously created topic
	 * @throws Exception
	 */
public void testInReplyToCreateNewTopicThenReply() throws Exception {
    int beforeTopicId = this.maxTopicId();
    String sender = "ze@zinho.com";
    String subject = "Mail Message " + new Date();
    String forumAddress = "forum_test@jforum.testcase";
    String contents = "Mail message contents " + new Date();
    this.sendMessage(sender, subject, forumAddress, contents, null);
    int afterTopicId = this.maxTopicId();
    assertTrue("The message was not inserted", afterTopicId > beforeTopicId);
    try {
        this.assertPost(afterTopicId, sender, subject, contents);
        // Ok, now send a new message, replying to the previously topic
        subject = "Reply subject for topic " + afterTopicId;
        contents = "Changed contents, replying tpoic " + afterTopicId;
        this.sendMessage(sender, subject, forumAddress, contents, MessageId.buildMessageId(7777, afterTopicId, 999999));
        assertTrue("A new message was created, instead of a reply", afterTopicId == maxTopicId());
        PostDAO postDAO = DataAccessDriver.getInstance().newPostDAO();
        List posts = postDAO.selectAllByTopic(afterTopicId);
        assertTrue("There should be two posts", posts.size() == 2);
        // The first message was already validated
        Post p = (Post) posts.get(1);
        User user = DataAccessDriver.getInstance().newUserDAO().selectById(p.getUserId());
        assertNotNull("User should not be null", user);
        assertEquals("sender", sender, user.getEmail());
        assertEquals("subject", subject, p.getSubject());
        assertEquals("text", contents, p.getText());
    } finally {
        this.deleteTopic(afterTopicId);
    }
}
Also used : User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) List(java.util.List) Date(java.util.Date)

Aggregations

Post (net.jforum.entities.Post)47 List (java.util.List)20 PostDAO (net.jforum.dao.PostDAO)15 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 Iterator (java.util.Iterator)9 DatabaseException (net.jforum.exceptions.DatabaseException)9 ResultSet (java.sql.ResultSet)8 Topic (net.jforum.entities.Topic)8 User (net.jforum.entities.User)8 TopicDAO (net.jforum.dao.TopicDAO)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 UserDAO (net.jforum.dao.UserDAO)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ModerationLog (net.jforum.entities.ModerationLog)4 ForumDAO (net.jforum.dao.ForumDAO)3 AttachmentException (net.jforum.exceptions.AttachmentException)3 IOException (java.io.IOException)2