use of it.vige.rubia.model.Post in project rubia-forums by flashboss.
the class ForumsModuleImpl method findFirstPost.
@Override
public Post findFirstPost(Topic topic) throws ModuleException {
try {
TypedQuery<Post> query = em.createNamedQuery("findFirstPost", Post.class);
query.setParameter("lastPostDate", topic.getLastPostDate(), DATE);
query.setParameter("topicId", "" + topic.getId());
query.setFirstResult(0);
query.setMaxResults(1);
Post firstPost = uniqueElement(query.getResultList());
return firstPost;
} catch (Exception e) {
log.error(e);
return null;
}
}
use of it.vige.rubia.model.Post in project rubia-forums by flashboss.
the class ForumsModuleImpl method createPost.
@Override
public Post createPost(Topic topic, Forum forum, Message message, Date creationDate, Poster poster, Collection<Attachment> attachments) throws ModuleException {
try {
Poster posterOld = findPosterByUserId(poster.getUserId());
if (posterOld == null) {
em.persist(poster);
}
em.merge(poster);
Post post = new Post();
post.setMessage(message);
post.setCreateDate(creationDate);
post.setPoster(poster);
if (attachments != null)
for (Attachment attachment : attachments) {
em.persist(attachment);
post.addAttachment(attachment);
}
em.persist(post);
em.flush();
post.setTopic(topic);
topic.setLastPostDate(post.getCreateDate());
topic.setReplies(topic.getReplies() + 1);
em.merge(topic);
forum.addPostSize();
em.merge(forum);
notificationEngine.scheduleForNotification(post.getId(), MODE_REPLY);
em.flush();
return post;
} catch (Exception e) {
String errorMessage = "Cannot create topic";
throw new ModuleException(errorMessage, e);
}
}
use of it.vige.rubia.model.Post in project rubia-forums by flashboss.
the class ForumsModuleImpl method createTopic.
@Override
public Post createTopic(Forum forum, Message message, Date creationDate, Poster poster, Poll poll, Collection<Attachment> attachments, TopicType type) throws ModuleException {
try {
if (poster.getId() == null || em.find(Poster.class, poster.getId()) == null)
em.persist(poster);
em.merge(poster);
em.persist(poll);
for (PollOption pollOption : poll.getOptions()) em.persist(pollOption);
em.flush();
Post post = new Post();
post.setMessage(message);
post.setCreateDate(creationDate);
post.setPoster(poster);
if (attachments != null)
for (Attachment attachment : attachments) {
em.persist(attachment);
post.addAttachment(attachment);
}
Topic topic = new Topic();
topic.setSubject(message.getSubject());
topic.setForum(forum);
topic.setPoster(poster);
post.setTopic(topic);
topic.setLastPostDate(creationDate);
topic.setType(type);
topic.setStatus(TOPIC_UNLOCKED);
topic.setPoll(poll);
em.persist(topic);
em.persist(post);
em.flush();
forum.addTopicSize();
forum.addPostSize();
em.merge(forum);
post.setTopic(topic);
em.persist(post);
notificationEngine.scheduleForNotification(post.getId(), MODE_POST);
em.flush();
return post;
} catch (Exception e) {
String errorMessage = "Cannot create topic";
throw new ModuleException(errorMessage, e);
}
}
use of it.vige.rubia.model.Post in project rubia-forums by flashboss.
the class EditPost method start.
// action processing
// methods-----------------------------------------------------------------------------------------------------
/**
* @return the navigation state of the application
*/
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String start() {
String navState = null;
try {
int postId = -1;
String p = getParameter(p_postId);
if (p != null && p.trim().length() > 0) {
postId = parseInt(p);
}
// grab the post information
if (postId != -1) {
// re-initialize this controller to edit the specified post
cleanup();
// get the post from the module
Post post = forumsModule.findPostById(postId);
Topic topic = post.getTopic();
// set the selected post's topic id
topicId = topic.getId().intValue();
this.postId = postId;
// set the subject of the post
subject = post.getMessage().getSubject();
// set the message of the post
message = post.getMessage().getText();
// set the topicType
topicType = topic.getType();
// setup poll related information
setupPoll(topic.getPoll());
attachments = forumsModule.findAttachments(post);
// setup the attachment related information
List<Post> posts = forumsModule.findPostsByTopicId(topic);
isFirstPost = false;
if (posts.get(0).getId().intValue() == post.getId().intValue()) {
isFirstPost = true;
}
}
navState = START_EDIT_POST;
} catch (Exception e) {
handleException(e);
}
return navState;
}
use of it.vige.rubia.model.Post in project rubia-forums by flashboss.
the class Search method search.
public String search() throws Exception {
int currentPage = 0;
SearchCriteria criteria = getSearchCriteria();
criteria.setPageSize(userPreferences.getPostsPerTopic());
criteria.setPageNumber(currentPage);
if (criteria.getDisplayAs().equals(POSTS.name())) {
ResultPage<Post> resultPage = forumsSearchModule.findPosts(criteria);
viewSearch.setPosts(resultPage.getPage());
viewSearch.setPostsDataModel(new ListDataModel<Post>(viewSearch.getPosts()));
if (viewSearch.getPosts() != null && viewSearch.getPosts().isEmpty()) {
viewSearch.setPosts(null);
viewSearch.setPostsDataModel(null);
}
return "posts";
} else {
ResultPage<Topic> resultPage = forumsSearchModule.findTopics(criteria);
viewSearch.setTopics(resultPage.getPage());
viewSearch.setTopicsDataModel(new ListDataModel<Topic>(viewSearch.getTopics()));
if (viewSearch.getTopics() == null || viewSearch.getTopics().isEmpty()) {
viewSearch.setTopics(null);
viewSearch.setTopicsDataModel(null);
} else {
viewSearch.setTopicLastPosts(forumsModule.findLastPostsOfTopics(viewSearch.getTopics()));
}
return "topics";
}
}
Aggregations