Search in sources :

Example 1 with Interceptors

use of javax.interceptor.Interceptors in project UVMS-ActivityModule-APP by UnionVMS.

the class FishingActivityResource method listFishingTripsByQuery.

@POST
@Path("/listTrips")
@Consumes(value = { MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_JSON)
@Interceptors(ActivityExceptionInterceptor.class)
@IUserRoleInterceptor(requiredUserRole = { ActivityFeaturesEnum.LIST_ACTIVITY_REPORTS })
public Response listFishingTripsByQuery(@Context HttpServletRequest request, @HeaderParam("scopeName") String scopeName, @HeaderParam("roleName") String roleName, FishingActivityQuery fishingActivityQuery) throws ServiceException {
    log.info("Query Received to search Fishing Activity Reports. " + fishingActivityQuery);
    if (fishingActivityQuery == null) {
        return createErrorResponse("Query to find list is null.");
    }
    String username = request.getRemoteUser();
    List<Dataset> datasets = usmService.getDatasetsPerCategory(USMSpatial.USM_DATASET_CATEGORY, username, USMSpatial.APPLICATION_NAME, roleName, scopeName);
    log.info("Successful retrieved");
    FishingTripResponse fishingTripIdsForFilter = fishingTripService.filterFishingTrips(fishingActivityQuery);
    return createSuccessResponse(fishingTripIdsForFilter);
}
Also used : FishingTripResponse(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishingTripResponse) Dataset(eu.europa.ec.fisheries.wsdl.user.types.Dataset) Path(javax.ws.rs.Path) Interceptors(javax.interceptor.Interceptors) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) IUserRoleInterceptor(eu.europa.ec.fisheries.uvms.activity.rest.IUserRoleInterceptor)

Example 2 with Interceptors

use of javax.interceptor.Interceptors 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 3 with Interceptors

use of javax.interceptor.Interceptors 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 4 with Interceptors

use of javax.interceptor.Interceptors 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 5 with Interceptors

use of javax.interceptor.Interceptors 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)

Aggregations

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