Search in sources :

Example 11 with Poster

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

the class ReplyTopic method execute.

/**
 * Execute
 *
 * @return the navigation state of the application
 */
public String execute() {
    String navState = null;
    boolean success = false;
    try {
        Message message = createMessage();
        message.setText(this.message);
        message.setSubject(subject);
        // setup the forum and the corresponding poster
        Forum forum = forumsModule.findForumById(forumId);
        topic = forumsModule.findTopicById(topicId);
        Poster poster = getPoster(forumsModule, userModule);
        // 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));
        }
        // actually post a reply to this topic in the forum
        poster.incrementPostCount();
        // attachments
        forumsModule.createPost(// attachments
        topic, // attachments
        forum, // attachments
        message, // attachments
        new Date(), // attachments
        poster, // attachments
        attachments);
        currentTopicPage.setPage(viewTopic.getLastPageNumber());
        // 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) JSFUtil.getBundleMessage(it.vige.rubia.ui.JSFUtil.getBundleMessage) Message(it.vige.rubia.model.Message) PortalUtil.getPoster(it.vige.rubia.PortalUtil.getPoster) Poster(it.vige.rubia.model.Poster) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Date(java.util.Date) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 12 with Poster

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

the class VerifyTopic method getPoster.

public static Poster getPoster(WebDriver driver, Forum forum) {
    WebElement profileLink = driver.findElement(linkText(forum.getName())).findElement(xpath("../../../td[5]/a[2]"));
    String userId = profileLink.getText();
    profileLink.click();
    Poster poster = verifyProfile(driver, userId);
    return poster;
}
Also used : Poster(it.vige.rubia.model.Poster) WebElement(org.openqa.selenium.WebElement)

Example 13 with Poster

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

the class VerifyTopic method getPosterLastPost.

public static Poster getPosterLastPost(WebDriver driver, Topic topic) {
    WebElement profileLink = driver.findElements(className(PROFILE_LINK)).get(0).findElement(xpath("../tr/td/a[contains(text(),'" + topic.getSubject() + "')]")).findElement(xpath("../a[2]"));
    String userId = profileLink.getText();
    profileLink.click();
    Poster poster = verifyProfile(driver, userId);
    return poster;
}
Also used : Poster(it.vige.rubia.model.Poster) WebElement(org.openqa.selenium.WebElement)

Example 14 with Poster

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

the class ViewRSSLink method getPage.

public static Forum getPage(WebDriver driver, Forum forum) {
    VerifyForum.goTo(driver, forum);
    goTo(driver);
    Forum result = new Forum();
    result.setName(driver.findElement(id(FEED_TITLE_TEXT)).getText().split(": ")[1]);
    result.setCategory(new Category(driver.findElement(id(FEED_SUBTITLE_TEXT)).getText().split(" in category ")[1]));
    Map<String, Topic> topics = new HashMap<String, Topic>();
    List<WebElement> entries = driver.findElements(className(ENTRY_LINK));
    DateFormat dateFormat = new SimpleDateFormat("d MMM yyyy, HH:mm");
    for (WebElement entry : entries) {
        String[] entryText = entry.getText().split(BY);
        String lastUpdated = entry.findElement(className(LAST_UPDATED)).getText();
        String topicTitle = entryText[0].replace(RE, "");
        Topic topic = topics.get(topicTitle);
        if (topic == null) {
            topic = new Topic(topicTitle);
            topics.put(topicTitle, topic);
        }
        Post post = new Post(entry.findElement(className(FEED_ENTRY_CONTENT)).getText());
        post.setPoster(new Poster(entryText[1].split("\n")[0]));
        try {
            post.setCreateDate(dateFormat.parse(lastUpdated));
        } catch (ParseException e) {
        }
        post.getMessage().setSubject(entryText[0]);
        topic.getPosts().add(post);
    }
    result.setTopics(new ArrayList<Topic>(topics.values()));
    returnToHome(driver);
    return result;
}
Also used : Category(it.vige.rubia.model.Category) HashMap(java.util.HashMap) Post(it.vige.rubia.model.Post) 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) ParseException(java.text.ParseException) VerifyTopic(it.vige.rubia.selenium.forum.action.VerifyTopic) Topic(it.vige.rubia.model.Topic) SimpleDateFormat(java.text.SimpleDateFormat)

Example 15 with Poster

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

the class JSFUtil method getPoster.

/**
 * @param userModule
 *            the user module of the application
 * @param forumsModule
 *            the forums module of the application
 *
 * @return the current poster
 * @throws Exception
 *             the error exception
 */
public static Poster getPoster(UserModule userModule, ForumsModule forumsModule) throws Exception {
    Poster poster = null;
    if (!isAnonymous()) {
        User user = getUser(userModule);
        Object userId = user.getId();
        poster = forumsModule.findPosterByUserId(userId.toString());
        if (poster == null) {
            poster = new Poster(userId.toString());
        }
    } else {
        poster = getGuestPoster(userModule, forumsModule);
    }
    return poster;
}
Also used : PortalUtil.getUser(it.vige.rubia.PortalUtil.getUser) User(it.vige.rubia.auth.User) PortalUtil.getGuestPoster(it.vige.rubia.PortalUtil.getGuestPoster) Poster(it.vige.rubia.model.Poster)

Aggregations

Poster (it.vige.rubia.model.Poster)46 Post (it.vige.rubia.model.Post)20 WebElement (org.openqa.selenium.WebElement)18 Topic (it.vige.rubia.model.Topic)17 Forum (it.vige.rubia.model.Forum)14 Test (org.junit.Test)13 Message (it.vige.rubia.model.Message)11 ParseException (java.text.ParseException)10 Category (it.vige.rubia.model.Category)7 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)7 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)7 Date (java.util.Date)7 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)6 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)6 NoResultException (javax.persistence.NoResultException)6 NonUniqueResultException (javax.persistence.NonUniqueResultException)6 VerifyPost.getLastPostOfCurrentForum (it.vige.rubia.selenium.forum.action.VerifyPost.getLastPostOfCurrentForum)5 VerifyTopic (it.vige.rubia.selenium.forum.action.VerifyTopic)5 VerifyTopic.getPoster (it.vige.rubia.selenium.forum.action.VerifyTopic.getPoster)5 DateFormat (java.text.DateFormat)5