Search in sources :

Example 21 with Poster

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

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

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

the class ViewPageTopicSearch method getPoster.

public static Poster getPoster(WebDriver driver, Topic topic) {
    WebElement profileLink = driver.findElement(linkText(topic.getSubject())).findElement(xpath("../../a"));
    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 24 with Poster

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

the class SearchTopicTest method verifyPostProfileFromTopicPage.

@Test
public void verifyPostProfileFromTopicPage() {
    goTo(driver);
    SearchCriteria searchForumCriteria = new SearchCriteria();
    searchForumCriteria.setAuthor("root");
    searchForumCriteria.setCategory(null);
    searchForumCriteria.setDisplayAs(TOPICS.name());
    searchForumCriteria.setForum(null);
    searchForumCriteria.setKeywords("Topic");
    searchForumCriteria.setPageNumber(0);
    searchForumCriteria.setPageSize(0);
    searchForumCriteria.setSearching(null);
    searchForumCriteria.setSortBy(null);
    searchForumCriteria.setSortOrder(null);
    searchForumCriteria.setTimePeriod(null);
    List<Topic> topics = searchTopic(driver, searchForumCriteria);
    Topic topic = topics.get(2);
    Poster poster = getPoster(driver, topic);
    assertTrue(poster != null);
    assertEquals("root", poster.getUserId());
    assertTrue(poster.getPostCount() >= 4);
}
Also used : Poster(it.vige.rubia.model.Poster) ViewPageTopicSearch.getPoster(it.vige.rubia.selenium.search.action.ViewPageTopicSearch.getPoster) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) ViewPageTopicSearch.searchTopic(it.vige.rubia.selenium.search.action.ViewPageTopicSearch.searchTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) ViewPageTopicSearch.getTopic(it.vige.rubia.selenium.search.action.ViewPageTopicSearch.getTopic) SearchCriteria(it.vige.rubia.search.SearchCriteria) Test(org.junit.Test)

Example 25 with Poster

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

the class ForumsModuleImpl method findPosterByUserId.

@Override
public Poster findPosterByUserId(String userId) throws ModuleException {
    if (userId != null) {
        try {
            TypedQuery<Poster> query = em.createNamedQuery("findPosterByUserId", Poster.class);
            query.setParameter("userId", userId);
            Poster user = uniqueElement(query.getResultList());
            return user;
        } catch (Exception e) {
            String message = "Cannot find poster by name " + userId;
            throw new ModuleException(message, e);
        }
    } else {
        throw new IllegalArgumentException("user name cannot be null");
    }
}
Also used : Poster(it.vige.rubia.model.Poster) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

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