Search in sources :

Example 1 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum in project rubia-forums by flashboss.

the class ModeratorAction method moveTopic.

/**
 * UI Action for moveing topic(s) from one forum to other.
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String moveTopic() {
    String forum_to_id = getParameter(p_forum_to_id);
    if (forum_to_id == null || forum_to_id.trim().length() == 0 || forum_to_id.trim().compareToIgnoreCase("-1") == 0) {
        setWarnBundleMessage("ERR_NO_DEST_FORUM");
        return "success";
    }
    Forum forumDest = null;
    try {
        forumDest = forumsModule.findForumById(new Integer(forum_to_id));
    } catch (Exception e) {
        setWarnBundleMessage("ERR_INTERNAL");
        return "success";
    }
    try {
        for (int topicId : checkboxes.keySet()) {
            boolean value = checkboxes.get(topicId);
            if (value) {
                Topic topic = null;
                try {
                    topic = forumsModule.findTopicById(topicId);
                } catch (Exception e) {
                    setWarnBundleMessage("ERR_INTERNAL");
                    return "success";
                }
                topic.setForum(forumDest);
                forumDest.setPostCount(forumDest.getPostCount() + topic.getReplies() + 1);
                forumDest.setTopicCount(forumDest.getTopicCount() + 1);
                forum.setPostCount(forum.getPostCount() - topic.getReplies() - 1);
                forum.setTopicCount(forum.getTopicCount() - 1);
                forumsModule.update(forum);
                forumsModule.update(forumDest);
                forumsModule.update(topic);
                topics.remove(topic);
            }
        }
        setInfoBundleMessage("SUCC_TOPIC_MOVED");
    } catch (Exception e) {
        handleException(e);
    }
    if (!conversation.isTransient())
        conversation.end();
    return "success";
}
Also used : ViewTopic(it.vige.rubia.ui.view.ViewTopic) Topic(it.vige.rubia.model.Topic) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 2 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum in project rubia-forums by flashboss.

the class PollController method vote.

/**
 * accepts a vote and processes it
 *
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String vote() {
    String navState = null;
    try {
        String t = getParameter(p_topicId);
        String vote = getParameter(p_vote);
        if (t != null && t.trim().length() > 0) {
            // setup the data needed for this process
            int topicId, voteIndex;
            try {
                topicId = parseInt(t);
                voteIndex = parseInt(vote);
            } catch (NumberFormatException e) {
                // dont process a vote
                return null;
            }
            Topic topic = forumsModule.findTopicById(topicId);
            Poll poll = topic.getPoll();
            PollOption selectedOption = poll.getOptions().get(voteIndex);
            Poster poster = getPoster(userModule, forumsModule);
            // perform the voting on the selected option
            if (poster != null) {
                poll.getVoted().add(poster.getUserId());
            }
            selectedOption.incVotes();
            forumsModule.update(selectedOption);
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : JSFUtil.getPoster(it.vige.rubia.ui.JSFUtil.getPoster) Poster(it.vige.rubia.model.Poster) Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) Topic(it.vige.rubia.model.Topic) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 3 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum in project rubia-forums by flashboss.

the class SplitTopic method splitAfter.

// ---------- UI Actions supported by this bean ----------------------------
/**
 * This user interface action is spliting topic after post selected by user.
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String splitAfter() {
    // Checking whether topic has only one post, so it can't be splitted
    if (posts.size() == 1) {
        setWarnBundleMessage("ERR_SPLIT_ONE_POST_TOPIC");
        return "";
    }
    // Removing all not slected posts
    Iterator<Integer> selectIt = checkboxes.keySet().iterator();
    while (selectIt.hasNext()) {
        Boolean postFlag = checkboxes.get(selectIt.next());
        if (!postFlag.booleanValue()) {
            selectIt.remove();
        }
    }
    // Checking if user selected anything.
    if (checkboxes.size() == 0) {
        setWarnBundleMessage("ERR_NO_POST_SELECTED");
        return "";
    }
    // User can't select more than one post for this action.
    if (checkboxes.size() != 1) {
        setWarnBundleMessage("Too_many_error");
        return "";
    }
    // check if user selected first post
    try {
        posts = forumsModule.findPostsByTopicId(topic);
        if (posts.get(0).getId().equals(checkboxes.keySet().iterator().next())) {
            setWarnBundleMessage("ERR_SPLIT_ALL");
            return "";
        }
    } catch (ModuleException e1) {
        setWarnBundleMessage("ERR_SPLIT_ALL");
        return "";
    } catch (Exception e1) {
        setWarnBundleMessage("ERR_SPLIT_ALL");
        return "";
    }
    // Trying to get destination forum for new topic.
    String toForumId = getParameter(p_forum_to_id);
    if (toForumId == null || toForumId.trim().compareToIgnoreCase("-1") == 0 || toForumId.trim().length() == 0) {
        setWarnBundleMessage("ERR_DEST_FORUM");
        return "";
    }
    // Checking if user gave subject for new topic.
    if (newTopicTitle == null || newTopicTitle.trim().compareToIgnoreCase("-1") == 0 || newTopicTitle.trim().length() == 0) {
        setWarnBundleMessage("ERR_NO_SUBJECT_GIVEN");
        return "";
    }
    try {
        Forum destForum = forumsModule.findForumById(new Integer(toForumId));
        // Creating new topic in destination forum.
        Topic newTopic = forumsModule.createTopic(destForum, getUser(userModule).getId().toString(), newTopicTitle, topic.getType());
        // Getting post id after which the topic must be splitted.
        Integer selectedPostId = (Integer) checkboxes.keySet().iterator().next();
        // Searching for the split pointing post in topic.
        Iterator<Post> it = posts.iterator();
        Post tempPost = null;
        while (it.hasNext()) {
            tempPost = it.next();
            // searching for post to split after
            if (tempPost.getId().equals(selectedPostId)) {
                break;
            }
        }
        List<Post> postsToRemove = new ArrayList<Post>();
        // Adding splitting post and all which are after him to new topic.
        if (tempPost != null) {
            tempPost.setTopic(newTopic);
            forumsModule.update(tempPost);
            postsToRemove.add(tempPost);
        }
        while (it.hasNext()) {
            Post post = it.next();
            post.setTopic(newTopic);
            forumsModule.update(post);
            postsToRemove.add(post);
        }
        newTopic = forumsModule.findTopicById(newTopic.getId());
        List<Post> postsNewTopic = forumsModule.findPostsByTopicId(newTopic);
        newTopic.setReplies(postsNewTopic.size() - 1);
        newTopic.setLastPostDate(postsNewTopic.get(postsNewTopic.size() - 1).getCreateDate());
        Forum fromForum = topic.getForum();
        topic.setReplies(topic.getReplies() - newTopic.getReplies() - 1);
        fromForum.setPostCount(fromForum.getPostCount() - newTopic.getReplies() - 1);
        posts.removeAll(postsToRemove);
        topic.setLastPostDate(posts.get(posts.size() - 1).getCreateDate());
        destForum.addTopicSize();
        destForum.setPostCount(destForum.getPostCount() + newTopic.getReplies() + 1);
        forumsModule.update(newTopic);
        forumsModule.update(topic);
        forumsModule.update(fromForum);
        forumsModule.update(destForum);
    } catch (Exception e) {
        log.error(e);
        setWarnBundleMessage("ERR_INTERNAL");
        return "";
    }
    // Setting message that everything went smooth.
    setInfoBundleMessage("SUCC_TOPIC_SPLITTED");
    return "";
}
Also used : Post(it.vige.rubia.model.Post) ArrayList(java.util.ArrayList) ModuleException(it.vige.rubia.ModuleException) Topic(it.vige.rubia.model.Topic) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 4 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum in project rubia-forums by flashboss.

the class ViewMyForumsBase method execute.

/**
 * @throws Exception
 *             an error exception is launched
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public void execute() throws Exception {
    Collection<Topic> topics = getWatchedTopics();
    // minipaging
    if (topics != null) {
        for (Topic courTopic : topics) {
            if (courTopic.getReplies() > 0) {
                PageNavigator topicNav = new PageNavigator(courTopic.getReplies() + 1, // this
                getUserPreferences().getPostsPerTopic(), // current page of the navigator
                0) {

                    /**
                     */
                    private static final long serialVersionUID = 1L;

                    protected Collection<Integer> initializePage() {
                        return null;
                    }
                };
                topicNavigator.put(courTopic.getId(), topicNav);
            }
        }
    }
}
Also used : PageNavigator(it.vige.rubia.ui.PageNavigator) Topic(it.vige.rubia.model.Topic) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 5 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum in project rubia-forums by flashboss.

