Author: unibrew Date: 2006-06-30 21:37:10 -0400 (Fri, 30 Jun 2006) New Revision: 4897 Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml Log: [JBFORUMS-54] Working on TopicSplit actions. Debugging. Commenting. Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ModeratorAction.java 2006-07-01 01:37:10 UTC (rev 4897) @@ -44,6 +44,9 @@ import org.jboss.portlet.forums.ui.view.PageNavigator; /** + * ModeratorAction class is a managed bean used for getting, keeping, transforming + * all data and invoking moderator actions for Moderator's Control Panel. + * * @author <a href="mailto:rys...@jb...">Ryszard Kozmik</a> */ public class ModeratorAction extends BaseController @@ -60,7 +63,6 @@ private Collection page = new ArrayList(); private Map topicNavigator = new HashMap(); private Map checkboxes; - private ResourceBundle bundle; @@ -133,6 +135,11 @@ //ui actions supported by this bean---------------------------------------------------------------------------------------------------- + /** + * UI Action for deleting topic(s) from the forum. + * + * @return + */ public String deleteTopic () { Iterator it = checkboxes.keySet().iterator(); @@ -168,11 +175,16 @@ return "success"; } + /** + * UI Action for moveing topic(s) from one forum to other. + * + * @return + */ public String moveTopic () { String message=""; String forum_to_id = ForumUtil.getParameter(Constants.p_forum_to_id); - if (forum_to_id==null || forum_to_id.trim().compareToIgnoreCase("-1")==0) + if (forum_to_id==null || forum_to_id.trim().length()==0 || forum_to_id.trim().compareToIgnoreCase("-1")==0) { message = bundle.getString("ERR_NO_DEST_FORUM"); FacesContext.getCurrentInstance().addMessage("message", @@ -222,6 +234,11 @@ return "success"; } + /** + * UI Action for locking selected topic(s). + * + * @return + */ public String lockTopic () { if (isAnyCheckboxSelected()) @@ -269,6 +286,11 @@ } + /** + * UI Action for unlocking selected topic(s). + * + * @return + */ public String unlockTopic () { if (isAnyCheckboxSelected()) @@ -314,6 +336,12 @@ } } + /** + * Action checking if user selected at least one topic and forwards him to + * delete confirmation view. + * + * @return + */ public String deleteConfirm() { if (isAnyCheckboxSelected()) @@ -327,7 +355,13 @@ return ""; } } - + + /** + * Action checking if user selected at least one topic and forwards him to + * move topic view. + * + * @return + */ public String moveConfirm() { if (isAnyCheckboxSelected()) @@ -342,6 +376,12 @@ } } + /** + * Method checks if user selected at least one topic from checkboxes or + * there is topic id sent in request. + * + * @return + */ private boolean isAnyCheckboxSelected() { // Looking for selected topicId's in checkboxes Map @@ -367,6 +407,8 @@ return false; } + // ---------- Initialization ----------------------------------------------- + /** * */ @@ -387,12 +429,14 @@ private void execute() throws Exception { - // Getting ResourceBundle with current Locale - FacesContext ctx = FacesContext.getCurrentInstance(); - UIViewRoot uiRoot = ctx.getViewRoot(); - Locale locale = uiRoot.getLocale(); - ClassLoader ldr = Thread.currentThread().getContextClassLoader(); - this.bundle = ResourceBundle.getBundle("ResourceJSF", locale, ldr); + if (this.bundle == null) { + // Getting ResourceBundle with current Locale + FacesContext ctx = FacesContext.getCurrentInstance(); + UIViewRoot uiRoot = ctx.getViewRoot(); + Locale locale = uiRoot.getLocale(); + ClassLoader ldr = Thread.currentThread().getContextClassLoader(); + this.bundle = ResourceBundle.getBundle("ResourceJSF", locale, ldr); + } int currentPage = 0; //parse the input parameters Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java 2006-07-01 01:37:10 UTC (rev 4897) @@ -22,25 +22,45 @@ package org.jboss.portlet.forums.ui.action; -import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; import java.util.Map; +import java.util.ResourceBundle; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIViewRoot; +import javax.faces.context.FacesContext; + +import org.jboss.portlet.forums.model.Forum; +import org.jboss.portlet.forums.model.Post; import org.jboss.portlet.forums.model.Topic; import org.jboss.portlet.forums.ui.BaseController; import org.jboss.portlet.forums.ui.Constants; import org.jboss.portlet.forums.ui.ForumUtil; import org.jboss.portlet.forums.ui.JSFUtil; -import org.jboss.portlet.forums.ui.view.PageNavigator; /** + * SplitTopic is a bean which keeps data and has actions needed to achieve + * spltting topic into two separate topics. + * * @author <a href="mailto:rys...@jb...">Ryszard Kozmik</a> */ public class SplitTopic extends BaseController { + // Title for newly created topic private String newTopicTitle; + + // Map containing Integer:Boolean pairs with TopicId:IsSelected states private Map checkboxes; + + // Topic to split private Topic topic; + private ResourceBundle bundle; + // ---------- Getters And Setters for bean's attributes -------------------- + public void setNewTopicTitle(String newTopicTitle) { this.newTopicTitle = newTopicTitle; } @@ -63,10 +83,230 @@ return topic; } + // ---------- UI Actions supported by this bean ---------------------------- /** - * + * This user interface action is spliting topic after post selected by user. + * + * @return */ + public String splitAfter () { + + // Temporary variable for bunlde message + String message = ""; + + // Removing all not slected posts + Iterator selectIt = checkboxes.keySet().iterator(); + while (selectIt.hasNext()) { + Boolean postFlag = (Boolean)checkboxes.get(selectIt.next()); + if (!postFlag.booleanValue()) { + selectIt.remove(); + } + } + + // Checking whether topic has only one post, so it can't be splitted + if (topic.getPosts().size()==1) { + message = bundle.getString("ERR_SPLIT_ONE_POST_TOPIC"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Checking if user selected anything. + if (checkboxes.size()==0) { + message = bundle.getString("ERR_NO_POST_SELECTED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // User can't select more than one post for this action. + if (checkboxes.size()!=1) { + message = bundle.getString("Too_many_error"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + //check if user selected first post + if (topic.getFirstPost().getId().equals((Integer)(checkboxes.keySet().iterator().next()))) { + message = bundle.getString("ERR_SPLIT_ALL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Trying to get destination forum for new topic. + String toForumId = ForumUtil.getParameter(Constants.p_forum_to_id); + if (toForumId == null || + toForumId.trim().compareToIgnoreCase("-1")==0 || + toForumId.trim().length()==0) { + message = bundle.getString("ERR_DEST_FORUM"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Checking if user gave subject for new topic. + if (newTopicTitle == null || + newTopicTitle.trim().compareToIgnoreCase("-1")==0 || + newTopicTitle.trim().length()==0) { + message = bundle.getString("ERR_NO_SUBJECT_GIVEN"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + try { + Forum destForum = getForumsModule().findForumById(new Integer(toForumId)); + + // Creating new topic in destination forum. + Topic newTopic = getForumsModule().createTopic(destForum, + topic.getPoster().getUserId(), + 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 it = topic.getPosts().iterator(); + Post tempPost = null; + while( it.hasNext() ) + { + tempPost = (Post)it.next(); + // searching for post to split after + if (tempPost.getId().equals(selectedPostId)) + { + break; + } + } + + // Adding splitting post and all which are after him to new topic. + if (tempPost != null) + { + newTopic.addPost(tempPost); + } + while (it.hasNext()) + { + newTopic.addPost((Post)it.next()); + } + newTopic.setLastPostDate(newTopic.getLastPost().getCreateDate()); + } catch (Exception e) { + e.printStackTrace(); + message = bundle.getString("ERR_INTERNAL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Setting message that everything went smooth. + message = bundle.getString("SUCC_TOPIC_SPLITTED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate")); + return ""; + } + + /** + * This user interface action is spliting topic bh=y moving all selected + * by user posts into newly created topic. + * + * @return + */ + public String splitPosts () { + + // Temporary variable for bunlde message + String message = ""; + + // Removing all not slected posts + Iterator selectIt = checkboxes.keySet().iterator(); + while (selectIt.hasNext()) { + Boolean postFlag = (Boolean)checkboxes.get(selectIt.next()); + if (!postFlag.booleanValue()) { + selectIt.remove(); + } + } + + // Checking whether topic has only one post, so it can't be splitted + if (topic.getPosts().size()==1) { + message = bundle.getString("ERR_SPLIT_ONE_POST_TOPIC"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Checking if user selected anything. + if (checkboxes.size()==0) { + message = bundle.getString("ERR_NO_POST_SELECTED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Checking if user didn't select all posts. + if (checkboxes.size()==topic.getPosts().size()) { + message = bundle.getString("ERR_SPLIT_ALL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Trying to get destination forum for new topic. + String toForumId = ForumUtil.getParameter(Constants.p_forum_to_id); + if (toForumId == null || + toForumId.trim().compareToIgnoreCase("-1")==0 || + toForumId.trim().length()==0) { + message = bundle.getString("ERR_DEST_FORUM"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Checking if user gave subject for new topic. + if (newTopicTitle == null || + newTopicTitle.trim().compareToIgnoreCase("-1")==0 || + newTopicTitle.trim().length()==0) { + message = bundle.getString("ERR_NO_SUBJECT_GIVEN"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + try { + + Forum destForum = getForumsModule().findForumById(new Integer(toForumId)); + + // Creating new topic in selected destination forum. + Topic newTopic = getForumsModule().createTopic(destForum, + topic.getPoster().getUserId(), + newTopicTitle, topic.getType()); + + // Moving all selected posts to new topic. + selectIt = checkboxes.keySet().iterator(); + Post movedPost=null; + while (selectIt.hasNext()) { + movedPost = getForumsModule().findPostById((Integer)selectIt.next()); + newTopic.addPost(movedPost); + } + newTopic.setLastPostDate(newTopic.getLastPost().getCreateDate()); + } catch (Exception e) { + e.printStackTrace(); + message = bundle.getString("ERR_INTERNAL"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate")); + return ""; + } + + // Setting message that everything went smooth. + message = bundle.getString("SUCC_TOPIC_SPLITTED"); + FacesContext.getCurrentInstance().addMessage("message", + new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate")); + return ""; + } + + // ---------- Initializing ------------------------------------------------- + + /** + * Called at every page refresh, manages bean's initialization. + */ public boolean isInitialized() { boolean initialized = false; @@ -82,8 +322,22 @@ return initialized; } + /** + * Bean's attributes initialization. + * + * @throws Exception + */ private void execute() throws Exception { + if ( this.bundle == null ) { + // Getting ResourceBundle with current Locale + FacesContext ctx = FacesContext.getCurrentInstance(); + UIViewRoot uiRoot = ctx.getViewRoot(); + Locale locale = uiRoot.getLocale(); + ClassLoader ldr = Thread.currentThread().getContextClassLoader(); + this.bundle = ResourceBundle.getBundle("ResourceJSF", locale, ldr); + } + //parse input data int topicId = -1; String t = ForumUtil.getParameter(Constants.p_topicId); @@ -96,6 +350,9 @@ if (topicId != -1) { this.topic = BaseController.getForumsModule().findTopicById(new Integer(topicId)); } + if (checkboxes==null || checkboxes.size()!=topic.getPosts().size()) { + checkboxes = new HashMap(); + } } } Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/classes/ResourceJSF.properties 2006-07-01 01:37:10 UTC (rev 4897) @@ -1125,10 +1125,10 @@ ERR_DEST_FORUM=You have to select destination forum! ERR_PERMISSION_VIOLATION=You don't have proper perrmisions - STOP HACKING!!! ERR_NO_POST_SELECTED=You have not selected any posts to split. +ERR_NO_SUBJECT_GIVEN=You have to give subject for new topic. - # # Timezones ... for display on each page # Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-07-01 01:37:10 UTC (rev 4897) @@ -303,6 +303,7 @@ <managed-bean-class>org.jboss.portlet.forums.ui.action.SplitTopic</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> + <navigation-rule> <from-view-id>/views/moderator/modcp_body.xhtml</from-view-id> <navigation-case> Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_body.xhtml 2006-07-01 01:37:10 UTC (rev 4897) @@ -28,6 +28,7 @@ xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:forums="http://www.jboss.com/products/jbossportal/forums" class="bb"> + <ui:composition template="/views/common/common.xhtml"> <ui:define name="mainContent"> <c:if test="#{moderator.initialized && moderator.forum!=null && moderator.forum.id!=-1}"> @@ -177,6 +178,7 @@ <table width="100%" cellspacing="2" border="0" align="center" cellpadding="2"> <tr> + <!-- the current page number information --> <c:if test="#{moderator.pageNavigator.totalPages gt 1}"> <td align="left" colspan="3"> @@ -191,6 +193,7 @@ </span> </td> </c:if> + <!-- page navigation --> <c:if test="#{moderator.pageNavigator.totalPages gt 1}"> <td align="right" valign="middle" nowrap="nowrap"> Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml 2006-06-30 19:41:00 UTC (rev 4896) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml 2006-07-01 01:37:10 UTC (rev 4897) @@ -106,16 +106,18 @@ <td width="50%" align="center"> <h:commandButton action="${splitTopic.splitPosts}" type="submit" - class="liteoption" - name="split_type_all" - value="${resource.L_SPLIT_POSTS}"/> + class="liteoption" + value="${resource.L_SPLIT_POSTS}"> + <f:param name="t" value="#{splitTopic.topic.id}"/> + </h:commandButton> </td> <td width="50%" align="center"> <h:commandButton action="${splitTopic.splitAfter}" type="submit" class="liteoption" - name="split_type_beyond" - value="${resource.L_SPLIT_AFTER}"/> + value="${resource.L_SPLIT_AFTER}"> + <f:param name="t" value="#{splitTopic.topic.id}"/> + </h:commandButton> </td> </tr> </table> @@ -162,7 +164,7 @@ </table> </td> <td width="5%" align="center" class='${(status.index%2==0)?"row1":"row2"}'> - <h:selectBooleanCheckbox value="#{splitTopic.checkboxes[postrow.id]}"/> + <h:selectBooleanCheckbox value="${splitTopic.checkboxes[postrow.id]}"/> </td> </tr> <tr> @@ -176,27 +178,35 @@ <table width="60%" cellspacing="0" cellpadding="0" border="0" align="center"> <tr> <td width="50%" align="center"> - <input class="liteoption" type="submit" name="split_type_all" - value="${resource.L_SPLIT_POSTS}"/> + <h:commandButton action="${splitTopic.splitPosts}" + type="submit" + class="liteoption" + value="${resource.L_SPLIT_POSTS}"> + <f:param name="t" value="#{splitTopic.topic.id}"/> + </h:commandButton> </td> <td width="50%" align="center"> - <input class="liteoption" type="submit" name="split_type_beyond" - value="${resource.L_SPLIT_AFTER}"/> + <h:commandButton action="${splitTopic.splitAfter}" + type="submit" + class="liteoption" + value="${resource.L_SPLIT_AFTER}"> + <f:param name="t" value="#{splitTopic.topic.id}"/> + </h:commandButton> </td> </tr> </table> </td> </tr> </table> - <table width="100%" cellspacing="2" border="0" align="center" cellpadding="2"> - <tr> - <!-- integrate jumpbox here --> - <td align="right" valign="top" nowrap="nowrap"> - <ui:include src="/views/jumpbox.xhtml"/> - </td> - </tr> - </table> </h:form> +<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2"> + <tr> + <!-- integrate jumpbox here --> + <td align="right" valign="top" nowrap="nowrap"> + <ui:include src="/views/jumpbox.xhtml"/> + </td> + </tr> +</table> </forums:isAllowed> </c:if> |