Search in sources :

Example 6 with SecureActionForum

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

the class AdminController method addCategory.

// ----actions---------------------------------------------------------------------------------------------------------------------------
/**
 * adds a category
 *
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String addCategory() {
    String navState = null;
    boolean success = false;
    try {
        // get the forumInstanceId where this forum should be added
        int forumInstanceId = userPreferences.getForumInstanceId();
        // add this new category to the forum instance
        ForumInstance forumInstance = forumsModule.findForumInstanceById(forumInstanceId);
        forumsModule.createCategory(categoryName, forumInstance);
        String start = getBundleMessage("ResourceJSF", "Category_created_0");
        String end = getBundleMessage("ResourceJSF", "Category_created_1");
        setMessage(FEEDBACK, start + " \"" + categoryName + "\" " + end);
        success = true;
    } catch (Exception e) {
        handleException(e);
    } finally {
        if (success) {
            // cleanup the state
            cleanup();
        }
    }
    return navState;
}
Also used : ForumInstance(it.vige.rubia.model.ForumInstance) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 7 with SecureActionForum

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

the class AdminController method editCategory.

/**
 * edit category
 *
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String editCategory() {
    String navState = null;
    boolean success = false;
    try {
        int categoryId = -1;
        String cour = ForumUtil.getParameter(p_categoryId);
        if (cour != null && cour.trim().length() > 0) {
            categoryId = Integer.parseInt(cour);
        }
        // grab the category from the module and set the title
        Category category = forumsModule.findCategoryById(categoryId);
        category.setTitle(categoryName);
        forumsModule.update(category);
        String start = getBundleMessage("ResourceJSF", "Category_updated_0");
        String end = getBundleMessage("ResourceJSF", "Category_updated_1");
        setMessage(FEEDBACK, start + " \"" + categoryName + "\" " + end);
        navState = "";
        success = true;
    } catch (Exception e) {
        handleException(e);
    } finally {
        if (success) {
            // cleanup the state
            cleanup();
        }
    }
    return navState;
}
Also used : Category(it.vige.rubia.model.Category) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 8 with SecureActionForum

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

the class EditPost method start.

// action processing
// methods-----------------------------------------------------------------------------------------------------
/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String start() {
    String navState = null;
    try {
        int postId = -1;
        String p = getParameter(p_postId);
        if (p != null && p.trim().length() > 0) {
            postId = parseInt(p);
        }
        // grab the post information
        if (postId != -1) {
            // re-initialize this controller to edit the specified post
            cleanup();
            // get the post from the module
            Post post = forumsModule.findPostById(postId);
            Topic topic = post.getTopic();
            // set the selected post's topic id
            topicId = topic.getId().intValue();
            this.postId = postId;
            // set the subject of the post
            subject = post.getMessage().getSubject();
            // set the message of the post
            message = post.getMessage().getText();
            // set the topicType
            topicType = topic.getType();
            // setup poll related information
            setupPoll(topic.getPoll());
            attachments = forumsModule.findAttachments(post);
            // setup the attachment related information
            List<Post> posts = forumsModule.findPostsByTopicId(topic);
            isFirstPost = false;
            if (posts.get(0).getId().intValue() == post.getId().intValue()) {
                isFirstPost = true;
            }
        }
        navState = START_EDIT_POST;
    } 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) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 9 with SecureActionForum

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

the class EditPost method execute.

/**
 * @return the navigation state of the application
 */
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String execute() {
    String navState = null;
    boolean success = false;
    try {
        // setup the business objects to be updated
        Post post = forumsModule.findPostById(postId);
        forumsModule.updateAttachments(attachments, post);
        // TODO: cleanup this forums update process............move this as
        // a private method
        // setup attachment information
        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));
        }
        // setup the message/subject related data
        Message message = createMessage();
        message.setText(this.message);
        message.setSubject(subject);
        // update the message/subject/topicType data on the business objects
        post.setMessage(message);
        if (isFirstPost) {
            topic.setSubject(subject);
            topic.setType(topicType);
        }
        // miscellaneous post related update
        post.setEditCount(post.getEditCount() + 1);
        post.setEditDate(new Date());
        // TODO: cleanup this poll update process............move this as a
        // private method
        // setup poll information
        List<PollOption> localPollOptions = new LinkedList<PollOption>();
        for (String key : options.keySet()) {
            PollOption pollOption = createPollOption(topic.getPoll());
            pollOption.setQuestion(options.get(key));
            pollOption.setVotes(0);
            localPollOptions.add(pollOption);
        }
        // update poll information
        if (topic.getPoll() == null || topic.getPoll().getTitle() == null || topic.getPoll().getTitle().trim().length() == 0) {
            // no existing poll information found in the database
            if (localPollOptions.size() > 0 && question != null && question.trim().length() > 0) {
                // need to add a new poll to this topic
                Poll poll = createPoll();
                poll.setTitle(question);
                poll.setLength(activeDuration);
                poll.setOptions(localPollOptions);
                validatePoll(poll);
                forumsModule.addPollToTopic(topic, poll);
            }
        } else {
            // existing poll information is available in the database
            if (localPollOptions.size() > 0) {
                // this is a diff update..............................
                // setup the poll to be updated in the database
                Poll poll = createPoll();
                poll.setTitle(question);
                poll.setLength(activeDuration);
                poll.setVoted(topic.getPoll().getVoted());
                poll.setCreationDate(topic.getPoll().getCreationDate());
                for (PollOption newPollOption : localPollOptions) {
                    Iterator<PollOption> stored = topic.getPoll().getOptions().iterator();
                    while (stored.hasNext()) {
                        PollOption oldPollOption = (PollOption) stored.next();
                        if (oldPollOption != null && oldPollOption.getQuestion().equals(newPollOption.getQuestion())) {
                            newPollOption.setVotes(oldPollOption.getVotes());
                            break;
                        }
                    }
                }
                poll.setOptions(localPollOptions);
                forumsModule.addPollToTopic(topic, poll);
            } else {
                // remove the poll from the database...poll was removed
                // during this editPost process
                topic.setPoll(null);
            }
        }
        forumsModule.update(topic);
        forumsModule.update(post);
        // set the proper navigation state
        navState = SUCCESS;
        success = true;
    } 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) JSFUtil.getBundleMessage(it.vige.rubia.ui.JSFUtil.getBundleMessage) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Date(java.util.Date) LinkedList(java.util.LinkedList) 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) Topic(it.vige.rubia.model.Topic) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 10 with SecureActionForum

use of it.vige.rubia.auth.SecureActionForum 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)

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