use of net.jforum.dao.PostDAO 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);
}
}
use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.
the class GenericTopicDAO method deleteTopics.
public void deleteTopics(List topics, boolean fromModeration) {
// Topic
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.delete"));
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
for (Iterator iter = topics.iterator(); iter.hasNext(); ) {
Topic topic = (Topic) iter.next();
// Remove watches
this.removeSubscriptionByTopic(topic.getId());
// Remove the messages
postDao.deleteByTopic(topic.getId());
// Remove the poll
pollDao.deleteByTopicId(topic.getId());
// Delete the topic itself
p.setInt(1, topic.getId());
p.executeUpdate();
if (!fromModeration) {
forumDao.decrementTotalTopics(topic.getForumId(), 1);
}
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.
the class POPListenerTestCase method assertPost.
/**
* Asserts the post instance, after execution some part of the testcase
* @param topicId the topic's id of the new message
* @param sender the matching sender email
* @param subject the matching subject
* @param contents the matching message contents
*/
private void assertPost(int topicId, String sender, String subject, String contents) {
PostDAO postDAO = DataAccessDriver.getInstance().newPostDAO();
List posts = postDAO.selectAllByTopic(topicId);
assertTrue("There should be exactly one post", posts.size() == 1);
Post p = (Post) posts.get(0);
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());
}
use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.
the class ModerationAction method showActivityLog.
public void showActivityLog() {
if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG)) {
this.denied();
return;
}
ModerationLogDAO dao = DataAccessDriver.getInstance().newModerationLogDAO();
int start = ViewCommon.getStartPage();
int recordsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
List list = dao.selectAll(start, recordsPerPage);
boolean canAccessFullModerationLog = SecurityRepository.canAccess(SecurityConstants.PERM_FULL_MODERATION_LOG);
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
ModerationLog log = (ModerationLog) iter.next();
if (log.getPostId() > 0) {
Post post = postDao.selectById(log.getPostId());
if (post.getId() > 0 && ForumRepository.getForum(post.getForumId()) == null) {
iter.remove();
continue;
}
} else if (log.getTopicId() > 0) {
Topic topic = topicDao.selectRaw(log.getTopicId());
if (topic.getId() > 0 && ForumRepository.getForum(topic.getForumId()) == null) {
iter.remove();
continue;
}
}
if (log.getOriginalMessage() != null && canAccessFullModerationLog) {
Post post = new Post();
post.setText(log.getOriginalMessage());
log.setOriginalMessage(PostCommon.preparePostForDisplay(post).getText());
}
}
this.setTemplateName(TemplateKeys.MODERATION_SHOW_ACTIVITY_LOG);
this.context.put("activityLog", list);
this.context.put("canAccessFullModerationLog", canAccessFullModerationLog);
int totalRecords = dao.totalRecords();
ViewCommon.contextToPagination(start, totalRecords, recordsPerPage);
}
use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.
the class PostAction method listByUser.
public void listByUser() {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
User u = um.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
int start = ViewCommon.getStartPage();
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
List posts = pm.selectByUserByLimit(u.getId(), start, postsPerPage);
int totalMessages = pm.countUserPosts(u.getId());
// get list of forums
Map topics = new HashMap();
Map forums = new HashMap();
for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
Post p = (Post) iter.next();
if (!topics.containsKey(new Integer(p.getTopicId()))) {
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = tm.selectRaw(p.getTopicId());
}
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(t.getForumId())));
this.context.put("am", new AttachmentCommon(this.request, t.getForumId()));
topics.put(new Integer(t.getId()), t);
}
if (!forums.containsKey(new Integer(p.getForumId()))) {
Forum f = ForumRepository.getForum(p.getForumId());
if (f == null) {
// Ok, probably the user does not have permission to see this forum
iter.remove();
totalMessages--;
continue;
}
forums.put(new Integer(f.getId()), f);
}
PostCommon.preparePostForDisplay(p);
}
this.setTemplateName(TemplateKeys.POSTS_USER_POSTS_LIST);
this.context.put("canDownloadAttachments", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
this.context.put("posts", posts);
this.context.put("topics", topics);
this.context.put("forums", forums);
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("PostShow.userPosts") + " " + u.getUsername());
this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
ViewCommon.contextToPagination(start, totalMessages, count);
}
Aggregations