Search in sources :

Example 16 with Interceptors

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

the class DeletePost method confirmDelete.

// actions---------------------------------------------------------------------------------------------------------------------------------
/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String confirmDelete() {
    String navState = null;
    try {
        // setup the business objects/data of interest
        Post post = forumsModule.findPostById(postId);
        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));
        }
        boolean isFirstPost = false;
        boolean isLastPost = false;
        List<Post> posts = forumsModule.findPostsByTopicId(topic);
        if (posts.get(0).getId() == post.getId().intValue()) {
            isFirstPost = true;
        }
        if (posts.get(posts.size() - 1).getId().intValue() == post.getId().intValue()) {
            isLastPost = true;
        }
        // now perform the actual delete operation.........................
        if (isLastPost && isFirstPost) {
            // cascade delete will take care of removing
            // the post
            // the watches
            // the poll
            // the links
            forumsModule.removeTopic(post.getTopic().getId());
            // set the proper navigation state
            navState = TOPIC_DELETED;
        } else {
            forumsModule.removePost(post.getId(), isLastPost);
            // set the proper navigation state
            navState = SUCCESS;
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : Post(it.vige.rubia.model.Post) 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 17 with Interceptors

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

the class ForumWatchController method activateWatch.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String activateWatch() {
    String navState = null;
    try {
        int forumId = selectedForum;
        try {
            String wt = getRequestParameter(p_notified_watch_type);
            if (wt != null && wt.trim().length() > 0) {
                watchMode = parseInt(wt);
            } else {
                watchMode = -1;
            }
        } catch (NumberFormatException e) {
            handleException(e);
            watchMode = -1;
        }
        if (forumId == -1 || watchMode == -1) {
            return null;
        }
        // make sure a watch for this forum is not already issued for this
        // user
        boolean isDuplicate = isDuplicateWatch(forumId);
        if (isDuplicate) {
            return "success";
        }
        // get the forum that must be activated for watching
        Forum forum = forumsModule.findForumById(forumId);
        // activate the watch for the selected forum
        forumsModule.createWatch(getPoster(userModule, forumsModule), forum, watchMode);
        navState = "success";
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 18 with Interceptors

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

the class ForumWatchController method deActivateWatch.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String deActivateWatch() {
    String navState = null;
    try {
        int watchId = -1;
        String w = getRequestParameter(p_watchId);
        if (w != null && w.trim().length() > 0) {
            watchId = parseInt(w);
        }
        if (watchId == -1) {
            String f = getRequestParameter(p_forumId);
            if (f != null && f.trim().length() > 0) {
                int forumId = parseInt(f);
                ForumWatch forumWatch = forumsModule.findForumWatchByUserAndForum(getUser(userModule), forumId);
                watchId = forumWatch != null ? forumWatch.getId().intValue() : -1;
            }
        }
        if (watchId != -1) {
            forumsModule.removeWatch(forumsModule.findForumWatchById(watchId));
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : ForumWatch(it.vige.rubia.model.ForumWatch) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 19 with Interceptors

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

the class ModeratorAction method deleteTopic.

// ui actions supported by this
// bean----------------------------------------------------------------------------------------------------
/**
 * UI Action for deleting topic(s) from the forum.
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String deleteTopic() {
    try {
        for (int topicId : checkboxes.keySet()) {
            boolean value = checkboxes.get(topicId);
            try {
                if (value) {
                    Topic topic = forumsModule.findTopicById(topicId);
                    forumsModule.removeTopic(topicId);
                    topics.remove(topic);
                }
            } catch (Exception e) {
                setWarnBundleMessage("ERR_CANNOT_REMOVE_TOPIC");
                return "success";
            }
        }
        setInfoBundleMessage("SUCC_TOPIC_REMOVED");
    } 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) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 20 with Interceptors

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

the class ModeratorAction method lockTopic.

/**
 * UI Action for locking selected topic(s).
 *
 * @return the name of the operation
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String lockTopic() {
    if (isAnyCheckboxSelected()) {
        try {
            for (int topicId : checkboxes.keySet()) {
                boolean value = checkboxes.get(topicId);
                try {
                    if (value) {
                        Topic topic = forumsModule.findTopicById(topicId);
                        updateStatus(topic, TOPIC_LOCKED);
                    }
                } catch (Exception e) {
                    setWarnBundleMessage("ERR_INTERNAL");
                    return "";
                }
            }
            setInfoBundleMessage("SUCC_TOPIC_LOCKED");
        } 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)

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