Search in sources :

Example 21 with Interceptors

use of javax.interceptor.Interceptors in project rubia-forums by flashboss.

the class ModeratorAction method unlockTopic.

/**
 * UI Action for unlocking selected topic(s).
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String unlockTopic() {
    if (isAnyCheckboxSelected()) {
        try {
            for (int topicId : checkboxes.keySet()) {
                boolean value = checkboxes.get(topicId);
                try {
                    if (value) {
                        Topic topic = forumsModule.findTopicById(topicId);
                        updateStatus(topic, TOPIC_UNLOCKED);
                    }
                } catch (Exception e) {
                    setWarnBundleMessage("ERR_INTERNAL");
                    return "";
                }
            }
            setInfoBundleMessage("SUCC_TOPIC_UNLOCKED");
        } catch (Exception e) {
            handleException(e);
        }
        return "";
    } else {
        setWarnBundleMessage("None_selected");
        return "";
    }
}
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) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 22 with Interceptors

use of javax.interceptor.Interceptors in project rubia-forums by flashboss.

the class PostAction method setupPoll.

/**
 * sets the poll information of a post for the ui from the business object
 *
 * @param poll
 *            the poll to configure
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
protected void setupPoll(Poll poll) {
    if (poll != null) {
        question = poll.getTitle();
        activeDuration = poll.getLength();
        List<PollOption> pollOptions = poll.getOptions();
        if (pollOptions != null && pollOptions.size() > 0) {
            options = new TreeMap<String, String>();
            int counter = 1;
            for (PollOption cour : pollOptions) {
                options.put(Integer.toString(counter), cour.getQuestion());
                counter++;
            }
        }
    }
}
Also used : PollOption(it.vige.rubia.model.PollOption) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 23 with Interceptors

use of javax.interceptor.Interceptors in project rubia-forums by flashboss.

the class ReplyTopic method startQuote.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String startQuote() {
    String navState = start();
    try {
        String p = getParameter(p_postId);
        if (p != null && p.trim().length() > 0) {
            postId = parseInt(p);
        }
        // setup the quote information
        Post post = forumsModule.findPostById(postId);
        Poster poster = getPoster(forumsModule, userModule);
        String userName = userModule.findUserById(poster.getUserId()).getUserName();
        message = userName + "<" + QUOTE + ">" + post.getMessage().getText() + "</" + QUOTE + "></br>";
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : Post(it.vige.rubia.model.Post) PortalUtil.getPoster(it.vige.rubia.PortalUtil.getPoster) Poster(it.vige.rubia.model.Poster) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 24 with Interceptors

use of javax.interceptor.Interceptors in project rubia-forums by flashboss.

the class SplitTopic method splitPosts.

/**
 * This user interface action is spliting topic bh=y moving all selected by
 * user posts into newly created topic.
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String splitPosts() {
    // 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 "";
    }
    // Checking if user didn't select all posts.
    if (checkboxes.size() == posts.size()) {
        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 selected destination forum.
        Topic newTopic = forumsModule.createTopic(destForum, getUser(userModule).getId().toString(), newTopicTitle, topic.getType());
        // Moving all selected posts to new topic.
        selectIt = checkboxes.keySet().iterator();
        Post movedPost = null;
        List<Post> postsToRemove = new ArrayList<Post>();
        while (selectIt.hasNext()) {
            movedPost = forumsModule.findPostById(selectIt.next());
            movedPost.setTopic(newTopic);
            forumsModule.update(movedPost);
            postsToRemove.add(movedPost);
        }
        Forum fromForum = topic.getForum();
        topic.setReplies(topic.getReplies() - checkboxes.size());
        fromForum.setPostCount(fromForum.getPostCount() - checkboxes.size());
        posts.removeAll(postsToRemove);
        topic.setLastPostDate(posts.get(posts.size() - 1).getCreateDate());
        newTopic.setReplies(checkboxes.size() - 1);
        List<Post> postsNewTopic = forumsModule.findPostsByTopicId(newTopic);
        newTopic.setLastPostDate(postsNewTopic.get(postsNewTopic.size() - 1).getCreateDate());
        destForum.addTopicSize();
        destForum.setPostCount(destForum.getPostCount() + newTopic.getReplies() + 1);
        forumsModule.update(topic);
        forumsModule.update(newTopic);
        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) 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 25 with Interceptors

use of javax.interceptor.Interceptors in project rubia-forums by flashboss.

the class ViewMyForumsBase method getTopicsLastPosts.

/**
 * @return a map of the last posts and respective topics
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public Map<Object, Object> getTopicsLastPosts() {
    if (topicsLastPosts == null) {
        try {
            Collection<Topic> watched = getWatchedTopics();
            if (watched != null) {
                Set<Topic> temporaryContainer = new HashSet<Topic>(watched.size());
                Iterator<Topic> it = watched.iterator();
                while (it.hasNext()) {
                    Topic topic = it.next();
                    temporaryContainer.add(topic);
                }
                topicsLastPosts = getMyForumsModule().findLastPostsOfTopics(temporaryContainer);
            }
        } catch (Exception e) {
            handleException(e);
        }
    }
    return topicsLastPosts;
}
Also used : Topic(it.vige.rubia.model.Topic) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) HashSet(java.util.HashSet) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Aggregations

Interceptors (javax.interceptor.Interceptors)27 SecureActionForum (it.vige.rubia.auth.SecureActionForum)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 IUserRoleInterceptor (eu.europa.ec.fisheries.uvms.activity.rest.IUserRoleInterceptor)4 PollOption (it.vige.rubia.model.PollOption)4 ViewTopic (it.vige.rubia.ui.view.ViewTopic)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Poll (it.vige.rubia.model.Poll)3 Poster (it.vige.rubia.model.Poster)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Dataset (eu.europa.ec.fisheries.wsdl.user.types.Dataset)2 PortalUtil.createMessage (it.vige.rubia.PortalUtil.createMessage)2