Search in sources :

Example 56 with Forum

use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.

the class AdminController method moveForumUp.

/**
 * @return the navigation state of the application
 */
public String moveForumUp() {
    String navState = null;
    try {
        // get the categoryId where this forum should be added
        int forumId = -1;
        String cour = ForumUtil.getParameter(p_forumId);
        if (cour != null && cour.trim().length() > 0) {
            forumId = Integer.parseInt(cour);
        }
        Forum forum = forumsModule.findForumById(forumId);
        forum.setOrder(forum.getOrder() + up);
        forumsModule.update(forum);
        Iterator<Forum> forums = forumsModule.findForumsByCategory(forum.getCategory()).iterator();
        for (int index = 10; forums.hasNext(); index += 10) {
            forum = forums.next();
            forum.setOrder(index);
            forumsModule.update(forum);
        }
    } catch (Exception e) {
        handleException(e);
    }
    return navState;
}
Also used : JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) ModuleException(it.vige.rubia.ModuleException) Forum(it.vige.rubia.model.Forum) ViewForum(it.vige.rubia.ui.view.ViewForum) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 57 with Forum

use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.

the class AdminController method deleteForum.

/**
 * @return the navigation state of the application
 */
public String deleteForum() {
    String navState = null;
    boolean success = false;
    try {
        int forumId = -1;
        String cour = ForumUtil.getParameter(p_forumId);
        if (cour != null && cour.trim().length() > 0) {
            forumId = Integer.parseInt(cour);
        }
        Forum source = null;
        // forum
        if (selectedForum != -1) {
            source = forumsModule.findForumByIdFetchTopics(forumId);
            Forum target = forumsModule.findForumByIdFetchTopics(selectedForum);
            target.getTopics().addAll(source.getTopics());
            target.setPostCount(target.getPostCount() + source.getPostCount());
            target.setTopicCount(target.getTopicCount() + source.getTopicCount());
            forumsModule.update(target);
            for (Topic tp : target.getTopics()) {
                tp.setForum(target);
                forumsModule.update(tp);
            }
            // clear the source out before delete
            source.setTopics(new ArrayList<Topic>());
            forumsModule.update(source);
        } else {
            source = forumsModule.findForumById(forumId);
        }
        // means delete all topic/posts on this forum
        forumsModule.removeForum(source.getId());
        String start = getBundleMessage("ResourceJSF", "Forum_deleted_0");
        String end = getBundleMessage("ResourceJSF", "Forum_deleted_1");
        setMessage(FEEDBACK, start + " \"" + forumName + "\" " + end);
        navState = DELETE_FORUM;
        success = true;
    } catch (Exception e) {
        handleException(e);
    } finally {
        if (success) {
            // cleanup the state
            cleanup();
        }
    }
    return navState;
}
Also used : 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) ViewForum(it.vige.rubia.ui.view.ViewForum) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 58 with Forum

use of it.vige.rubia.model.Forum 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)

Example 59 with Forum

use of it.vige.rubia.model.Forum 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 60 with Forum

use of it.vige.rubia.model.Forum in project rubia-forums by flashboss.

the class ViewMyForumsEditAllForums method execute.

/**
 */
@PostConstruct
public void execute() {
    Collection<Forum> forums = getWatchedForums();
    try {
        // get the forumInstanceId where this forum should be added
        int forumInstanceId = userPreferences.getForumInstanceId();
        forumWatches = forumsModule.findForumWatches(getUser(userModule), forumInstanceId);
    } catch (Exception e) {
        handleException(e);
        setForumWatches(new HashMap<Object, Object>(0));
    }
    Date userLastLogin = getUserLastLoginDate(userModule, userProfileModule);
    for (Forum currentForum : forums) {
        // setup folderLook based on whats specified in the theme
        String folderImage = themeHelper.getResourceForumURL();
        // bundle key
        String folderAlt = "No_new_posts";
        if (forumsLastPosts != null && forumsLastPosts.containsKey(currentForum.getId())) {
            Post lastPost = (Post) forumsLastPosts.get(currentForum.getId());
            Date lastPostDate = lastPost.getCreateDate();
            if (lastPostDate != null && userLastLogin != null && lastPostDate.compareTo(userLastLogin) > 0) {
                // bundle key
                folderAlt = "New_posts";
                folderImage = themeHelper.getResourceForumNewURL();
            }
        }
        if (currentForum.getStatus() == FORUM_LOCKED) {
            folderImage = themeHelper.getResourceForumLockedURL();
            // bundle key
            folderAlt = "Forum_locked";
        }
        getForumImages().put(currentForum.getId(), folderImage);
        getForumImageDescriptions().put(currentForum.getId(), folderAlt);
    }
    try {
        String t = getRequestParameter(p_forumId);
        if (t != null && t.trim().length() > 0) {
            forumId = parseInt(t);
        } else {
            forumId = -1;
        }
        if (forumId != -1) {
            watch = forumsModule.findForumWatchByUserAndForum(getUser(userModule), forumId);
        }
    } catch (Exception e) {
        handleException(e);
        forumId = -1;
        watch = null;
    }
}
Also used : HashMap(java.util.HashMap) Post(it.vige.rubia.model.Post) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Date(java.util.Date) JSFUtil.getUserLastLoginDate(it.vige.rubia.ui.JSFUtil.getUserLastLoginDate) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Forum (it.vige.rubia.model.Forum)100 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)65 Topic (it.vige.rubia.model.Topic)63 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)55 Post (it.vige.rubia.model.Post)52 Category (it.vige.rubia.model.Category)50 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)49 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)40 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)40 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)34 Test (org.junit.Test)33 Poll (it.vige.rubia.model.Poll)23 Attachment (it.vige.rubia.model.Attachment)21 PollOption (it.vige.rubia.model.PollOption)21 SecureActionForum (it.vige.rubia.auth.SecureActionForum)16 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)15 Poster (it.vige.rubia.model.Poster)14 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)14 BeforeClass (org.junit.BeforeClass)14 AfterClass (org.junit.AfterClass)13