[jboss-svn-commits] JBL Code SVN: r8805 - in labs/jbossforums/branches/forums22/forums/src: main/org/jboss/portlet/forums/impl and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 10 16:17:03 EST 2007
Author: unibrew
Date: 2007-01-10 16:16:55 -0500 (Wed, 10 Jan 2007)
New Revision: 8805
Modified:
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/TopicWatchController.java
labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
Log:
[JBFORUMS-77] [JBFORUMS-78] Adding topic watch and unwatch.
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2007-01-10 19:59:21 UTC (rev 8804)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2007-01-10 21:16:55 UTC (rev 8805)
@@ -563,7 +563,17 @@
*/
ForumWatch findForumWatchById(Integer forumWatchID) throws ModuleException;
+
/**
+ *
+ * @param user
+ * @param topicId
+ * @return TopicWatch
+ * @throws ModuleException
+ */
+ TopicWatch findTopicWatchByUserAndTopic(User user,int topicId) throws ModuleException;
+
+ /**
* @param poster
* @param topic
*/
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2007-01-10 19:59:21 UTC (rev 8804)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2007-01-10 21:16:55 UTC (rev 8805)
@@ -1593,6 +1593,31 @@
throw new ModuleException(message, e);
}
}
+
+ public TopicWatch findTopicWatchByUserAndTopic(User user,int topicId) throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
+ Query query = session.createQuery(" from TopicWatchImpl as tw " +
+ " where tw.poster.userId = :userId " +
+ " and tw.topic.id= :topicId ");
+ query.setString("userId", user.getId().toString());
+ query.setInteger("topicId", topicId );
+ Object obj = query.uniqueResult();
+ if (obj==null) {
+ return null;
+ } else {
+ return (TopicWatch)obj;
+ }
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find forum watch";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
public void createWatch(Poster poster, Topic topic)
throws ModuleException
Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/TopicWatchController.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/TopicWatchController.java 2007-01-10 19:59:21 UTC (rev 8804)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/TopicWatchController.java 2007-01-10 21:16:55 UTC (rev 8805)
@@ -21,15 +21,11 @@
*/
package org.jboss.portlet.forums.ui.action;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Collection;
-
-import org.jboss.portlet.forums.ui.*;
-
-import org.jboss.portlet.forums.model.Category;
-import org.jboss.portlet.forums.model.Forum;
import org.jboss.portlet.forums.model.Topic;
+import org.jboss.portlet.forums.model.TopicWatch;
+import org.jboss.portlet.forums.ui.Constants;
+import org.jboss.portlet.forums.ui.JSFUtil;
+import org.jboss.portlet.forums.ui.PortalUtil;
/**
* This controller is used for activating/deactivating topic watches
@@ -37,15 +33,25 @@
* Created on Jul 7, 2006
*
* @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
*/
public class TopicWatchController extends ActionController
{
+
+ private int topicId ;
+
/**
*
*
*/
public TopicWatchController()
- {
+ {
+ String t = JSFUtil.getRequestParameter(Constants.p_topicId);
+ if (t!=null && t.trim().length()>0) {
+ topicId = Integer.parseInt(t);
+ } else {
+ topicId = -1;
+ }
}
/**
@@ -56,11 +62,29 @@
{
String navState = null;
- String t = JSFUtil.getRequestParameter(Constants.p_topicId);
- int topicId = Integer.parseInt(t);
+ try
+ {
+
+ //make sure a watch for this topic is not already issued for this user
+ boolean isDuplicate = this.isWatched();
+ if(isDuplicate)
+ {
+ return navState;
+ }
+
+ //get the topic that must be activated for watching
+ Topic topic = getForumsModule().findTopicById(new Integer(topicId));
+
+
+ //activate the watch for the selected topic
+ getForumsModule().createWatch(PortalUtil.getPoster(),topic);
+
+ }
+ catch(Exception e)
+ {
+ JSFUtil.handleException(e);
+ }
- //System.out.println("Successfully activated watch for---"+topicId);
-
return navState;
}
@@ -72,11 +96,32 @@
{
String navState = null;
- String t = JSFUtil.getRequestParameter(Constants.p_topicId);
- int topicId = Integer.parseInt(t);
+ try {
+
+ TopicWatch watch = getForumsModule().findTopicWatchByUserAndTopic(PortalUtil.getUser(),topicId);
- //System.out.println("Successfully deActivated watch for---"+topicId);
+ getForumsModule().removeWatch(watch);
+
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
return navState;
}
+
+ public boolean isWatched()
+ {
+ TopicWatch topicWatch = null;
+
+ try {
+
+ topicWatch = getForumsModule().findTopicWatchByUserAndTopic(PortalUtil.getUser(),this.topicId);
+
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+
+ return topicWatch!=null;
+ }
+
}
Modified: labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2007-01-10 19:59:21 UTC (rev 8804)
+++ labs/jbossforums/branches/forums22/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2007-01-10 21:16:55 UTC (rev 8805)
@@ -197,6 +197,25 @@
</h:outputLink>
</td>
+ <c:if test="#{shared.anonymous==false}">
+ <td align="right" valign="middle" class="nav" width="100%">
+ <c:choose>
+ <!-- TODO: PLACE FOR UNSUBSCRIBE BUTTON -->
+ <c:when test="#{topicWatch.watched}">
+ <h:commandLink action="#{topicWatch.deActivateWatch}" value="TopicUnWatch" >
+ <f:param name="t" value="#{topic.topic.id}"/>
+ </h:commandLink>
+ </c:when>
+ <c:otherwise>
+ <!-- TODO: PLACE FOR SUBSCRIBE BUTTON -->
+ <h:commandLink action="#{topicWatch.activateWatch}" value="TopicWatch" >
+ <f:param name="t" value="#{topic.topic.id}"/>
+ </h:commandLink>
+ </c:otherwise>
+ </c:choose>
+ </td>
+ </c:if>
+
</tr>
</table>
More information about the jboss-svn-commits
mailing list