Search in sources :

Example 6 with Message

use of it.vige.rubia.model.Message in project rubia-forums by flashboss.

the class ViewAtomLink method getPage.

public static Topic getPage(WebDriver driver, Topic topic) {
    VerifyTopic.goTo(driver, topic);
    goTo(driver);
    Topic result = new Topic();
    result.setSubject(driver.findElement(id(FEED_TITLE_TEXT)).getText().split(": ")[1]);
    String[] splittedText = driver.findElement(id(FEED_SUBTITLE_TEXT)).getText().split(" in topic | in forum | in category ");
    result.setForum(new Forum(splittedText[2]));
    result.getForum().setCategory(new Category(splittedText[3]));
    List<Post> posts = new ArrayList<Post>();
    int entriesSize = driver.findElements(className(ENTRY_LINK)).size();
    DateFormat dateFormat = new SimpleDateFormat("d MMM yyyy, HH:mm");
    for (int i = 0; i < entriesSize; i++) {
        WebElement entry = driver.findElements(className(ENTRY_LINK)).get(i);
        String[] entryText = entry.getText().split(BY);
        String lastUpdated = entry.findElement(className(LAST_UPDATED)).getText();
        Post post = new Post(entryText[0]);
        post.setPoster(new Poster(entryText[1].split("\n")[0]));
        try {
            post.setCreateDate(dateFormat.parse(lastUpdated));
        } catch (ParseException e) {
        }
        post.setMessage(new Message(entry.findElement(className(FEED_ENTRY_CONTENT)).getText()));
        post.getMessage().setSubject(entryText[0]);
        posts.add(post);
        WebElement entryLink = driver.findElement(linkText(entry.getText().split("\n")[0]));
        entryLink.click();
        List<Attachment> attachments = getAttachmentsOfCurrentPostInPage(driver, post);
        post.setAttachments(attachments);
        if (topic.getPoll() == null) {
            Poll poll = getPollOfCurrentTopic(driver);
            result.setPoll(poll);
        }
        VerifyTopic.goTo(driver, result);
        goTo(driver);
    }
    result.setPosts(posts);
    returnToHome(driver);
    return result;
}
Also used : Category(it.vige.rubia.model.Category) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) Attachment(it.vige.rubia.model.Attachment) WebElement(org.openqa.selenium.WebElement) Forum(it.vige.rubia.model.Forum) VerifyForum(it.vige.rubia.selenium.forum.action.VerifyForum) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Poster(it.vige.rubia.model.Poster) Poll(it.vige.rubia.model.Poll) ParseException(java.text.ParseException) VerifyTopic(it.vige.rubia.selenium.forum.action.VerifyTopic) Topic(it.vige.rubia.model.Topic) VerifyPoll.getPollOfCurrentTopic(it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with Message

use of it.vige.rubia.model.Message in project rubia-forums by flashboss.

the class EditPost method execute.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String execute() {
    String navState = null;
    boolean success = false;
    try {
        // setup the business objects to be updated
        Post post = forumsModule.findPostById(postId);
        forumsModule.updateAttachments(attachments, post);
        // TODO: cleanup this forums update process............move this as
        // a private method
        // setup attachment information
        Topic topic = post.getTopic();
        // make sure this topic is not locked
        if (topic.getStatus() == TOPIC_LOCKED) {
            // should not allow posting a reply since the topic is locked
            throw new Exception(getBundleMessage(BUNDLE_NAME, TOPIC_LOCKED_ERR_KEY));
        }
        // setup the message/subject related data
        Message message = createMessage();
        message.setText(this.message);
        message.setSubject(subject);
        // update the message/subject/topicType data on the business objects
        post.setMessage(message);
        if (isFirstPost) {
            topic.setSubject(subject);
            topic.setType(topicType);
        }
        // miscellaneous post related update
        post.setEditCount(post.getEditCount() + 1);
        post.setEditDate(new Date());
        // TODO: cleanup this poll update process............move this as a
        // private method
        // setup poll information
        List<PollOption> localPollOptions = new LinkedList<PollOption>();
        for (String key : options.keySet()) {
            PollOption pollOption = createPollOption(topic.getPoll());
            pollOption.setQuestion(options.get(key));
            pollOption.setVotes(0);
            localPollOptions.add(pollOption);
        }
        // update poll information
        if (topic.getPoll() == null || topic.getPoll().getTitle() == null || topic.getPoll().getTitle().trim().length() == 0) {
            // no existing poll information found in the database
            if (localPollOptions.size() > 0 && question != null && question.trim().length() > 0) {
                // need to add a new poll to this topic
                Poll poll = createPoll();
                poll.setTitle(question);
                poll.setLength(activeDuration);
                poll.setOptions(localPollOptions);
                validatePoll(poll);
                forumsModule.addPollToTopic(topic, poll);
            }
        } else {
            // existing poll information is available in the database
            if (localPollOptions.size() > 0) {
                // this is a diff update..............................
                // setup the poll to be updated in the database
                Poll poll = createPoll();
                poll.setTitle(question);
                poll.setLength(activeDuration);
                poll.setVoted(topic.getPoll().getVoted());
                poll.setCreationDate(topic.getPoll().getCreationDate());
                for (PollOption newPollOption : localPollOptions) {
                    Iterator<PollOption> stored = topic.getPoll().getOptions().iterator();
                    while (stored.hasNext()) {
                        PollOption oldPollOption = (PollOption) stored.next();
                        if (oldPollOption != null && oldPollOption.getQuestion().equals(newPollOption.getQuestion())) {
                            newPollOption.setVotes(oldPollOption.getVotes());
                            break;
                        }
                    }
                }
                poll.setOptions(localPollOptions);
                forumsModule.addPollToTopic(topic, poll);
            } else {
                // remove the poll from the database...poll was removed
                // during this editPost process
                topic.setPoll(null);
            }
        }
        forumsModule.update(topic);
        forumsModule.update(post);
        // set the proper navigation state
        navState = SUCCESS;
        success = true;
    } catch (PollValidationException e) {
        // handle proper validation error with a proper message...not just a
        // generic message..
        // just use generic error page for the proof of concept
        // set the custom exception such that e.toString() results in the
        // proper message
        handleException(e);
    } catch (Exception e) {
        handleException(e);
    } finally {
        // cleanup if necessary
        if (success) {
            cleanup();
        }
    }
    return navState;
}
Also used : PortalUtil.createMessage(it.vige.rubia.PortalUtil.createMessage) JSFUtil.getBundleMessage(it.vige.rubia.ui.JSFUtil.getBundleMessage) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Date(java.util.Date) LinkedList(java.util.LinkedList) PortalUtil.createPoll(it.vige.rubia.PortalUtil.createPoll) Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) PortalUtil.createPollOption(it.vige.rubia.PortalUtil.createPollOption) Topic(it.vige.rubia.model.Topic) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 8 with Message