the class ViewMyForumsMain method getWatchedTopics.

/**
 * @return the watched topics
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public Collection<Topic> getWatchedTopics() {
    if (watchedTopics == null) {
        try {
            Date lastLoginDate = getUserLastLoginDate(userModule, userProfileModule);
            if (lastLoginDate == null) {
                return watchedTopics;
            }
            // get the forumInstanceId where this forum should be added
            int forumInstanceId = userPreferences.getForumInstanceId();
            watchedTopics = forumsModule.findTopicWatchedByUser(getUser(userModule), lastLoginDate, forumInstanceId);
        } catch (Exception e) {
            handleException(e);
        }
    }
    return watchedTopics;
}
Also used : Date(java.util.Date) JSFUtil.getUserLastLoginDate(it.vige.rubia.ui.JSFUtil.getUserLastLoginDate) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Aggregations

SecureActionForum (it.vige.rubia.auth.SecureActionForum)21 Interceptors (javax.interceptor.Interceptors)21 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)17 Topic (it.vige.rubia.model.Topic)13 ModuleException (it.vige.rubia.ModuleException)9 Post (it.vige.rubia.model.Post)6 Forum (it.vige.rubia.model.Forum)5 PollOption (it.vige.rubia.model.PollOption)4 ViewTopic (it.vige.rubia.ui.view.ViewTopic)4 Poll (it.vige.rubia.model.Poll)3 Poster (it.vige.rubia.model.Poster)3 Date (java.util.Date)3 PortalUtil.createMessage (it.vige.rubia.PortalUtil.createMessage)2 PortalUtil.createPoll (it.vige.rubia.PortalUtil.createPoll)2 PortalUtil.createPollOption (it.vige.rubia.PortalUtil.createPollOption)2 Message (it.vige.rubia.model.Message)2 JSFUtil.getPoster (it.vige.rubia.ui.JSFUtil.getPoster)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 PortalUtil.getPoster (it.vige.rubia.PortalUtil.getPoster)1