use of it.vige.rubia.model.Attachment 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.Attachment 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.Attachment in project rubia-forums by flashboss.
the class DownloadFilter method doFilter.
/**
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException {
try {
if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
// get this attachment data
int attachmentId = Integer.parseInt(request.getParameter("id"));
Attachment attachment = forumsModule.findAttachmentById(attachmentId);
// set the attachment headers
httpResponse.setContentLength((int) attachment.getSize());
httpResponse.setContentType(attachment.getContentType());
httpResponse.setHeader("Content-Disposition", "attachment; filename=" + attachment.getName());
// now send the actual content down
InputStream is = new ByteArrayInputStream(attachment.getContent());
OutputStream os = httpResponse.getOutputStream();
transferBytes(is, os);
os.flush();
// cleanup
if (is != null) {
is.close();
}
} else {
response.setContentType("text/html");
response.getWriter().write(WRONG_REQ_RESP);
}
} catch (Exception e) {
log.error(e);
}
}
use of it.vige.rubia.model.Attachment in project rubia-forums by flashboss.
the class ViewPagePostSearch method getPost.
private static Post getPost(WebDriver driver, WebElement element) {
Post post = new Post();
post.setPoster(new Poster(element.findElement(xpath(POST_POSTER)).getText()));
String createdDate = element.findElement(xpath(POST_CREATED_DATE)).getText().replace(getBundle("ResourceJSF").getString("Posted") + ": ", "");
try {
Date date = dateFormat.parse(createdDate);
post.setCreateDate(date);
} catch (ParseException e) {
}
Message message = new Message();
message.setSubject(element.findElement(xpath(POST_SUBJECT)).getText().replace(getBundle("ResourceJSF").getString("Post_subject") + ": ", ""));
message.setText(element.findElement(xpath(POST_TEXT)).getText());
post.setMessage(message);
List<Attachment> attachments = getAttachmentsOfCurrentPostInPageNoParent(driver, post);
post.setAttachments(attachments);
return post;
}
use of it.vige.rubia.model.Attachment in project rubia-forums by flashboss.
the class VerifyAttachment method getAttachmentsOfCurrentPost.
private static List<Attachment> getAttachmentsOfCurrentPost(WebDriver driver, WebElement postComponent) {
List<Attachment> attachments = new LinkedList<Attachment>();
List<WebElement> attachmentComponents = postComponent.findElements(className(ATTACHMENT_LIST));
for (WebElement attachmentComponent : attachmentComponents) {
Attachment attachment = getAttachment(attachmentComponent);
addParents(driver, attachment);
attachments.add(attachment);
}
return attachments;
}
Aggregations