use of it.vige.rubia.model.Message in project rubia-forums by flashboss.

the class NewTopic method execute.

/**
 * Execute
 *
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String execute() {
    String navState = null;
    boolean success = false;
    try {
        // setup the message
        Message message = createMessage();
        message.setText(this.message);
        message.setSubject(subject);
        // setup the forum and the corresponding poster
        Forum forum = forumsModule.findForumById(forumId);
        Poster poster = getPoster(userModule, forumsModule);
        // setup the poll related information
        Poll poll = createPoll();
        if (question != null && question.trim().length() > 0) {
            poll.setTitle(question);
            poll.setLength(activeDuration);
            List<PollOption> pollOptions = new LinkedList<PollOption>();
            for (String option : options.keySet()) {
                PollOption pollOption = createPollOption(poll);
                pollOption.setQuestion((String) options.get(option));
                pollOption.setVotes(0);
                pollOptions.add(pollOption);
            }
            poll.setOptions(pollOptions);
            validatePoll(poll);
        }
        poster.incrementPostCount();
        // actually create the topic in this forum
        // use this method when poll and attachments are actually integrated
        // poll
        forumsModule.createTopic(// poll
        forum, // poll
        message, // poll
        new Date(), // poll
        poster, // poll
        poll, // attachments
        attachments, topicType);
        // setup the navigation state
        navState = SUCCESS;
        success = true;
    } catch (MessageValidationException e) {
        // handle proper validation error with a proper message...not just a
        // generic message..
        // just use generic error page for the proof of concept
        // set the custom exception such that e.toString() results in the
        // proper message
        handleException(e);
    } catch (PollValidationException e) {
        // handle proper validation error with a proper message...not just a
        // generic message..
        // just use generic error page for the proof of concept
        // set the custom exception such that e.toString() results in the
        // proper message
        handleException(e);
    } catch (Exception e) {
        handleException(e);
    } finally {
        // cleanup if necessary
        if (success) {
            cleanup();
        }
    }
    return navState;
}
Also used : PortalUtil.createMessage(it.vige.rubia.PortalUtil.createMessage) Message(it.vige.rubia.model.Message) LinkedList(java.util.LinkedList) Date(java.util.Date) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) JSFUtil.getPoster(it.vige.rubia.ui.JSFUtil.getPoster) Poster(it.vige.rubia.model.Poster) PortalUtil.createPoll(it.vige.rubia.PortalUtil.createPoll) Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) PortalUtil.createPollOption(it.vige.rubia.PortalUtil.createPollOption) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 9 with Message

use of it.vige.rubia.model.Message 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 10 with Message

use of it.vige.rubia.model.Message in project rubia-forums by flashboss.

the class VerifyAttachment method addParents.

private static void addParents(WebDriver driver, Attachment attachment) {
    Post post = new Post();
    Message message = new Message();
    message.setSubject(driver.findElement(POST_TEMPLATE_LINK.getValue()).getText());
    post.setMessage(message);
    Topic topic = new Topic();
    topic.setSubject(driver.findElement(TOPIC_TEMPLATE_LINK.getValue()).getText());
    post.setTopic(topic);
    Forum forum = new Forum();
    forum.setName(driver.findElement(FORUM_TEMPLATE_LINK.getValue()).getText());
    topic.setForum(forum);
    Category category = new Category();
    category.setTitle(driver.findElement(CATEGORY_TEMPLATE_LINK.getValue()).getText());
    forum.setCategory(category);
    attachment.setPost(post);
}
Also used : Category(it.vige.rubia.model.Category) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) Topic(it.vige.rubia.model.Topic) Forum(it.vige.rubia.model.Forum)

Aggregations

Message (it.vige.rubia.model.Message)16 Post (it.vige.rubia.model.Post)14 Poster (it.vige.rubia.model.Poster)11 Topic (it.vige.rubia.model.Topic)9 Forum (it.vige.rubia.model.Forum)7 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Test (org.junit.Test)6 ViewAllForumsSelectPost (it.vige.rubia.selenium.myforums.action.ViewAllForumsSelectPost)4 WebElement (org.openqa.selenium.WebElement)4 PortalUtil.createMessage (it.vige.rubia.PortalUtil.createMessage)3 SecureActionForum (it.vige.rubia.auth.SecureActionForum)3 Category (it.vige.rubia.model.Category)3 Poll (it.vige.rubia.model.Poll)3 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)3 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)3 VerifyTopic (it.vige.rubia.selenium.forum.action.VerifyTopic)3 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)3 ArrayList (java.util.ArrayList)3 PortalUtil.createPoll (it.vige.rubia.PortalUtil.createPoll)2