Search in sources :

Example 16 with Attachment

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);
    }
}
Also used : Post(it.vige.rubia.model.Post) Poster(it.vige.rubia.model.Poster) Attachment(it.vige.rubia.model.Attachment) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 17 with Attachment

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);
    }
}
Also used : Post(it.vige.rubia.model.Post) PollOption(it.vige.rubia.model.PollOption) Attachment(it.vige.rubia.model.Attachment) Topic(it.vige.rubia.model.Topic) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 18 with Attachment

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) Attachment(it.vige.rubia.model.Attachment) IOException(java.io.IOException)

Example 19 with Attachment

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;
}
Also used : Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) Poster(it.vige.rubia.model.Poster) Attachment(it.vige.rubia.model.Attachment) ParseException(java.text.ParseException) Date(java.util.Date)

Example 20 with Attachment

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;
}
Also used : Attachment(it.vige.rubia.model.Attachment) WebElement(org.openqa.selenium.WebElement) LinkedList(java.util.LinkedList)

Aggregations

Attachment (it.vige.rubia.model.Attachment)34 Post (it.vige.rubia.model.Post)25 Topic (it.vige.rubia.model.Topic)23 Forum (it.vige.rubia.model.Forum)21 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)20 Poll (it.vige.rubia.model.Poll)19 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)19 PollOption (it.vige.rubia.model.PollOption)18 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)18 Category (it.vige.rubia.model.Category)15 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)13 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)13 BeforeClass (org.junit.BeforeClass)11 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)10 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)9 Test (org.junit.Test)7 WebElement (org.openqa.selenium.WebElement)7 LockTopic.lockTopic (it.vige.rubia.selenium.moderate.action.LockTopic.lockTopic)5 MoveTopic.moveTopic (it.vige.rubia.selenium.moderate.action.MoveTopic.moveTopic)5 RemoveTopic.removeTopic (it.vige.rubia.selenium.moderate.action.RemoveTopic.removeTopic)5