[jboss-svn-commits] JBL Code SVN: r12889 - in labs/jbossforums/branches/forums101P26/forums/src: main/org/jboss/portlet/forums/feeds and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 27 07:06:19 EDT 2007
Author: szimano
Date: 2007-06-27 07:06:19 -0400 (Wed, 27 Jun 2007)
New Revision: 12889
Modified:
labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
Log:
perm links, feed links etc.
Modified: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2007-06-27 11:06:19 UTC (rev 12889)
@@ -28,621 +28,688 @@
* @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
* @version $Revision: 3217 $
*/
-public interface ForumsModule
-{
+public interface ForumsModule {
- public HibernateProvider getHibernate();
- /**
- *
- */
- int getFloodInterval();
+ public HibernateProvider getHibernate();
- /**
- *
- */
- void setFloodInterval(int floodInterval);
+ /**
+ *
+ */
+ int getFloodInterval();
- /**
- *
- */
- String getFromAddress();
+ /**
+ *
+ */
+ void setFloodInterval(int floodInterval);
- /**
- *
- */
- void setFromAddress(String fromAddress);
+ /**
+ *
+ */
+ String getFromAddress();
- /**
- * Returns all the announcements of the forum
- *
- * @param forum Forum in which we want to search for the announcements
- * @return List of topics
- * @throws ModuleException Throws an exception if unable to find the announcements.
- */
- List findAnnouncements(Forum forum)
- throws ModuleException;
+ /**
+ *
+ */
+ void setFromAddress(String fromAddress);
- /**
- * Returns some topics of a forum that are not of a certain type
- *
- * @return List of topics
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopics()
- throws ModuleException;
+ /**
+ * Returns all the announcements of the forum
+ *
+ * @param forum
+ * Forum in which we want to search for the announcements
+ * @return List of topics
+ * @throws ModuleException
+ * Throws an exception if unable to find the announcements.
+ */
+ List findAnnouncements(Forum forum) throws ModuleException;
+ /**
+ * Returns some topics of a forum that are not of a certain type
+ *
+ * @return List of topics
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopics() throws ModuleException;
- /**
- * Returns some topics of a forum that are not of a certain type
- * The topics are ordered by creation date from oldest to newest
- *
- * @param forum Forum in which we want to search for topics
- * @param type Type to avoid
- * @param start Index for fetching result
- * @param perPage Number of result to return
- * @return List of perPage topics ordered by creation date.
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopicsAsc(Forum forum,
- int type,
- int start,
- int perPage)
- throws ModuleException;
+ /**
+ * Returns some topics of a forum that are not of a certain type The topics
+ * are ordered by creation date from oldest to newest
+ *
+ * @param forum
+ * Forum in which we want to search for topics
+ * @param type
+ * Type to avoid
+ * @param start
+ * Index for fetching result
+ * @param perPage
+ * Number of result to return
+ * @return List of perPage topics ordered by creation date.
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopicsAsc(Forum forum, int type, int start, int perPage)
+ throws ModuleException;
- /**
- * Returns topics that are ordered by creation date from newest to oldest.
- *
- * @param forum Forum in which we want to search for topics
- * @param type Type to avoid
- * @param start Index for fetching result
- * @param perPage Number of result to return
- * @return List of perPage topics ordered by opposite creation date.
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopicsDesc(Forum forum,
- int type,
- int start,
- int perPage)
- throws ModuleException;
+ /**
+ * Returns topics that are ordered by creation date from newest to oldest.
+ *
+ * @param forum
+ * Forum in which we want to search for topics
+ * @param type
+ * Type to avoid
+ * @param start
+ * Index for fetching result
+ * @param perPage
+ * Number of result to return
+ * @return List of perPage topics ordered by opposite creation date.
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopicsDesc(Forum forum, int type, int start, int perPage)
+ throws ModuleException;
- /**
- * Returns topics that are ordered by creation date from oldest to newest.
- *
- * @param forum Forum in which we want to search for topics
- * @param start Index for fetching result
- * @param perPage Number of result to return
- * @return List of perPage topics ordered by creation date.
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopicsAsc(Forum forum,
- int start,
- int perPage)
- throws ModuleException;
+ /**
+ * Returns topics that are ordered by creation date from oldest to newest.
+ *
+ * @param forum
+ * Forum in which we want to search for topics
+ * @param start
+ * Index for fetching result
+ * @param perPage
+ * Number of result to return
+ * @return List of perPage topics ordered by creation date.
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopicsAsc(Forum forum, int start, int perPage)
+ throws ModuleException;
- /**
- * Returns some topics of a forum that are not of a certain type
- * The topics are ordered by creation date from newest to oldest
- *
- * @param forum Forum in which we want to search for topics
- * @param start Index for fetching result
- * @param perPage Number of result to return
- * @return List of perPage topics ordered by opposite creation date.
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopicsDesc(Forum forum,
- int start,
- int perPage)
- throws ModuleException;
+ /**
+ * Returns some topics of a forum that are not of a certain type The topics
+ * are ordered by creation date from newest to oldest
+ *
+ * @param forum
+ * Forum in which we want to search for topics
+ * @param start
+ * Index for fetching result
+ * @param perPage
+ * Number of result to return
+ * @return List of perPage topics ordered by opposite creation date.
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopicsDesc(Forum forum, int start, int perPage)
+ throws ModuleException;
- /**
- * *
- *
- * @param forum Forum in which we want to search for topics
- * @return List of perPage topics ordered by creation date.
- * @throws ModuleException Throws an excpetion if unable to find the topics.
- */
- List findTopics(Forum forum)
- throws ModuleException;
+ /**
+ * *
+ *
+ * @param forum
+ * Forum in which we want to search for topics
+ * @return List of perPage topics ordered by creation date.
+ * @throws ModuleException
+ * Throws an excpetion if unable to find the topics.
+ */
+ List findTopics(Forum forum) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param forum DOCUMENT_ME
- * @param type DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param perPage DOCUMENT_ME
- * @param date DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findTopicsBefore(Forum forum,
- int type,
- int start,
- int perPage,
- Date date)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param forum
+ * DOCUMENT_ME
+ * @param type
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param perPage
+ * DOCUMENT_ME
+ * @param date
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findTopicsBefore(Forum forum, int type, int start, int perPage,
+ Date date) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param replies DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findTopicsHot(int replies, int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param replies
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findTopicsHot(int replies, int limit) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findTopicsByLatestPosts(int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findTopicsByLatestPosts(int limit) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param after DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findTopicsHottest(Date after, int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param after
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findTopicsHottest(Date after, int limit) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param after DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findTopicsMostViewed(Date after, int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param after
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findTopicsMostViewed(Date after, int limit) throws ModuleException;
+ /**
+ * Find a forum by specifying its ID
+ *
+ * @param id
+ * ID of the forum to retrieve
+ * @return Forum with specified ID
+ * @throws ModuleException
+ * Throws an exception if the forum cannot be found
+ */
+ Forum findForumById(Integer id) throws ModuleException;
- /**
- * Find a forum by specifying its ID
- *
- * @param id ID of the forum to retrieve
- * @return Forum with specified ID
- * @throws ModuleException Throws an exception if the forum cannot be found
- */
- Forum findForumById(Integer id)
- throws ModuleException;
-
- /**
- * Find a forum by specifying its ID and fetch Topics of this Forum.
- *
- * @param id ID of the forum to retrieve
- * @return Forum with specified ID
- * @throws ModuleException Throws an exception if the forum cannot be found
- */
- Forum findForumByIdFetchTopics(Integer id)
- throws ModuleException;
+ /**
+ * Find a forum by specifying its ID and fetch Topics of this Forum.
+ *
+ * @param id
+ * ID of the forum to retrieve
+ * @return Forum with specified ID
+ * @throws ModuleException
+ * Throws an exception if the forum cannot be found
+ */
+ Forum findForumByIdFetchTopics(Integer id) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param category DOCUMENT_ME
- * @param name DOCUMENT_ME
- * @param description DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Forum createForum(Category category,
- String name,
- String description)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param category
+ * DOCUMENT_ME
+ * @param name
+ * DOCUMENT_ME
+ * @param description
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Forum createForum(Category category, String name, String description)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- public List findPosts() throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ public List findPosts() throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param id DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Post findPostById(Integer id)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param id
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Post findPostById(Integer id) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param userID DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Poster findPosterByUserId(String userID)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param userID
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Poster findPosterByUserId(String userID) throws ModuleException;
- /**
- * Get all the categories of forums.
- *
- * @return All the categories
- * @throws ModuleException
- */
- List findCategories()
- throws ModuleException;
+ /**
+ * Get all the categories of forums.
+ *
+ * @return All the categories
+ * @throws ModuleException
+ */
+ List findCategories() throws ModuleException;
- /**
- * Get all the categories of forums and fetch forums.
- *
- * @return All the categories
- * @throws ModuleException
- */
- List findCategoriesFetchForums()
- throws ModuleException;
+ /**
+ * Get all the categories of forums and fetch forums.
+ *
+ * @return All the categories
+ * @throws ModuleException
+ */
+ List findCategoriesFetchForums() throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findForums()
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findForums() throws ModuleException;
- /**
- * Get all the forums of a category
- *
- * @param categoryID Category of forums
- * @return Forums of one category
- */
- List findForumsByCategoryId(Integer categoryID)
- throws ModuleException;
+ /**
+ * Get all the forums of a category
+ *
+ * @param categoryID
+ * Category of forums
+ * @return Forums of one category
+ */
+ List findForumsByCategoryId(Integer categoryID) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param forum DOCUMENT_ME
- * @param message DOCUMENT_ME
- * @param creationDate DOCUMENT_ME
- * @param poster DOCUMENT_ME
- * @return The new post created
- * @throws ModuleException DOCUMENT_ME
- */
- Post createTopic(Forum forum,
- Message message,
- Date creationDate,
- Poster poster,
- Poll poll,
- List attachments,
- int type)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param forum
+ * DOCUMENT_ME
+ * @param message
+ * DOCUMENT_ME
+ * @param creationDate
+ * DOCUMENT_ME
+ * @param poster
+ * DOCUMENT_ME
+ * @return The new post created
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Post createTopic(Forum forum, Message message, Date creationDate,
+ Poster poster, Poll poll, List attachments, int type)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param forum DOCUMENT_ME
- * @param userID DOCUMENT_ME
- * @param subject DOCUMENT_ME
- * @param type DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Topic createTopic(Forum forum,
- String userID,
- String subject,
- int type)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param forum
+ * DOCUMENT_ME
+ * @param userID
+ * DOCUMENT_ME
+ * @param subject
+ * DOCUMENT_ME
+ * @param type
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Topic createTopic(Forum forum, String userID, String subject, int type)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topic DOCUMENT_ME
- * @param forum DOCUMENT_ME
- * @param message DOCUMENT_ME
- * @param creationTime DOCUMENT_ME
- * @param poster DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Post createPost(Topic topic,
- Forum forum,
- Message message,
- Date creationTime,
- Poster poster,
- List attachments)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic
+ * DOCUMENT_ME
+ * @param forum
+ * DOCUMENT_ME
+ * @param message
+ * DOCUMENT_ME
+ * @param creationTime
+ * DOCUMENT_ME
+ * @param poster
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Post createPost(Topic topic, Forum forum, Message message,
+ Date creationTime, Poster poster, List attachments)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topic DOCUMENT_ME
- * @param poll DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- public Poll addPollToTopic(Topic topic,
- Poll poll)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic
+ * DOCUMENT_ME
+ * @param poll
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ public Poll addPollToTopic(Topic topic, Poll poll) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Category createCategory(String name)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Category createCategory(String name) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param category DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- void removeCategory(Category category)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param category
+ * DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void removeCategory(Category category) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param forum DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- void removeForum(Forum forum)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param forum
+ * DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void removeForum(Forum forum) throws ModuleException;
- /**
- * Delete a post
- *
- * @param post Post to delete
- * @throws ModuleException DOCUMENT_ME
- */
- void removePost(Post post)
- throws ModuleException;
+ /**
+ * Delete a post
+ *
+ * @param post
+ * Post to delete
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void removePost(Post post) throws ModuleException;
- /**
- * Delete a post
- *
- * @param topic Post to delete
- * @throws ModuleException DOCUMENT_ME
- */
- void removePollInTopic(Topic topic)
- throws ModuleException;
+ /**
+ * Delete a post
+ *
+ * @param topic
+ * Post to delete
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void removePollInTopic(Topic topic) throws ModuleException;
- /**
- * Delete a topic
- *
- * @param topic Topic to delete
- * @throws ModuleException DOCUMENT_ME
- */
- void removeTopic(Topic topic)
- throws ModuleException;
+ /**
+ * Delete a topic
+ *
+ * @param topic
+ * Topic to delete
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void removeTopic(Topic topic) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param categoryID DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Category findCategoryById(Integer categoryID)
- throws ModuleException;
-
- /**
- * DOCUMENT_ME
- *
- * @param categoryID DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- Category findCategoryByIdFetchForums(Integer categoryID)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param categoryID
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Category findCategoryById(Integer categoryID) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param source DOCUMENT_ME
- * @param target DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- void addAllForums(Category source,
- Category target)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param categoryID
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ Category findCategoryByIdFetchForums(Integer categoryID)
+ throws ModuleException;
- /**
- * @param topicID
- * @return DOCUMENT_ME
- */
- Topic findTopicById(Integer topicID)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param source
+ * DOCUMENT_ME
+ * @param target
+ * DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ void addAllForums(Category source, Category target) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostsByTopicId(Integer topicID)
- throws ModuleException;
+ /**
+ * @param topicID
+ * @return DOCUMENT_ME
+ */
+ Topic findTopicById(Integer topicID) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostsByIdsAscFetchAttachmentsAndPosters( Collection postIds )
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostsByTopicId(Integer topicID) throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostsByIdsDescFetchAttachmentsAndPosters( Collection postIds )
- throws ModuleException;
-
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostIdsAsc(Integer topicID,
- int start,
- int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostsByIdsAscFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostIdsDesc(Integer topicID,
- int start,
- int limit)
- throws ModuleException;
-
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostsByTopicIdAsc(Integer topicID,
- int start,
- int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostIdsAsc(Integer topicID, int start, int limit)
+ throws ModuleException;
- /**
- * DOCUMENT_ME
- *
- * @param topicID DOCUMENT_ME
- * @param start DOCUMENT_ME
- * @param limit DOCUMENT_ME
- * @return DOCUMENT_ME
- * @throws ModuleException DOCUMENT_ME
- */
- List findPostsByTopicIdDesc(Integer topicID,
- int start,
- int limit)
- throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostIdsDesc(Integer topicID, int start, int limit)
+ throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostsByTopicIdAsc(Integer topicID, int start, int limit)
+ throws ModuleException;
- Date findLastPostDateForUser(User user) throws ModuleException;
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicID
+ * DOCUMENT_ME
+ * @param start
+ * DOCUMENT_ME
+ * @param limit
+ * DOCUMENT_ME
+ * @return DOCUMENT_ME
+ * @throws ModuleException
+ * DOCUMENT_ME
+ */
+ List findPostsByTopicIdDesc(Integer topicID, int start, int limit)
+ throws ModuleException;
- Post findLastPost(Forum forum) throws ModuleException;
+ Date findLastPostDateForUser(User user) throws ModuleException;
- Post findFirstPost(Topic topic) throws ModuleException;
+ Post findLastPost(Forum forum) throws ModuleException;
- Post findLastPost(Topic topic) throws ModuleException;
-
- Map findLastPostsOfTopics(Collection topics) throws ModuleException;
-
- Map findLastPostsOfForums() throws ModuleException;
+ Post findFirstPost(Topic topic) throws ModuleException;
- List findForumWatchByUser(User user) throws ModuleException;
+ Post findLastPost(Topic topic) throws ModuleException;
- List findForumWatchedByUser(User user) throws ModuleException;
-
- List findTopicWatchedByUser(User user) throws ModuleException;
-
- List findTopicWatchedByUser(User user,Date date) throws ModuleException;
-
- Map findTopicWatches(User user) throws ModuleException;
-
- Attachment findFindAttachmentById(Integer attachID)
- throws ModuleException;
+ Map findLastPostsOfTopics(Collection topics) throws ModuleException;
+ Map findLastPostsOfForums() throws ModuleException;
- Poster createPoster(String userID) throws ModuleException;
+ List findForumWatchByUser(User user) throws ModuleException;
- /**
- * @param poster
- * @param forum
- * @param i
- */
- void createWatch(Poster poster, Forum forum, int i) throws ModuleException;
+ List findForumWatchedByUser(User user) throws ModuleException;
- /**
- * @param forumWatchID
- * @return DOCUMENT_ME
- */
- ForumWatch findForumWatchById(Integer forumWatchID) throws ModuleException;
+ List findTopicWatchedByUser(User user) throws ModuleException;
- Map findForumWatches(User user) throws ModuleException;
-
- /**
- *
- * @param user
- * @param forumId
- * @return ForumWatch
- * @throws ModuleException
- */
- ForumWatch findForumWatchByUserAndForum(User user,int forumId) throws ModuleException;
-
- /**
- *
- * @param user
- * @param topicId
- * @return TopicWatch
- * @throws ModuleException
- */
- TopicWatch findTopicWatchByUserAndTopic(User user,int topicId) throws ModuleException;
-
- /**
- * @param poster
- * @param topic
- */
- void createWatch(Poster poster, Topic topic, int mode) throws ModuleException;
+ List findTopicWatchedByUser(User user, Date date) throws ModuleException;
- /**
- * @param topicWatchID
- * @return DOCUMENT_ME
- */
- TopicWatch findTopicWatchById(Integer topicWatchID) throws ModuleException;
+ List findPostsFromForumAsc(Forum forum, int limit) throws ModuleException;
- /**
- * @param watch
- */
- void removeWatch(Watch watch) throws ModuleException;
-
- /**
- *
- *
- */
- public void processNotifications (Integer postId, int watchType , String postUrl , String replyUrl );
-
- /**
- *
- * @return
- */
- public UserProfileModule getUserProfileModule();
+ List findPostsFromForumDesc(Forum forum, int limit) throws ModuleException;
+ List findPostsFromCategoryAsc(Category category, int limit)
+ throws ModuleException;
+
+ List findPostsFromCategoryDesc(Category category, int limit)
+ throws ModuleException;
+
+ Map findTopicWatches(User user) throws ModuleException;
+
+ Attachment findFindAttachmentById(Integer attachID) throws ModuleException;
+
+ Poster createPoster(String userID) throws ModuleException;
+
+ /**
+ * @param poster
+ * @param forum
+ * @param i
+ */
+ void createWatch(Poster poster, Forum forum, int i) throws ModuleException;
+
+ /**
+ * @param forumWatchID
+ * @return DOCUMENT_ME
+ */
+ ForumWatch findForumWatchById(Integer forumWatchID) throws ModuleException;
+
+ Map findForumWatches(User user) throws ModuleException;
+
+ /**
+ *
+ * @param user
+ * @param forumId
+ * @return ForumWatch
+ * @throws ModuleException
+ */
+ ForumWatch findForumWatchByUserAndForum(User user, int forumId)
+ throws ModuleException;
+
+ /**
+ *
+ * @param user
+ * @param topicId
+ * @return TopicWatch
+ * @throws ModuleException
+ */
+ TopicWatch findTopicWatchByUserAndTopic(User user, int topicId)
+ throws ModuleException;
+
+ /**
+ * @param poster
+ * @param topic
+ */
+ void createWatch(Poster poster, Topic topic, int mode)
+ throws ModuleException;
+
+ /**
+ * @param topicWatchID
+ * @return DOCUMENT_ME
+ */
+ TopicWatch findTopicWatchById(Integer topicWatchID) throws ModuleException;
+
+ /**
+ * @param watch
+ */
+ void removeWatch(Watch watch) throws ModuleException;
+
+ /**
+ *
+ *
+ */
+ public void processNotifications(Integer postId, int watchType,
+ String postUrl, String replyUrl);
+
+ /**
+ *
+ * @return
+ */
+ public UserProfileModule getUserProfileModule();
+
+ public List findPostsDesc(int limit) throws ModuleException;
+
+ public List findPostsAsc(int limit) throws ModuleException;
+
}
\ No newline at end of file
Modified: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java 2007-06-27 11:06:19 UTC (rev 12889)
@@ -2,11 +2,7 @@
import java.io.IOException;
import java.io.Writer;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import javax.naming.InitialContext;
@@ -60,6 +56,8 @@
private static final String WRONG_FEED_SHOW_TYPE = "Wrong feed forum type: ";
+ private static final int POST_LIMIT = 20;
+
private TransactionManager tm;
public void init() {
@@ -76,7 +74,9 @@
try {
String[] uri = request.getRequestURI().split("/");
- if (uri.length != 6) {
+ if (uri.length < 5
+ || (uri[4].equals(FeedConstants.GLOBAL) && uri.length != 5)
+ || (!uri[4].equals(FeedConstants.GLOBAL) && uri.length != 6)) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
WRONG_FEED_REQ);
return;
@@ -84,10 +84,12 @@
String type = uri[3];
String what = uri[4];
- Integer id = Integer.valueOf(uri[5]);
- log.info("Type = " + type + " what = " + what + " id = " + id);
+ Integer id = null;
+ if (!what.equals(FeedConstants.GLOBAL))
+ id = Integer.valueOf(uri[5]);
+
SyndFeed feed = new SyndFeedImpl();
if (!setFeedType(feed, type)) {
@@ -118,14 +120,17 @@
} else if (what.equals(FeedConstants.TOPIC)) {
createTopicFeed(feed, id);
} else if (what.equals(FeedConstants.GLOBAL)) {
-
+ createGlobalFeed(feed, id);
} else {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
WRONG_FEED_SHOW_TYPE + what);
return;
}
} catch (ModuleException e) {
- e.printStackTrace();
+ response.sendError(
+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e
+ .getMessage());
+ return;
}
} catch (TransactionException e) {
@@ -154,29 +159,37 @@
}
+ private void createGlobalFeed(SyndFeed feed, Integer id)
+ throws ModuleException {
+ feed.setTitle("JBoss Forums Global Feed");
+ feed.setLink(PortalUtil.globalPermlink());
+ feed.setDescription("Messages posted in JBoss Forums");
+
+ List entries = new ArrayList();
+
+ List posts = forumsModule.findPostsDesc(POST_LIMIT);
+
+ for (int i = 0; i < posts.size(); i++) {
+ entries.add(getEntry((Post) posts.get(i)));
+ }
+
+ feed.setEntries(entries);
+ }
+
private void createForumFeed(SyndFeed feed, Integer id)
throws ModuleException {
Forum forum = forumsModule.findForumById(id);
feed.setTitle("JBoss Forums Forum Feed: " + forum.getName());
- feed.setLink("http://rome.dev.java.net");
+ feed.setLink(PortalUtil.categoryPermlink(id.toString()));
feed.setDescription("Messages posted in forum " + forum.getName()
+ " in category " + forum.getCategory().getTitle());
List entries = new ArrayList();
- List posts = new ArrayList();
+ List posts = forumsModule.findPostsFromForumDesc(forum, POST_LIMIT);
- for (int i = 0; i < forum.getTopics().size(); i++) {
- Topic topic = (Topic) forum.getTopics().get(i);
-
- posts.addAll(topic.getPosts());
-
- }
-
- sortPostList(posts);
-
for (int i = 0; i < posts.size(); i++) {
entries.add(getEntry((Post) posts.get(i)));
}
@@ -191,7 +204,7 @@
Topic topic = forumsModule.findTopicById(id);
feed.setTitle("JBoss Forums Topic Feed: " + topic.getSubject());
- feed.setLink("http://rome.dev.java.net");
+ feed.setLink(PortalUtil.topicPermlink(id.toString()));
feed.setDescription("Messages posted in topic " + topic.getSubject()
+ " in forum " + topic.getForum().getName() + " in category "
+ topic.getForum().getCategory().getTitle());
@@ -200,8 +213,6 @@
List posts = topic.getPosts();
- sortPostList(posts);
-
for (int i = 0; i < posts.size(); i++) {
entries.add(getEntry((Post) posts.get(i)));
}
@@ -210,19 +221,6 @@
}
- private void sortPostList(List posts) {
- Collections.sort(posts, new Comparator() {
-
- public int compare(Object o1, Object o2) {
- Post p1 = (Post) o1;
- Post p2 = (Post) o2;
-
- return p1.getCreateDate().compareTo(p2.getCreateDate());
- }
-
- });
- }
-
private boolean setFeedType(SyndFeed feed, String type) {
if (type.equals(FeedConstants.RSS)) {
feed.setFeedType("rss_2.0");
@@ -239,13 +237,20 @@
Category category = forumsModule.findCategoryById(id);
- feed.setTitle("JBoss Forums");
- feed.setLink("http://rome.dev.java.net");
- feed
- .setDescription("This feed has been created using ROME (Java syndication utilities");
+ feed.setTitle("JBoss Forums Category Feed: " + category.getTitle());
+ feed.setLink(PortalUtil.categoryPermlink(id.toString()));
+ feed.setDescription("Messages posted in category "
+ + category.getTitle());
List entries = new ArrayList();
+ List posts = forumsModule.findPostsFromCategoryDesc(category,
+ POST_LIMIT);
+
+ for (int i = 0; i < posts.size(); i++) {
+ entries.add(getEntry((Post) posts.get(i)));
+ }
+
feed.setEntries(entries);
}
@@ -256,8 +261,8 @@
entry = new SyndEntryImpl();
entry.setTitle(post.getMessage().getSubject() + " by "
- + post.getPoster().getUserId());
- entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
+ + post.getPoster().getUser().getUserName());
+ entry.setLink(PortalUtil.postPermlink(post.getId().toString()));
entry.setPublishedDate(post.getCreateDate());
description = new SyndContentImpl();
description.setType("text/html");
Modified: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2007-06-27 11:06:19 UTC (rev 12889)
@@ -47,7 +47,6 @@
import org.jboss.portlet.forums.model.Watch;
import org.jboss.portlet.forums.util.NotificationEngine;
-
/**
* @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
* @author <a href="mailto:boleslaw.dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
@@ -56,1878 +55,1565 @@
* @jmx.mbean
* @jboss.xmbean
*/
-public class ForumsModuleImpl
- extends AbstractModule
- implements ForumsModule
-{
+public class ForumsModuleImpl extends AbstractModule implements ForumsModule {
- private final Logger log = Logger.getLogger(getClass());
+ private final Logger log = Logger.getLogger(getClass());
- private HibernateProvider hibernate;
- private SessionFactory factory;
- private UserProfileModule userProfileModule;
+ private HibernateProvider hibernate;
- private NotificationEngine notificationEngine;
-
- private int floodInterval;
+ private SessionFactory factory;
- private String fromAddress;
+ private UserProfileModule userProfileModule;
-// private final ResourceCacheInvalidatorInterceptor resourceInterceptor;
-// private final IndexInterceptor indexInterceptor;
-// private CompositeFilter compositeInterceptor;
-// private NotificationInterceptor notificationInterceptor;
-// private FloodControlInterceptor floodControlInterceptor;
-// private ExecuteFilter executeInterceptor;
-// private CommandFilter chain;
+ private NotificationEngine notificationEngine;
- protected void startService() throws Exception
- {
- super.startService();
+ private int floodInterval;
- factory = hibernate.getSessionFactory();
- userProfileModule = (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
- notificationEngine = new NotificationEngine(this);
- notificationEngine.setFrom(fromAddress);
- // Define the chain of interceptors
-// chain = compositeInterceptor = new CompositeFilter();
-// resourceInterceptor = new ResourceCacheInvalidatorInterceptor();
-// indexInterceptor = new IndexInterceptor();
-// floodControlInterceptor = new FloodControlInterceptor();
-// floodControlInterceptor.setFloodInterval(floodInterval);
-// executeInterceptor = new ExecuteFilter();
+ private String fromAddress;
- // Assemble the chain
-// compositeInterceptor.setNext(resourceInterceptor);
-// resourceInterceptor.setNext(indexInterceptor);
-// indexInterceptor.setNext(notificationInterceptor);
+ // private final ResourceCacheInvalidatorInterceptor resourceInterceptor;
+ // private final IndexInterceptor indexInterceptor;
+ // private CompositeFilter compositeInterceptor;
+ // private NotificationInterceptor notificationInterceptor;
+ // private FloodControlInterceptor floodControlInterceptor;
+ // private ExecuteFilter executeInterceptor;
+ // private CommandFilter chain;
-// compositeInterceptor.setNext(executeInterceptor);
-// notificationInterceptor.setNext(floodControlInterceptor);
-// floodControlInterceptor.setNext(executeInterceptor);
- }
+ protected void startService() throws Exception {
+ super.startService();
- /**
- * @jmx.managed-attribute
- */
- public HibernateProvider getHibernate()
- {
- return hibernate;
- }
+ factory = hibernate.getSessionFactory();
+ userProfileModule = (UserProfileModule) new InitialContext()
+ .lookup("java:portal/UserProfileModule");
+ notificationEngine = new NotificationEngine(this);
+ notificationEngine.setFrom(fromAddress);
+ // Define the chain of interceptors
+ // chain = compositeInterceptor = new CompositeFilter();
+ // resourceInterceptor = new ResourceCacheInvalidatorInterceptor();
+ // indexInterceptor = new IndexInterceptor();
+ // floodControlInterceptor = new FloodControlInterceptor();
+ // floodControlInterceptor.setFloodInterval(floodInterval);
+ // executeInterceptor = new ExecuteFilter();
- /**
- * @jmx.managed-attribute
- */
- public void setHibernate(HibernateProvider hibernate)
- {
- this.hibernate = hibernate;
- }
+ // Assemble the chain
+ // compositeInterceptor.setNext(resourceInterceptor);
+ // resourceInterceptor.setNext(indexInterceptor);
+ // indexInterceptor.setNext(notificationInterceptor);
- /**
- * @jmx.managed-attribute
- */
- public int getFloodInterval()
- {
- return floodInterval;
- }
+ // compositeInterceptor.setNext(executeInterceptor);
+ // notificationInterceptor.setNext(floodControlInterceptor);
+ // floodControlInterceptor.setNext(executeInterceptor);
+ }
- /**
- * @jmx.managed-attribute
- */
- public void setFloodInterval(int floodInterval)
- {
- this.floodInterval = floodInterval;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public HibernateProvider getHibernate() {
+ return hibernate;
+ }
- /**
- * @jmx.managed-attribute
- */
- public String getFromAddress()
- {
- return fromAddress;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setHibernate(HibernateProvider hibernate) {
+ this.hibernate = hibernate;
+ }
- /**
- * @jmx.managed-attribute
- */
- public void setFromAddress(String fromAddress)
- {
- this.fromAddress = fromAddress;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public int getFloodInterval() {
+ return floodInterval;
+ }
- public Forum findForumById(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- ForumImpl forum = (ForumImpl)session.get(ForumImpl.class, id);
- if (forum == null)
- {
- throw new ModuleException("No forum found for " + id);
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setFloodInterval(int floodInterval) {
+ this.floodInterval = floodInterval;
+ }
- return forum;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
-
- public Forum findForumByIdFetchTopics(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select f " +
- "from ForumImpl f " +
- "left outer join fetch f.topics " +
- "where f.id = :forumId ");
- query.setParameter("forumId",id);
- List forumList = query.list();
- if (forumList == null)
- {
- throw new ModuleException("No forum found for " + id);
- }
-
- if (forumList.size()>0) {
- return (Forum)forumList.get(0);
- } else {
- return null;
- }
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public String getFromAddress() {
+ return fromAddress;
+ }
- public Category findCategoryById(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- CategoryImpl category = (CategoryImpl)session.get(CategoryImpl.class, id);
- if (category == null)
- {
- throw new ModuleException("No category found for " + id);
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setFromAddress(String fromAddress) {
+ this.fromAddress = fromAddress;
+ }
- return category;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find category by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ public Forum findForumById(Integer id) throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ ForumImpl forum = (ForumImpl) session.get(ForumImpl.class, id);
+ if (forum == null) {
+ throw new ModuleException("No forum found for " + id);
+ }
- public Category findCategoryByIdFetchForums(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery(" from CategoryImpl as c " +
- " join fetch c.forums " +
- " where c.id=:categoryId ");
- query.setParameter("categoryId",id);
- Category category = (Category)query.uniqueResult();
- if (category == null)
- {
- throw new ModuleException("No category found for " + id);
- }
+ return forum;
+ } catch (HibernateException e) {
+ String message = "Cannot find forum by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- return category;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find category by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ public Forum findForumByIdFetchTopics(Integer id) throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select f "
+ + "from ForumImpl f "
+ + "left outer join fetch f.topics "
+ + "where f.id = :forumId ");
+ query.setParameter("forumId", id);
+ List forumList = query.list();
+ if (forumList == null) {
+ throw new ModuleException("No forum found for " + id);
+ }
+ if (forumList.size() > 0) {
+ return (Forum) forumList.get(0);
+ } else {
+ return null;
+ }
+ } catch (HibernateException e) {
+ String message = "Cannot find forum by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public Poster findPosterByUserId(String userId)
- throws ModuleException
- {
- if (userId != null)
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from PosterImpl as u where u.userId=:userId");
- query.setString("userId", userId);
- PosterImpl user = (PosterImpl)query.uniqueResult();
- return user;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find poster by name " + userId;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("user name cannot be null");
- }
- }
+ public Category findCategoryById(Integer id) throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ CategoryImpl category = (CategoryImpl) session.get(
+ CategoryImpl.class, id);
+ if (category == null) {
+ throw new ModuleException("No category found for " + id);
+ }
- public Poster createPoster(String userId)
- throws ModuleException
- {
- if (userId != null)
- {
- try
- {
- Session session = getSession();
- PosterImpl user = new PosterImpl();
- user.setUserId(userId);
- session.save(user);
- return user;
- }
- catch (HibernateException e)
- {
- String message = "Cannot create Poster";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("user name cannot be null");
- }
- }
+ return category;
+ } catch (HibernateException e) {
+ String message = "Cannot find category by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public List findCategories()
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from CategoryImpl as c order by c.order asc");
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find categories";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findCategoriesFetchForums()
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery(" select c " +
- " from CategoryImpl as c " +
- " left outer join fetch c.forums " +
- " order by c.order asc");
- List categoriesWithDuplicates = query.list();
- Iterator it = categoriesWithDuplicates.iterator();
- List categories = new LinkedList();
- while (it.hasNext()) {
- Category category = (Category)it.next();
- if (!categories.contains(category)) {
- categories.add(category);
- }
- }
- return categories;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find categories";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public Category findCategoryByIdFetchForums(Integer id)
+ throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery(" from CategoryImpl as c "
+ + " join fetch c.forums " + " where c.id=:categoryId ");
+ query.setParameter("categoryId", id);
+ Category category = (Category) query.uniqueResult();
+ if (category == null) {
+ throw new ModuleException("No category found for " + id);
+ }
- public List findForums()
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from ForumImpl as f order by f.order asc");
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forums";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ return category;
+ } catch (HibernateException e) {
+ String message = "Cannot find category by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public List findForumsByCategoryId(Integer categoryId)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from ForumImpl as f where f.category=:categoryId order by f.order asc");
- query.setString("categoryId",
- categoryId.toString());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forums";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public Poster findPosterByUserId(String userId) throws ModuleException {
+ if (userId != null) {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from PosterImpl as u where u.userId=:userId");
+ query.setString("userId", userId);
+ PosterImpl user = (PosterImpl) query.uniqueResult();
+ return user;
+ } catch (HibernateException e) {
+ String message = "Cannot find poster by name " + userId;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("user name cannot be null");
+ }
+ }
- public List findAnnouncements(Forum forum)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.forum=:forumid and t.type = :type order by t.lastPostDate");
- query.setString("forumid", "" + forum.getId());
- query.setString("type", "" + ForumsConstants.POST_ANNOUNCE);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forums";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public Poster createPoster(String userId) throws ModuleException {
+ if (userId != null) {
+ try {
+ Session session = getSession();
+ PosterImpl user = new PosterImpl();
+ user.setUserId(userId);
+ session.save(user);
+ return user;
+ } catch (HibernateException e) {
+ String message = "Cannot create Poster";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("user name cannot be null");
+ }
+ }
- public List findTopics() throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl");
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
+ public List findCategories() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from CategoryImpl as c order by c.order asc");
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find categories";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+ public List findCategoriesFetchForums() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery(" select c "
+ + " from CategoryImpl as c "
+ + " left outer join fetch c.forums "
+ + " order by c.order asc");
+ List categoriesWithDuplicates = query.list();
+ Iterator it = categoriesWithDuplicates.iterator();
+ List categories = new LinkedList();
+ while (it.hasNext()) {
+ Category category = (Category) it.next();
+ if (!categories.contains(category)) {
+ categories.add(category);
+ }
+ }
+ return categories;
+ } catch (HibernateException e) {
+ String message = "Cannot find categories";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- }
+ public List findForums() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from ForumImpl as f order by f.order asc");
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find forums";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- /**
- *
- * @param forum
- * @param type
- * @param start
- * @param perPage
- * @param order
- * @return
- * @throws ModuleException
- */
- private List findTopics(Forum forum,
- int type,
- int start,
- int perPage,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t " +
- "join fetch t.poster " +
- "where t.forum = :forumid " +
- "and t.type = :type " +
- "order by t.lastPostDate " + order);
- query.setFirstResult(start);
- query.setMaxResults(perPage);
- query.setString("forumid", "" + forum.getId());
- query.setString("type", "" + type);
- List list = query.list();
- return list;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- throw new ModuleException(message, e);
- } catch (Exception e) {
- String message = "Error while using ForumsModule.";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findForumsByCategoryId(Integer categoryId)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from ForumImpl as f where f.category=:categoryId order by f.order asc");
+ query.setString("categoryId", categoryId.toString());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find forums";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+ public List findAnnouncements(Forum forum) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t where t.forum=:forumid and t.type = :type order by t.lastPostDate");
+ query.setString("forumid", "" + forum.getId());
+ query.setString("type", "" + ForumsConstants.POST_ANNOUNCE);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find forums";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- /**
- *
- * @param forum
- * @param start
- * @param perPage
- * @param order
- * @return
- * @throws ModuleException
- */
- private List findTopics(Forum forum,
- int start,
- int perPage,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t " +
- "join fetch t.poster " +
- "where t.forum = :forumid " +
- "order by t.lastPostDate " + order);
- query.setFirstResult(start);
- query.setMaxResults(perPage);
- query.setString("forumid", "" + forum.getId());
- List list = query.list();
- return list;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- throw new ModuleException(message, e);
- } catch (Exception e) {
- String message = "Error while using ForumsModule.";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findTopics() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("from TopicImpl");
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
- public List findTopicsAsc(Forum forum,
- int type,
- int start,
- int perPage)
- throws ModuleException
- {
- return findTopics(forum, type, start, perPage, "asc");
- }
+ }
+ /**
+ *
+ * @param forum
+ * @param type
+ * @param start
+ * @param perPage
+ * @param order
+ * @return
+ * @throws ModuleException
+ */
+ private List findTopics(Forum forum, int type, int start, int perPage,
+ String order) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("from TopicImpl as t "
+ + "join fetch t.poster " + "where t.forum = :forumid "
+ + "and t.type = :type " + "order by t.lastPostDate "
+ + order);
+ query.setFirstResult(start);
+ query.setMaxResults(perPage);
+ query.setString("forumid", "" + forum.getId());
+ query.setString("type", "" + type);
+ List list = query.list();
+ return list;
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ throw new ModuleException(message, e);
+ } catch (Exception e) {
+ String message = "Error while using ForumsModule.";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public List findTopicsDesc(Forum forum,
- int type,
- int start,
- int perPage)
- throws ModuleException
- {
- return findTopics(forum, type, start, perPage, "desc");
- }
-
- public List findTopicsAsc(Forum forum,
- int start,
- int perPage)
- throws ModuleException
- {
- return findTopics(forum, start, perPage, "asc");
- }
+ /**
+ *
+ * @param forum
+ * @param start
+ * @param perPage
+ * @param order
+ * @return
+ * @throws ModuleException
+ */
+ private List findTopics(Forum forum, int start, int perPage, String order)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("from TopicImpl as t "
+ + "join fetch t.poster " + "where t.forum = :forumid "
+ + "order by t.lastPostDate " + order);
+ query.setFirstResult(start);
+ query.setMaxResults(perPage);
+ query.setString("forumid", "" + forum.getId());
+ List list = query.list();
+ return list;
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ throw new ModuleException(message, e);
+ } catch (Exception e) {
+ String message = "Error while using ForumsModule.";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+ public List findTopicsAsc(Forum forum, int type, int start, int perPage)
+ throws ModuleException {
+ return findTopics(forum, type, start, perPage, "asc");
+ }
- public List findTopicsDesc(Forum forum,
- int start,
- int perPage)
- throws ModuleException
- {
- return findTopics(forum, start, perPage, "desc");
- }
+ public List findTopicsDesc(Forum forum, int type, int start, int perPage)
+ throws ModuleException {
+ return findTopics(forum, type, start, perPage, "desc");
+ }
- public List findTopicsBefore(Forum forum,
- int type,
- int start,
- int perPage,
- Date date)
- throws ModuleException
- {
- return null;
- }
+ public List findTopicsAsc(Forum forum, int start, int perPage)
+ throws ModuleException {
+ return findTopics(forum, start, perPage, "asc");
+ }
- public List findTopicsHot(int replies, int limit)
- throws ModuleException
- {
- try
- {
- //"SELECT OBJECT(t) FROM topic AS t WHERE t.replies > ?1 ORDER BY t.creationDate DESC LIMIT ?2"
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.replies > :replies order by t.lastPostDate desc");
- query.setMaxResults(limit);
- query.setInteger("replies", replies);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findTopicsDesc(Forum forum, int start, int perPage)
+ throws ModuleException {
+ return findTopics(forum, start, perPage, "desc");
+ }
- public List findTopicsByLatestPosts(int limit)
- throws ModuleException
- {
- try
- {
- //SELECT DISTINCT OBJECT(t) FROM topic AS t ORDER BY t.lastPostDate DESC LIMIT ?1"
+ public List findTopicsBefore(Forum forum, int type, int start, int perPage,
+ Date date) throws ModuleException {
+ return null;
+ }
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t order by t.lastPostDate desc");
- query.setMaxResults(limit);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findTopicsHot(int replies, int limit) throws ModuleException {
+ try {
+ // "SELECT OBJECT(t) FROM topic AS t WHERE t.replies > ?1 ORDER BY
+ // t.creationDate DESC LIMIT ?2"
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t where t.replies > :replies order by t.lastPostDate desc");
+ query.setMaxResults(limit);
+ query.setInteger("replies", replies);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public List findTopicsHottest(Date after, int limit)
- throws ModuleException
- {
- try
- {
- //"SELECT OBJECT(t) FROM topic AS t WHERE t.lastPostDate > ?1 ORDER BY t.replies DESC LIMIT ?2"
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.lastPostDate > :after order by t.replies desc");
- query.setMaxResults(limit);
- query.setDate("after", after);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findTopicsByLatestPosts(int limit) throws ModuleException {
+ try {
+ // SELECT DISTINCT OBJECT(t) FROM topic AS t ORDER BY t.lastPostDate
+ // DESC LIMIT ?1"
- public List findTopicsMostViewed(Date after, int limit)
- throws ModuleException
- {
- try
- {
- //"SELECT OBJECT(t) FROM topic AS t WHERE t.lastPostDate > ?1 ORDER BY t.views DESC LIMIT ?2"
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.lastPostDate > :after order by t.viewCount desc");
- query.setMaxResults(limit);
- query.setDate("after", after);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t order by t.lastPostDate desc");
+ query.setMaxResults(limit);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+ public List findTopicsHottest(Date after, int limit) throws ModuleException {
+ try {
+ // "SELECT OBJECT(t) FROM topic AS t WHERE t.lastPostDate > ?1 ORDER
+ // BY t.replies DESC LIMIT ?2"
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t where t.lastPostDate > :after order by t.replies desc");
+ query.setMaxResults(limit);
+ query.setDate("after", after);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public Post createTopic(Forum forum,
- Message message,
- Date creationDate,
- Poster poster,
- Poll poll,
- List attachments,
- int type)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
+ public List findTopicsMostViewed(Date after, int limit)
+ throws ModuleException {
+ try {
+ // "SELECT OBJECT(t) FROM topic AS t WHERE t.lastPostDate > ?1 ORDER
+ // BY t.views DESC LIMIT ?2"
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t where t.lastPostDate > :after order by t.viewCount desc");
+ query.setMaxResults(limit);
+ query.setDate("after", after);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- session.save(poster);
- session.save(poll);
+ public Post createTopic(Forum forum, Message message, Date creationDate,
+ Poster poster, Poll poll, List attachments, int type)
+ throws ModuleException {
+ try {
+ Session session = getSession();
-
+ session.save(poster);
+ session.save(poll);
- PostImpl post = new PostImpl();
- post.setMessage(message);
- post.setCreateDate(creationDate);
- post.setPoster(poster);
- //post.setAttachments(attachments);
- for (Iterator i = attachments.iterator(); i.hasNext();)
- {
- Attachment a = (Attachment)i.next();
- session.save(a);
- post.addAttachment(a);
- }
- session.save(post);
+ PostImpl post = new PostImpl();
+ post.setMessage(message);
+ post.setCreateDate(creationDate);
+ post.setPoster(poster);
+ // post.setAttachments(attachments);
+ for (Iterator i = attachments.iterator(); i.hasNext();) {
+ Attachment a = (Attachment) i.next();
+ session.save(a);
+ post.addAttachment(a);
+ }
+ session.save(post);
- TopicImpl topic = new TopicImpl();
- topic.setSubject(message.getSubject());
- //topic.setForum(forum);
- forum.addTopic(topic);
- topic.setPoster(poster);
- //topic.setFirstPost(post);
- //topic.setLastPost(post);
- topic.addPost(post);
- //post.setTopic(topic);
- topic.setLastPostDate(creationDate);
- topic.setType(type);
- topic.setStatus(ForumsConstants.TOPIC_UNLOCKED);
- topic.setPoll(poll);
+ TopicImpl topic = new TopicImpl();
+ topic.setSubject(message.getSubject());
+ // topic.setForum(forum);
+ forum.addTopic(topic);
+ topic.setPoster(poster);
+ // topic.setFirstPost(post);
+ // topic.setLastPost(post);
+ topic.addPost(post);
+ // post.setTopic(topic);
+ topic.setLastPostDate(creationDate);
+ topic.setType(type);
+ topic.setStatus(ForumsConstants.TOPIC_UNLOCKED);
+ topic.setPoll(poll);
+ session.save(topic);
- session.save(topic);
+ forum.addTopicSize();
+ forum.addPostSize();
- forum.addTopicSize();
- forum.addPostSize();
+ post.setTopic(topic);
+ notificationEngine.scheduleForNotification(post.getId(),
+ NotificationEngine.MODE_POST);
+ return post;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- post.setTopic(topic);
- notificationEngine.scheduleForNotification(post.getId(), NotificationEngine.MODE_POST);
- return post;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public Topic createTopic(Forum forum, String userId, String subject,
+ int type) throws ModuleException {
+ try {
+ Session session = getSession();
- public Topic createTopic(Forum forum,
- String userId,
- String subject,
- int type)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
+ Poster poster = findPosterByUserId(userId);
- Poster poster = findPosterByUserId(userId);
+ if (poster == null) {
+ poster = createPoster(userId);
+ }
+ session.save(poster);
- if (poster == null)
- {
- poster = createPoster(userId);
- }
- session.save(poster);
+ TopicImpl topic = new TopicImpl();
+ topic.setSubject(subject);
+ // topic.setForum(forum);
+ forum.addTopic(topic);
+ topic.setPoster(poster);
+ // topic.setFirstPost(post);
+ // topic.setLastPost(post);
+ // topic.addPost(post);
+ // post.setTopic(topic);
+ // topic.setLastPostDate(creationDate);
+ topic.setType(type);
- TopicImpl topic = new TopicImpl();
- topic.setSubject(subject);
- //topic.setForum(forum);
- forum.addTopic(topic);
- topic.setPoster(poster);
- //topic.setFirstPost(post);
- //topic.setLastPost(post);
- //topic.addPost(post);
- //post.setTopic(topic);
- //topic.setLastPostDate(creationDate);
- topic.setType(type);
+ topic.setPoll(null);
- topic.setPoll(null);
+ session.save(topic);
+ // forum.addTopicSize();
+ // forum.addPostSize();
+ return topic;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- session.save(topic);
- //forum.addTopicSize();
- //forum.addPostSize();
+ public Post createPost(Topic topic, Forum forum, Message message,
+ Date creationDate, Poster poster, List attachments)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ session.save(poster);
+ PostImpl post = new PostImpl();
+ post.setMessage(message);
+ post.setCreateDate(creationDate);
+ post.setPoster(poster);
+ // post.setAttachments(attachments);
+ for (Iterator i = attachments.iterator(); i.hasNext();) {
+ Attachment a = (Attachment) i.next();
+ session.save(a);
+ post.addAttachment(a);
+ }
- return topic;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ session.save(post);
+ topic.addPost(post);
+ // post.setTopic(topic);
- public Post createPost(Topic topic,
- Forum forum,
- Message message,
- Date creationDate,
- Poster poster,
- List attachments)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- session.save(poster);
+ // topic.setLastPost(post);
+ topic.setLastPostDate(post.getCreateDate());
+ topic.setReplies(topic.getReplies() + 1);
+ session.save(topic);
+ // forum.setLastPost(post);
+ forum.addPostSize();
+ notificationEngine.scheduleForNotification(post.getId(),
+ NotificationEngine.MODE_REPLY);
+ return post;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
+ public Poll addPollToTopic(Topic topic, Poll poll) throws ModuleException {
+ try {
+ Session session = getSession();
+ Poll oldpoll = topic.getPoll();
+ if (oldpoll != null) {
+ session.delete(oldpoll);
+ }
+ session.save(poll);
+ topic.setPoll(poll);
+ return poll;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot add poll to topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- PostImpl post = new PostImpl();
- post.setMessage(message);
- post.setCreateDate(creationDate);
- post.setPoster(poster);
- //post.setAttachments(attachments);
- for (Iterator i = attachments.iterator(); i.hasNext();)
- {
- Attachment a = (Attachment)i.next();
- session.save(a);
- post.addAttachment(a);
- }
+ private int getLastCategoryOrder() {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select max(c.order) from CategoryImpl as c");
+ Integer lastCategoryOrder = (Integer) query.uniqueResult();
+ return (lastCategoryOrder != null) ? lastCategoryOrder.intValue()
+ : 0;
+ } catch (HibernateException e) {
+ return 0;
+ }
+ }
+ public Category createCategory(String name) throws ModuleException {
+ try {
+ Session session = getSession();
- session.save(post);
+ CategoryImpl category = new CategoryImpl();
+ category.setTitle(name);
+ category.setOrder(getLastCategoryOrder() + 10);
+ session.save(category);
+ return category;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- topic.addPost(post);
- //post.setTopic(topic);
+ public void removeCategory(Category category) throws ModuleException {
+ Session session = getSession();
+ try {
+ // session.flush();
+ session.delete(category);
+ // session.flush();
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete category";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- //topic.setLastPost(post);
- topic.setLastPostDate(post.getCreateDate());
- topic.setReplies(topic.getReplies() + 1);
- session.save(topic);
- //forum.setLastPost(post);
- forum.addPostSize();
- notificationEngine.scheduleForNotification(post.getId(), NotificationEngine.MODE_REPLY);
- return post;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public void removeForum(Forum forum) throws ModuleException {
+ Session session = getSession();
+ try {
+ // session.delete(forum);
+ if (forum.getCategory() != null) {
+ forum.getCategory().getForums().remove(forum);
+ forum.setCategory(null);
+ } else {
+ session.delete(forum);
+ }
- public Poll addPollToTopic(Topic topic,
- Poll poll)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Poll oldpoll = topic.getPoll();
- if (oldpoll != null)
- {
- session.delete(oldpoll);
- }
- session.save(poll);
- topic.setPoll(poll);
- return poll;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot add poll to topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ // session.flush();
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete forum";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- private int getLastCategoryOrder()
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select max(c.order) from CategoryImpl as c");
- Integer lastCategoryOrder = (Integer)query.uniqueResult();
- return (lastCategoryOrder != null) ? lastCategoryOrder.intValue() : 0;
- }
- catch (HibernateException e)
- {
- return 0;
- }
- }
+ public void removePost(Post post) throws ModuleException {
+ Session session = getSession();
+ try {
+ // session.flush();
+ // session.delete(post);
+ if (post.getTopic() != null) {
+ post.getTopic().getPosts().remove(post);
+ post.setTopic(null);
+ } else {
+ session.delete(post);
+ }
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete post";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- public Category createCategory(String name)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
+ public void removePollInTopic(Topic topic) throws ModuleException {
+ Session session = getSession();
+ try {
+ // session.flush();
+ Poll poll = topic.getPoll();
+ topic.setPoll(null);
+ session.delete(poll);
- CategoryImpl category = new CategoryImpl();
- category.setTitle(name);
- category.setOrder(getLastCategoryOrder() + 10);
- session.save(category);
- return category;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete poll";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- public void removeCategory(Category category)
- throws ModuleException
- {
- Session session = getSession();
- try
- {
- //session.flush();
- session.delete(category);
- //session.flush();
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete category";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public void removeTopic(Topic topic) throws ModuleException {
+ Session session = getSession();
+ try {
+ // session.flush();
+ // session.delete(topic);
+ Forum forum = topic.getForum();
+ if (forum != null) {
+ forum.getTopics().remove(topic);
+ topic.setForum(null);
+ forum.setPostCount(forum.getPostCount() - topic.getReplies()
+ - 1);
+ forum.setTopicCount(forum.getTopicCount() - 1);
+ // session.delete(topic);
+ } else {
+ session.delete(topic);
+ }
+ // session.flush();
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- public void removeForum(Forum forum)
- throws ModuleException
- {
- Session session = getSession();
- try
- {
- //session.delete(forum);
- if (forum.getCategory() != null)
- {
- forum.getCategory().getForums().remove(forum);
- forum.setCategory(null);
- }
- else
- {
- session.delete(forum);
- }
+ private int getLastForumOrder(Category category) {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select max(f.order) from ForumImpl as f where f.category = :categoryId");
+ query.setString("categoryId", "" + category.getId());
+ Integer lastForumOrder = (Integer) query.uniqueResult();
+ return (lastForumOrder != null) ? lastForumOrder.intValue() : 0;
+ } catch (HibernateException e) {
+ return 0;
+ }
+ }
- //session.flush();
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete forum";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public Forum createForum(Category category, String name, String description)
+ throws ModuleException {
+ try {
+ Session session = getSession();
- public void removePost(Post post)
- throws ModuleException
- {
- Session session = getSession();
- try
- {
- //session.flush();
- //session.delete(post);
- if (post.getTopic() != null)
- {
- post.getTopic().getPosts().remove(post);
- post.setTopic(null);
- }
- else
- {
- session.delete(post);
- }
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete post";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ ForumImpl forum = new ForumImpl();
+ // forum.setCategory(category);
+ category.addForum(forum);
+ forum.setName(name);
+ forum.setDescription(description);
+ forum.setOrder(getLastForumOrder(category) + 10);
+ session.save(forum);
+ return forum;
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create forum";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- public void removePollInTopic(Topic topic)
- throws ModuleException
- {
- Session session = getSession();
- try
- {
- //session.flush();
- Poll poll = topic.getPoll();
- topic.setPoll(null);
- session.delete(poll);
+ public Topic findTopicById(Integer id) throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ TopicImpl topic = (TopicImpl) session.get(TopicImpl.class, id);
+ if (topic == null) {
+ throw new ModuleException("No topic found for " + id);
+ }
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete poll";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ return topic;
+ } catch (HibernateException e) {
+ String message = "Cannot find forum by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public void removeTopic(Topic topic)
- throws ModuleException
- {
- Session session = getSession();
- try
- {
- //session.flush();
- //session.delete(topic);
- Forum forum = topic.getForum();
- if (forum != null)
- {
- forum.getTopics().remove(topic);
- topic.setForum(null);
- forum.setPostCount(forum.getPostCount()-topic.getReplies()-1);
- forum.setTopicCount(forum.getTopicCount()-1);
- //session.delete(topic);
- }
- else
- {
- session.delete(topic);
- }
- //session.flush();
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public List findTopics(Forum forum) throws ModuleException {
+ if (forum != null) {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicImpl as t where t.forum = :forumid");
+ query.setString("forumid", "" + forum.getId());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topics";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("forum cannot be null");
+ }
+ }
- private int getLastForumOrder(Category category)
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("select max(f.order) from ForumImpl as f where f.category = :categoryId");
- query.setString("categoryId", "" + category.getId());
- Integer lastForumOrder = (Integer)query.uniqueResult();
- return (lastForumOrder != null) ? lastForumOrder.intValue() : 0;
- }
- catch (HibernateException e)
- {
- return 0;
- }
- }
+ public List findPosts() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("from PostImpl");
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public Forum createForum(Category category,
- String name,
- String description)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
+ public Post findPostById(Integer id) throws ModuleException {
+ if (id != null) {
+ try {
+ Session session = getSession();
+ PostImpl post = (PostImpl) session.get(PostImpl.class, id);
+ if (post == null) {
+ throw new ModuleException("No post found for " + id);
+ }
- ForumImpl forum = new ForumImpl();
- //forum.setCategory(category);
- category.addForum(forum);
- forum.setName(name);
- forum.setDescription(description);
- forum.setOrder(getLastForumOrder(category) + 10);
- session.save(forum);
- return forum;
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create forum";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ return post;
+ } catch (HibernateException e) {
+ String message = "Cannot find post by id " + id;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public Topic findTopicById(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- TopicImpl topic = (TopicImpl)session.get(TopicImpl.class, id);
- if (topic == null)
- {
- throw new ModuleException("No topic found for " + id);
- }
+ public Attachment findFindAttachmentById(Integer attachID)
+ throws ModuleException {
+ if (attachID != null) {
+ try {
+ Session session = getSession();
+ Attachment attach = (Attachment) session.get(
+ AttachmentImpl.class, attachID);
+ if (attach == null) {
+ throw new ModuleException("No attachment found for "
+ + attachID);
+ }
- return topic;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ return attach;
+ } catch (HibernateException e) {
+ String message = "Cannot find attachment by id " + attachID;
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ } else {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
- public List findTopics(Forum forum)
- throws ModuleException
- {
- if (forum != null)
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from TopicImpl as t where t.forum = :forumid");
- query.setString("forumid", "" + forum.getId());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topics";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("forum cannot be null");
- }
- }
+ private List findPostsByTopicId(Integer topicId, int start, int limit,
+ String order) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from PostImpl as p where p.topic=:topicId order by p.createDate "
+ + order);
+ query.setString("topicId", topicId.toString());
+ query.setFirstResult(start);
+ if (limit != 0) {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public List findPosts()
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from PostImpl");
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find posts";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ private List findPostsByIdsFetchAttachmentsAndPosters(Collection postIds,
+ String order) throws ModuleException {
- public Post findPostById(Integer id)
- throws ModuleException
- {
- if (id != null)
- {
- try
- {
- Session session = getSession();
- PostImpl post = (PostImpl)session.get(PostImpl.class, id);
- if (post == null)
- {
- throw new ModuleException("No post found for " + id);
- }
+ if (postIds == null || postIds.size() == 0) {
+ return new LinkedList();
+ }
- return post;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find post by id " + id;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ try {
+ Session session = getSession();
+ Query query = session.createQuery(" from PostImpl as p "
+ + " join fetch p.poster "
+ + " left outer join fetch p.attachments "
+ + " where p.id IN ( :postIds ) "
+ + " order by p.createDate " + order);
+ query.setParameterList("postIds", postIds);
+ Iterator it = query.list().iterator();
+ List list = new LinkedList();
+ while (it.hasNext()) {
+ Post post = (Post) it.next();
+ if (!list.contains(post)) {
+ list.add(post);
+ }
+ }
+ return list;
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public Attachment findFindAttachmentById(Integer attachID)
- throws ModuleException
- {
- if (attachID != null)
- {
- try
- {
- Session session = getSession();
- Attachment attach = (Attachment)session.get(AttachmentImpl.class, attachID);
- if (attach == null)
- {
- throw new ModuleException("No attachment found for " + attachID);
- }
+ public List findPostsByIdsAscFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException {
+ return findPostsByIdsFetchAttachmentsAndPosters(postIds, "asc");
+ }
- return attach;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find attachment by id " + attachID;
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
+ public List findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException {
+ return findPostsByIdsFetchAttachmentsAndPosters(postIds, "desc");
+ }
- private List findPostsByTopicId(Integer topicId,
- int start,
- int limit,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from PostImpl as p where p.topic=:topicId order by p.createDate " + order);
- query.setString("topicId",
- topicId.toString());
- query.setFirstResult(start);
- if (limit != 0)
- {
- query.setMaxResults(limit);
- }
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find posts";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ private List findPostIds(Integer topicId, int start, int limit, String order)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select p.id "
+ + "from PostImpl as p " + "where p.topic=:topicId "
+ + "order by p.createDate " + order);
+ query.setString("topicId", topicId.toString());
+ query.setFirstResult(start);
+ if (limit != 0) {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find post ids";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- private List findPostsByIdsFetchAttachmentsAndPosters(Collection postIds ,
- String order)
- throws ModuleException
- {
-
- if (postIds==null || postIds.size()==0) {
- return new LinkedList();
- }
-
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery(" from PostImpl as p " +
- " join fetch p.poster " +
- " left outer join fetch p.attachments " +
- " where p.id IN ( :postIds ) " +
- " order by p.createDate " + order);
- query.setParameterList("postIds",postIds);
- Iterator it = query.list().iterator();
- List list = new LinkedList();
- while (it.hasNext()) {
- Post post = (Post)it.next();
- if (!list.contains(post)) {
- list.add(post);
- }
- }
- return list;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find posts";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findPostsByIdsAscFetchAttachmentsAndPosters(Collection postIds)
- throws ModuleException
- {
- return findPostsByIdsFetchAttachmentsAndPosters( postIds , "asc");
- }
+ public List findPostIdsAsc(Integer topicId, int start, int limit)
+ throws ModuleException {
+ return findPostIds(topicId, start, limit, "asc");
+ }
- public List findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
- throws ModuleException
- {
- return findPostsByIdsFetchAttachmentsAndPosters( postIds , "desc");
- }
+ public List findPostIdsDesc(Integer topicId, int start, int limit)
+ throws ModuleException {
+ return findPostIds(topicId, start, limit, "desc");
+ }
- private List findPostIds(Integer topicId,
- int start,
- int limit,
- String order)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("select p.id " +
- "from PostImpl as p " +
- "where p.topic=:topicId " +
- "order by p.createDate " + order);
- query.setString("topicId", topicId.toString());
- query.setFirstResult(start);
- if (limit != 0)
- {
- query.setMaxResults(limit);
- }
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find post ids";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findPostIdsAsc(Integer topicId,
- int start,
- int limit)
- throws ModuleException
- {
- return findPostIds(topicId, start, limit, "asc");
- }
+ public List findPostsByTopicId(Integer topicId) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from PostImpl as p where p.topic=:topicId");
+ query.setString("topicId", topicId.toString());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public List findPostIdsDesc(Integer topicId,
- int start,
- int limit)
- throws ModuleException
- {
- return findPostIds(topicId, start, limit, "desc");
- }
+ public void addAllForums(Category source, Category target)
+ throws ModuleException {
+ List sourceForums = this.findForumsByCategoryId(source.getId());
+ List targetForums = this.findForumsByCategoryId(target.getId());
+ targetForums.addAll(sourceForums);
+ Iterator iterator = targetForums.iterator();
+ while (iterator.hasNext()) {
+ Forum forum = (Forum) iterator.next();
+ forum.setCategory(target);
+ }
+ source.setForums(new ArrayList());
+ }
- public List findPostsByTopicId(Integer topicId)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from PostImpl as p where p.topic=:topicId");
- query.setString("topicId",
- topicId.toString());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find posts";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findPostsByTopicIdAsc(Integer topicId, int start, int limit)
+ throws ModuleException {
+ return findPostsByTopicId(topicId, start, limit, "asc");
+ }
+ public List findPostsByTopicIdDesc(Integer topicId, int start, int limit)
+ throws ModuleException {
+ return findPostsByTopicId(topicId, start, limit, "desc");
+ }
- public void addAllForums(Category source,
- Category target)
- throws ModuleException
- {
- List sourceForums = this.findForumsByCategoryId(source.getId());
- List targetForums = this.findForumsByCategoryId(target.getId());
- targetForums.addAll(sourceForums);
- Iterator iterator = targetForums.iterator();
- while (iterator.hasNext())
- {
- Forum forum = (Forum)iterator.next();
- forum.setCategory(target);
- }
- source.setForums(new ArrayList());
- }
+ public Date findLastPostDateForUser(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select max(p.createDate) from PostImpl as p where p.poster.userId = :userId");
+ query.setString("userId", "" + user.getId().toString());
+ Date lastPostDate = (Date) query.uniqueResult();
+ return lastPostDate;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- public List findPostsByTopicIdAsc(Integer topicId,
- int start,
- int limit)
- throws ModuleException
- {
- return findPostsByTopicId(topicId, start, limit, "asc");
- }
+ public Post findLastPost(Forum forum) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query =
- public List findPostsByTopicIdDesc(Integer topicId,
- int start,
- int limit)
- throws ModuleException
- {
- return findPostsByTopicId(topicId, start, limit, "desc");
- }
+ // This is old query, considered as less efficient
+ // session.createQuery("from PostImpl as p where p.topic.forum =
+ // :forumId order by p.createDate desc");
- public Date findLastPostDateForUser(User user)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("select max(p.createDate) from PostImpl as p where p.poster.userId = :userId");
- query.setString("userId", "" + user.getId().toString());
- Date lastPostDate = (Date)query.uniqueResult();
- return lastPostDate;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
+ session.createQuery("select p "
+ + "from PostImpl as p "
+ + "join fetch p.poster "
+ + "where p.createDate = ( "
+ + " select DISTINCT MAX(topic.lastPostDate) "
+ + " from TopicImpl as topic "
+ + " where topic.forum = :forumId "
+ + ") ");
+ query.setString("forumId", "" + forum.getId());
+ query.setFirstResult(0);
+ query.setMaxResults(1);
+ Post lastPost = (Post) query.uniqueResult();
+ return lastPost;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- public Post findLastPost(Forum forum)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
-
- // This is old query, considered as less efficient
- //session.createQuery("from PostImpl as p where p.topic.forum = :forumId order by p.createDate desc");
-
- session.createQuery("select p " +
- "from PostImpl as p " +
- "join fetch p.poster " +
- "where p.createDate = ( " +
- " select DISTINCT MAX(topic.lastPostDate) " +
- " from TopicImpl as topic " +
- " where topic.forum = :forumId " +
- ") " );
- query.setString("forumId", "" + forum.getId());
- query.setFirstResult(0);
- query.setMaxResults(1);
- Post lastPost = (Post)query.uniqueResult();
- return lastPost;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
+ public Post findFirstPost(Topic topic) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query =
+ // Old query considered as inefficient
+ // session.createQuery("from PostImpl as p where p.topic = :topicId
+ // order by p.createDate desc");
- public Post findFirstPost(Topic topic)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- // Old query considered as inefficient
- //session.createQuery("from PostImpl as p where p.topic = :topicId order by p.createDate desc");
-
- session.createQuery("select p " +
- "from PostImpl as p " +
- "join fetch p.poster " +
- "where p.topic = :topicId " +
- "AND p.createDate = :lastPostDate ");
- query.setDate("lastPostDate", topic.getLastPostDate());
- query.setString("topicId", "" + topic.getId());
- query.setFirstResult(0);
- query.setMaxResults(1);
- Post firstPost = (Post)query.uniqueResult();
- return firstPost;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
+ session.createQuery("select p "
+ + "from PostImpl as p "
+ + "join fetch p.poster "
+ + "where p.topic = :topicId "
+ + "AND p.createDate = :lastPostDate ");
+ query.setDate("lastPostDate", topic.getLastPostDate());
+ query.setString("topicId", "" + topic.getId());
+ query.setFirstResult(0);
+ query.setMaxResults(1);
+ Post firstPost = (Post) query.uniqueResult();
+ return firstPost;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- public Post findLastPost(Topic topic)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("from PostImpl as p where p.topic = :topicId order by p.createDate desc");
- query.setString("topicId", "" + topic.getId());
- query.setFirstResult(0);
- query.setMaxResults(1);
- Post lastPost = (Post)query.uniqueResult();
- return lastPost;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
-
- public Map findLastPostsOfTopics(Collection topics)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- //Query query =
- // Old query considered as inefficient
- //session.createQuery("from PostImpl as p where p.topic = :topicId order by p.createDate desc");
- session.createQuery("select topic.lastPostDate as maxDate , topic.id " +
- "from TopicImpl as topic " +
- "where topic.forum.id = :forumId ");
- Iterator it = topics.iterator();
- List lastPostDates = new ArrayList(topics.size());
- List dates = new LinkedList();
- while(it.hasNext()) {
- Topic tmpTopic = (Topic)it.next();
- dates.add(tmpTopic.getLastPostDate());
- lastPostDates.add(new Object[]{tmpTopic.getLastPostDate(),tmpTopic.getId()});
- }
-
- // if there are no createDates then we return an empty map
- if (dates.size()==0) {
- return new HashMap(0);
- }
-
- Query query = session.createQuery("select post.createDate, post " +
- "from PostImpl as post " +
- "join fetch post.poster " +
- "where post.createDate IN (:dates) " +
- "order by post.createDate ");
- query.setParameterList("dates",dates);
- List posts = query.list();
- Map forumPostMap = new HashMap(dates.size());
- Iterator iterator = lastPostDates.iterator();
- while (iterator.hasNext()) {
- Object[] dateTopic = (Object[])iterator.next();
- int index = Collections.binarySearch(posts,
- dateTopic,
- new Comparator() {
- public int compare(Object o1, Object o2) {
- Object[] datePostPair1 = (Object[])o1;
- Object[] datePostPair2 = (Object[])o2;
- Date postDate1 = (Date)datePostPair1[0];
- Date postDate2 = (Date)datePostPair2[0];
- return postDate1.compareTo(postDate2);
- }
- });
- if (index<0) {
- continue;
- }
- Object[] datePostPair = (Object[])posts.get(index);
- forumPostMap.put(dateTopic[1],datePostPair[1]);
- }
- return forumPostMap;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
+ public Post findLastPost(Topic topic) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from PostImpl as p where p.topic = :topicId order by p.createDate desc");
+ query.setString("topicId", "" + topic.getId());
+ query.setFirstResult(0);
+ query.setMaxResults(1);
+ Post lastPost = (Post) query.uniqueResult();
+ return lastPost;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- public Map findLastPostsOfForums()
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query =
- session.createQuery("select MAX(topic.lastPostDate) as maxDate , topic.forum.id " +
- "from TopicImpl as topic " +
- "group by topic.forum.id ");
- List createDates = query.list();
- Iterator it = createDates.iterator();
- List dates = new LinkedList();
- while(it.hasNext()) {
- dates.add(((Object[])it.next())[0]);
- }
-
- // if there are no posts in all forums then return empty map
- if (dates.size()==0) {
- return new HashMap(0);
- }
-
- query = session.createQuery("select post.createDate, post " +
- "from PostImpl as post " +
- "join fetch post.poster " +
- "where post.createDate IN (:dates) " +
- "order by post.createDate ");
- query.setParameterList("dates",dates);
- List posts = query.list();
- Map forumPostMap = new HashMap(createDates.size());
- Iterator iterator = createDates.iterator();
- while (iterator.hasNext()) {
- Object[] dateForum = (Object[])iterator.next();
- int index = Collections.binarySearch(posts,
- dateForum,
- new Comparator() {
- public int compare(Object o1, Object o2) {
- Object[] datePostPair1 = (Object[])o1;
- Object[] datePostPair2 = (Object[])o2;
- Date postDate1 = (Date)datePostPair1[0];
- Date postDate2 = (Date)datePostPair2[0];
- return postDate1.compareTo(postDate2);
- }
- });
- if (index<0) {
- continue;
- }
- Object[] datePostPair = (Object[])posts.get(index);
- forumPostMap.put(dateForum[1],datePostPair[1]);
- }
- return forumPostMap;
- }
- catch (HibernateException e)
- {
- e.printStackTrace();
- return null;
- }
- }
+ public Map findLastPostsOfTopics(Collection topics) throws ModuleException {
+ try {
+ Session session = getSession();
+ // Query query =
+ // Old query considered as inefficient
+ // session.createQuery("from PostImpl as p where p.topic = :topicId
+ // order by p.createDate desc");
+ session
+ .createQuery("select topic.lastPostDate as maxDate , topic.id "
+ + "from TopicImpl as topic "
+ + "where topic.forum.id = :forumId ");
+ Iterator it = topics.iterator();
+ List lastPostDates = new ArrayList(topics.size());
+ List dates = new LinkedList();
+ while (it.hasNext()) {
+ Topic tmpTopic = (Topic) it.next();
+ dates.add(tmpTopic.getLastPostDate());
+ lastPostDates.add(new Object[] { tmpTopic.getLastPostDate(),
+ tmpTopic.getId() });
+ }
- public List findForumWatchByUser(User user) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from ForumWatchImpl as f where f.poster.userId = :userId");
- query.setString("userId", user.getId().toString());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum watch";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findForumWatchedByUser(User user) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select f " +
- "from ForumImpl as f " +
- "where f.id IN ( "+
- " select fw.forum.id " +
- " from ForumWatchImpl fw " +
- " where fw.poster.userId = :userId )");
- query.setString("userId", user.getId().toString());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum watched";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findTopicWatchedByUser(User user) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select t " +
- "from TopicImpl as t " +
- "where t.id IN ( " +
- " select tw.topic.id " +
- " from TopicWatchImpl tw " +
- " where tw.poster.userId = :userId ) " +
- "order by t.lastPostDate desc ");
- query.setString("userId", user.getId().toString());
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topic watched";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public List findTopicWatchedByUser(User user,Date datePoint) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select t " +
- "from TopicImpl as t " +
- "where t.id IN ( " +
- " select tw.topic.id " +
- " from TopicWatchImpl tw " +
- " where tw.poster.userId = :userId ) " +
- "and (t.lastPostDate > :datePoint) " +
- "order by t.lastPostDate desc ");
- query.setString("userId", user.getId().toString());
- query.setTimestamp("datePoint", datePoint);
- return query.list();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topic watched";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- /**
- *
- * This method returns Map<Integer,TopicWatch> pairs where Integer
- * key is watched topic id.
- *
- * @param user
- * @return
- * @throws ModuleException
- */
- public Map findTopicWatches(User user) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select tw.topic.id , tw " +
- "from TopicWatchImpl tw " +
- "where tw.poster.userId = :userId ");
- query.setString("userId", user.getId().toString());
- List results = query.list();
- HashMap map = new HashMap(results.size());
- Iterator it = results.iterator();
- while (it.hasNext())
- {
- Object[] element = (Object[]) it.next();
- map.put(element[0], element[1]);
- }
- return map;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topic watches";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ // if there are no createDates then we return an empty map
+ if (dates.size() == 0) {
+ return new HashMap(0);
+ }
- public void createWatch(Poster poster, Forum forum, int mode) throws ModuleException
- {
- try
- {
- Session session = getSession();
+ Query query = session.createQuery("select post.createDate, post "
+ + "from PostImpl as post " + "join fetch post.poster "
+ + "where post.createDate IN (:dates) "
+ + "order by post.createDate ");
+ query.setParameterList("dates", dates);
+ List posts = query.list();
+ Map forumPostMap = new HashMap(dates.size());
+ Iterator iterator = lastPostDates.iterator();
+ while (iterator.hasNext()) {
+ Object[] dateTopic = (Object[]) iterator.next();
+ int index = Collections.binarySearch(posts, dateTopic,
+ new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Object[] datePostPair1 = (Object[]) o1;
+ Object[] datePostPair2 = (Object[]) o2;
+ Date postDate1 = (Date) datePostPair1[0];
+ Date postDate2 = (Date) datePostPair2[0];
+ return postDate1.compareTo(postDate2);
+ }
+ });
+ if (index < 0) {
+ continue;
+ }
+ Object[] datePostPair = (Object[]) posts.get(index);
+ forumPostMap.put(dateTopic[1], datePostPair[1]);
+ }
+ return forumPostMap;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- if (poster == null)
- {
- throw new ModuleException("poster must not be null");
- }
+ public Map findLastPostsOfForums() throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select MAX(topic.lastPostDate) as maxDate , topic.forum.id "
+ + "from TopicImpl as topic "
+ + "group by topic.forum.id ");
+ List createDates = query.list();
+ Iterator it = createDates.iterator();
+ List dates = new LinkedList();
+ while (it.hasNext()) {
+ dates.add(((Object[]) it.next())[0]);
+ }
- if (forum == null)
- {
- throw new ModuleException("forum must not be null");
- }
+ // if there are no posts in all forums then return empty map
+ if (dates.size() == 0) {
+ return new HashMap(0);
+ }
- session.save(poster);
-
- ForumWatch forumWatch = new ForumWatchImpl();
- forumWatch.setPoster(poster);
- forumWatch.setForum(forum);
- forumWatch.setMode(mode);
- session.save(forumWatch);
+ query = session.createQuery("select post.createDate, post "
+ + "from PostImpl as post " + "join fetch post.poster "
+ + "where post.createDate IN (:dates) "
+ + "order by post.createDate ");
+ query.setParameterList("dates", dates);
+ List posts = query.list();
+ Map forumPostMap = new HashMap(createDates.size());
+ Iterator iterator = createDates.iterator();
+ while (iterator.hasNext()) {
+ Object[] dateForum = (Object[]) iterator.next();
+ int index = Collections.binarySearch(posts, dateForum,
+ new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Object[] datePostPair1 = (Object[]) o1;
+ Object[] datePostPair2 = (Object[]) o2;
+ Date postDate1 = (Date) datePostPair1[0];
+ Date postDate2 = (Date) datePostPair2[0];
+ return postDate1.compareTo(postDate2);
+ }
+ });
+ if (index < 0) {
+ continue;
+ }
+ Object[] datePostPair = (Object[]) posts.get(index);
+ forumPostMap.put(dateForum[1], datePostPair[1]);
+ }
+ return forumPostMap;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create forum watch";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public List findForumWatchByUser(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from ForumWatchImpl as f where f.poster.userId = :userId");
+ query.setString("userId", user.getId().toString());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find forum watch";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public void removeWatch(Watch watch) throws ModuleException
- {
- Session session = getSession();
- try
- {
- session.delete(watch);
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot delete watch";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public List findForumWatchedByUser(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select f "
+ + "from ForumImpl as f " + "where f.id IN ( "
+ + " select fw.forum.id " + " from ForumWatchImpl fw "
+ + " where fw.poster.userId = :userId )");
+ query.setString("userId", user.getId().toString());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find forum watched";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public ForumWatch findForumWatchById(Integer forumWatchId)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from ForumWatchImpl as f where f.id = :forumWatchId");
- query.setString("forumWatchId",
- forumWatchId.toString());
- return (ForumWatch)query.uniqueResult();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum watch";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- /**
- *
- * This method returns Map<Integer,ForumWatch> pairs where Integer
- * key is watched forum id.
- *
- * @param user
- * @return
- * @throws ModuleException
- */
- public Map findForumWatches(User user) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("select fw.forum.id , fw " +
- "from ForumWatchImpl fw " +
- "where fw.poster.userId = :userId ");
- query.setString("userId", user.getId().toString());
- List results = query.list();
- HashMap map = new HashMap(results.size());
- Iterator it = results.iterator();
- while (it.hasNext())
- {
- Object[] element = (Object[]) it.next();
- map.put(element[0], element[1]);
- }
- return map;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum watches";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public ForumWatch findForumWatchByUserAndForum(User user,int forumId) throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery(" from ForumWatchImpl as fw " +
- " where fw.poster.userId = :userId " +
- " and fw.forum.id= :forumId ");
- query.setString("userId", user.getId().toString());
- query.setInteger("forumId", forumId );
- Object obj = query.uniqueResult();
- if (obj==null) {
- return null;
- } else {
- return (ForumWatch)obj;
- }
- }
- catch (HibernateException e)
- {
- String message = "Cannot find forum watch";
- log.error(message, e);
- 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 topic watch";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
+ public List findTopicWatchedByUser(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select t "
+ + "from TopicImpl as t " + "where t.id IN ( "
+ + " select tw.topic.id " + " from TopicWatchImpl tw "
+ + " where tw.poster.userId = :userId ) "
+ + "order by t.lastPostDate desc ");
+ query.setString("userId", user.getId().toString());
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topic watched";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- public void createWatch(Poster poster, Topic topic,int mode)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
+ public List findTopicWatchedByUser(User user, Date datePoint)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select t "
+ + "from TopicImpl as t " + "where t.id IN ( "
+ + " select tw.topic.id " + " from TopicWatchImpl tw "
+ + " where tw.poster.userId = :userId ) "
+ + "and (t.lastPostDate > :datePoint) "
+ + "order by t.lastPostDate desc ");
+ query.setString("userId", user.getId().toString());
+ query.setTimestamp("datePoint", datePoint);
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find topic watched";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- if (poster == null)
- {
- throw new ModuleException("poster must not be null");
- }
+ /**
+ *
+ * This method returns Map<Integer,TopicWatch> pairs where Integer key is
+ * watched topic id.
+ *
+ * @param user
+ * @return
+ * @throws ModuleException
+ */
+ public Map findTopicWatches(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select tw.topic.id , tw "
+ + "from TopicWatchImpl tw "
+ + "where tw.poster.userId = :userId ");
+ query.setString("userId", user.getId().toString());
+ List results = query.list();
+ HashMap map = new HashMap(results.size());
+ Iterator it = results.iterator();
+ while (it.hasNext()) {
+ Object[] element = (Object[]) it.next();
+ map.put(element[0], element[1]);
+ }
+ return map;
+ } catch (HibernateException e) {
+ String message = "Cannot find topic watches";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
- if (topic == null)
- {
- throw new ModuleException("topic must not be null");
- }
+ public void createWatch(Poster poster, Forum forum, int mode)
+ throws ModuleException {
+ try {
+ Session session = getSession();
- session.save(poster);
-
- TopicWatch topicWatch = new TopicWatchImpl();
- topicWatch.setPoster(poster);
- topicWatch.setTopic(topic);
- topicWatch.setMode(mode);
- session.save(topicWatch);
- }
- catch (HibernateException e)
- {
- String errorMessage = "Cannot create topic watch";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ if (poster == null) {
+ throw new ModuleException("poster must not be null");
+ }
- public TopicWatch findTopicWatchById(Integer topicWatchId)
- throws ModuleException
- {
- try
- {
- Session session = getSession();
- Query query = session.createQuery("from TopicWatchImpl as f where f.id = :topicWatchId");
- query.setString("topicWatchId",
- topicWatchId.toString());
- return (TopicWatch)query.uniqueResult();
- }
- catch (HibernateException e)
- {
- String message = "Cannot find topic watch";
- log.error(message, e);
- throw new ModuleException(message, e);
- }
- }
-
- public void processNotifications (Integer postId, int watchType , String postUrl , String replyUrl ) {
- notificationEngine.schedule(postId, watchType, postUrl , replyUrl );
- }
-
- public UserProfileModule getUserProfileModule() {
- return this.userProfileModule;
- }
-
- protected Session getSession () {
- return factory.getCurrentSession();
- }
+ if (forum == null) {
+ throw new ModuleException("forum must not be null");
+ }
+
+ session.save(poster);
+
+ ForumWatch forumWatch = new ForumWatchImpl();
+ forumWatch.setPoster(poster);
+ forumWatch.setForum(forum);
+ forumWatch.setMode(mode);
+ session.save(forumWatch);
+
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create forum watch";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
+
+ public void removeWatch(Watch watch) throws ModuleException {
+ Session session = getSession();
+ try {
+ session.delete(watch);
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot delete watch";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
+
+ public ForumWatch findForumWatchById(Integer forumWatchId)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from ForumWatchImpl as f where f.id = :forumWatchId");
+ query.setString("forumWatchId", forumWatchId.toString());
+ return (ForumWatch) query.uniqueResult();
+ } catch (HibernateException e) {
+ String message = "Cannot find forum watch";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ /**
+ *
+ * This method returns Map<Integer,ForumWatch> pairs where Integer key is
+ * watched forum id.
+ *
+ * @param user
+ * @return
+ * @throws ModuleException
+ */
+ public Map findForumWatches(User user) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery("select fw.forum.id , fw "
+ + "from ForumWatchImpl fw "
+ + "where fw.poster.userId = :userId ");
+ query.setString("userId", user.getId().toString());
+ List results = query.list();
+ HashMap map = new HashMap(results.size());
+ Iterator it = results.iterator();
+ while (it.hasNext()) {
+ Object[] element = (Object[]) it.next();
+ map.put(element[0], element[1]);
+ }
+ return map;
+ } catch (HibernateException e) {
+ String message = "Cannot find forum watches";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public ForumWatch findForumWatchByUserAndForum(User user, int forumId)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session.createQuery(" from ForumWatchImpl as fw "
+ + " where fw.poster.userId = :userId "
+ + " and fw.forum.id= :forumId ");
+ query.setString("userId", user.getId().toString());
+ query.setInteger("forumId", forumId);
+ Object obj = query.uniqueResult();
+ if (obj == null) {
+ return null;
+ } else {
+ return (ForumWatch) obj;
+ }
+ } catch (HibernateException e) {
+ String message = "Cannot find forum watch";
+ log.error(message, e);
+ 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 topic watch";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public void createWatch(Poster poster, Topic topic, int mode)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+
+ if (poster == null) {
+ throw new ModuleException("poster must not be null");
+ }
+
+ if (topic == null) {
+ throw new ModuleException("topic must not be null");
+ }
+
+ session.save(poster);
+
+ TopicWatch topicWatch = new TopicWatchImpl();
+ topicWatch.setPoster(poster);
+ topicWatch.setTopic(topic);
+ topicWatch.setMode(mode);
+ session.save(topicWatch);
+ } catch (HibernateException e) {
+ String errorMessage = "Cannot create topic watch";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
+
+ public TopicWatch findTopicWatchById(Integer topicWatchId)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("from TopicWatchImpl as f where f.id = :topicWatchId");
+ query.setString("topicWatchId", topicWatchId.toString());
+ return (TopicWatch) query.uniqueResult();
+ } catch (HibernateException e) {
+ String message = "Cannot find topic watch";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public void processNotifications(Integer postId, int watchType,
+ String postUrl, String replyUrl) {
+ notificationEngine.schedule(postId, watchType, postUrl, replyUrl);
+ }
+
+ public UserProfileModule getUserProfileModule() {
+ return this.userProfileModule;
+ }
+
+ protected Session getSession() {
+ return factory.getCurrentSession();
+ }
+
+ private List findPostsFromForum(Forum forum, int limit, String order)
+ throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select p from TopicImpl as t join t.posts as p where t.forum.id = :forumId order by p.createDate "
+ + order);
+
+ query.setString("forumId", forum.getId().toString());
+
+ query.setFirstResult(0);
+
+ if (limit != 0) {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public List findPostsFromForumAsc(Forum forum, int limit)
+ throws ModuleException {
+ return findPostsFromForum(forum, limit, "asc");
+ }
+
+ public List findPostsFromForumDesc(Forum forum, int limit)
+ throws ModuleException {
+ return findPostsFromForum(forum, limit, "desc");
+ }
+
+ private List findPostsFromCategory(Category category, int limit,
+ String order) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select p from ForumImpl as f join f.topics as t join t.posts as p where f.category.id = :categoryId order by p.createDate "
+ + order);
+
+ query.setString("categoryId", category.getId().toString());
+
+ query.setFirstResult(0);
+
+ if (limit != 0) {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public List findPostsFromCategoryAsc(Category category, int limit)
+ throws ModuleException {
+ return findPostsFromCategory(category, limit, "asc");
+ }
+
+ public List findPostsFromCategoryDesc(Category category, int limit)
+ throws ModuleException {
+ return findPostsFromCategory(category, limit, "desc");
+ }
+
+ private List findPosts(int limit, String order) throws ModuleException {
+ try {
+ Session session = getSession();
+ Query query = session
+ .createQuery("select p from PostImpl as p order by p.createDate "
+ + order);
+
+ query.setFirstResult(0);
+
+ if (limit != 0) {
+ query.setMaxResults(limit);
+ }
+ return query.list();
+ } catch (HibernateException e) {
+ String message = "Cannot find posts";
+ log.error(message, e);
+ throw new ModuleException(message, e);
+ }
+ }
+
+ public List findPostsAsc(int limit) throws ModuleException {
+ return findPosts(limit, "asc");
+ }
+
+ public List findPostsDesc(int limit) throws ModuleException {
+ return findPosts(limit, "desc");
+ }
}
\ No newline at end of file
Modified: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2007-06-27 11:06:19 UTC (rev 12889)
@@ -68,673 +68,640 @@
* @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
*
*/
-public class PortalUtil
-{
- private static CLLoader loader = new CLLoader("template");
+public class PortalUtil {
+ private static CLLoader loader = new CLLoader("template");
- private static Logger log = Logger.getLogger(PortalUtil.class);
-
- private static SimpleDateFormat sdfForLastLoginDate;
+ private static Logger log = Logger.getLogger(PortalUtil.class);
- private static User user = new User()
- {
- public Object getId()
- {
- return null;
- }
+ private static SimpleDateFormat sdfForLastLoginDate;
- public void updatePassword(String string)
- {
- }
+ private static User user = new User() {
+ public Object getId() {
+ return null;
+ }
- public boolean validatePassword(String string)
- {
- return false;
- }
+ public void updatePassword(String string) {
+ }
- public String getUserName()
- {
- return null;
- }
- };
+ public boolean validatePassword(String string) {
+ return false;
+ }
- private static User userNA = new User()
- {
- {
- this.id = new Long(-1);
- this.userName = "N/A";
- }
-
- protected Object id;
-
- protected String userName;
+ public String getUserName() {
+ return null;
+ }
+ };
- public Object getId() {
- return id;
- }
+ private static User userNA = new User() {
+ {
+ this.id = new Long(-1);
+ this.userName = "N/A";
+ }
- public String getUserName() {
- return userName;
- }
+ protected Object id;
- public void updatePassword(String password) {
- }
+ protected String userName;
- public boolean validatePassword(String password) {
- return false;
- }
- };
-
- private final static UserProfileModule upm;
+ public Object getId() {
+ return id;
+ }
- static
- {
- UserProfileModule temporary = null;
- try
- {
- temporary = (UserProfileModule) new InitialContext()
- .lookup("java:portal/UserProfileModule");
- } catch (NamingException e)
- {
- JSFUtil.handleException(e);
- } finally
- {
- upm = temporary;
- }
-
- sdfForLastLoginDate = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH);
- }
+ public String getUserName() {
+ return userName;
+ }
- /**
- *
- *
- */
- public static boolean isRunningInPortal()
- {
- boolean isRunningInPortal = false;
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (o instanceof PortletRequest)
- {
- isRunningInPortal = true;
- }
- return isRunningInPortal;
- }
+ public void updatePassword(String password) {
+ }
- /**
- *
- * @author sshah
- *
- */
- public static String outputLink(String outputLink, boolean isAction)
- {
- try
- {
- String url = null;
+ public boolean validatePassword(String password) {
+ return false;
+ }
+ };
- Object response = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ private final static UserProfileModule upm;
- if (!outputLink.startsWith("/"))
- {
- outputLink = "/" + outputLink;
- }
+ static {
+ UserProfileModule temporary = null;
+ try {
+ temporary = (UserProfileModule) new InitialContext()
+ .lookup("java:portal/UserProfileModule");
+ } catch (NamingException e) {
+ JSFUtil.handleException(e);
+ } finally {
+ upm = temporary;
+ }
- if (response instanceof RenderResponse)
- {
- RenderResponse renderResponse = (RenderResponse) response;
+ sdfForLastLoginDate = new SimpleDateFormat(
+ "EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
+ }
- PortletURL portletURL = null;
+ /**
+ *
+ *
+ */
+ public static boolean isRunningInPortal() {
+ boolean isRunningInPortal = false;
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (o instanceof PortletRequest) {
+ isRunningInPortal = true;
+ }
+ return isRunningInPortal;
+ }
- if (isAction)
- {
- portletURL = renderResponse.createActionURL();
- } else
- {
- portletURL = renderResponse.createRenderURL();
- }
+ /**
+ *
+ * @author sshah
+ *
+ */
+ public static String outputLink(String outputLink, boolean isAction) {
+ try {
+ String url = null;
- String jsfUrl = portletURL.toString();
- jsfUrl += "&"
- + ForumsJSFPortlet.VIEW
- + "="
- + URLEncoder.encode(ForumsJSFPortlet
- .getIdForName(outputLink), "UTF-8");
+ Object response = FacesContext.getCurrentInstance()
+ .getExternalContext().getResponse();
- url = jsfUrl;
- } else
- {
- String contextPath = JSFUtil.getContextPath();
- url = contextPath + outputLink;
- }
+ if (!outputLink.startsWith("/")) {
+ outputLink = "/" + outputLink;
+ }
- return url;
- } catch (Exception e)
- {
- log.error(PortalUtil.class.getName(), e);
- return null;
- }
- }
+ if (response instanceof RenderResponse) {
+ RenderResponse renderResponse = (RenderResponse) response;
- public static String postPermlink(String postId)
- {
+ PortletURL portletURL = null;
- Object response = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ if (isAction) {
+ portletURL = renderResponse.createActionURL();
+ } else {
+ portletURL = renderResponse.createRenderURL();
+ }
- String url = "";
+ String jsfUrl = portletURL.toString();
+ jsfUrl += "&"
+ + ForumsJSFPortlet.VIEW
+ + "="
+ + URLEncoder.encode(ForumsJSFPortlet
+ .getIdForName(outputLink), "UTF-8");
- if (response instanceof RenderResponse)
- {
- RenderResponse renderResponse = (RenderResponse) response;
- PortletURL portletURL = renderResponse.createActionURL();
- url = portletURL.toString();
- if (url.indexOf("/auth")!=-1)
- {
- url = url.replaceFirst("/auth", "");
- }
- url += "&" + Constants.p_viewId + "=t&" + Constants.p_postId + "="
- + postId + "#" + postId;
- } else
- {
- url = JSFUtil.getContextPath();
- ApplicationFactory factory = (ApplicationFactory) FactoryFinder
- .getFactory(FactoryFinder.APPLICATION_FACTORY);
- Application application = factory.getApplication();
- EmptyController binding = (EmptyController) application
- .getVariableResolver().resolveVariable(
- FacesContext.getCurrentInstance(), "shared");
- url += binding.getLinks().get("topic").toString();
- url += "?" + Constants.p_postId + "=" + postId + "#" + postId;
- }
+ url = jsfUrl;
+ } else {
+ String contextPath = JSFUtil.getContextPath();
+ url = contextPath + outputLink;
+ }
- return url;
- }
+ return url;
+ } catch (Exception e) {
+ log.error(PortalUtil.class.getName(), e);
+ return null;
+ }
+ }
- /**
- *
- *
- */
- public static void executeNotifications()
- {
+ public static String globalPermlink() {
+ return permlink("category");
+ }
- Object responseObj = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ public static String categoryPermlink(String categoryId) {
+ return permlink("category") + Constants.p_categoryId + "=" + categoryId;
+ }
- Object requestObj = FacesContext.getCurrentInstance()
- .getExternalContext().getRequest();
+ public static String forumPermlink(String forumId) {
+ return permlink("forum") + Constants.p_forumId + "=" + forumId;
+ }
- // Initializing url values
- String postUrl = "";
- String replyUrl = "";
+ public static String postPermlink(String postId) {
+ return permlink("topic") + Constants.p_postId + "=" + postId + "#"
+ + postId;
+ }
- if (requestObj instanceof RenderRequest)
- {
+ public static String topicPermlink(String topicId) {
+ return permlink("topic") + Constants.p_topicId + "=" + topicId;
+ }
- PortletRequest request = (PortletRequest) requestObj;
+ private static String permlink(String type) {
- // Checking whether there is watched post id in RenderParameters and
- // scheduling notification e-mails.
- String watchedPostId = request
- .getParameter(Constants.p_notified_post_id);
- String watchedType = request
- .getParameter(Constants.p_notified_watch_type);
+ Object response = FacesContext.getCurrentInstance()
+ .getExternalContext().getResponse();
- if (watchedPostId != null && watchedPostId.trim().length() > 0
- && watchedType != null && watchedType.trim().length() > 0)
- {
+ String url = "";
- // Creating permament link to post
- PortletURL portletURL = ((RenderResponse) responseObj)
- .createActionURL();
- postUrl = portletURL.toString();
- if (postUrl.indexOf("/auth")!=-1)
- {
- postUrl = postUrl.replaceFirst("/auth", "");
- }
- postUrl += "&" + Constants.p_viewId + "=t&"
- + Constants.p_postId + "=" + watchedPostId + "#"
- + watchedPostId;
+ if (response instanceof RenderResponse) {
+ RenderResponse renderResponse = (RenderResponse) response;
+ PortletURL portletURL = renderResponse.createActionURL();
+ url = portletURL.toString();
+ if (url.indexOf("/auth") != -1) {
+ url = url.replaceFirst("/auth", "");
+ }
+ url += "&" + Constants.p_viewId + "=" + type.charAt(0) + "&";
+ } else {
+ url = JSFUtil.getContextPath();
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application application = factory.getApplication();
+ EmptyController binding = (EmptyController) application
+ .getVariableResolver().resolveVariable(
+ FacesContext.getCurrentInstance(), "shared");
+ url += binding.getLinks().get(type).toString();
+ url += "?";
+ }
- portletURL = ((RenderResponse) responseObj).createRenderURL();
- replyUrl = portletURL.toString();
- replyUrl += "&" + Constants.p_viewId + "=z&"
- + Constants.p_postId + "=" + watchedPostId;
+ return url;
+ }
- // Generate hostUrl to servlet
- String hostURL = ((request.isSecure()) ? "https" : "http")
- + "://"
- + request.getServerName()
- + ((request.getServerPort() == 80) ? "" : ":"
- + request.getServerPort());
+ /**
+ * Creates feed link.
+ *
+ * @param type
+ * RSS/Atom. See FeedConstants
+ * @param what
+ * Kind of the link. See available kinds in FeedConstants
+ * @param id
+ * Id - for kind FeedCostants.GLOBAL is ignored
+ * @return String with proper address
+ */
+ public static String createFeedLink(String type, String what, Integer id) {
+ Object rreq = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
- postUrl = hostURL + postUrl;
- replyUrl = hostURL + replyUrl;
+ if (rreq instanceof RenderRequest) {
+ RenderRequest req = (RenderRequest) rreq;
- Integer postId = new Integer(watchedPostId);
- int type = Integer.parseInt(watchedType);
+ return req.getContextPath() + "/feeds/" + type + "/" + what + "/"
+ + id.toString();
+ }
- try
- {
- BaseController.getForumsModule().processNotifications(
- postId, type, postUrl, replyUrl);
- } catch (Exception e)
- {
- JSFUtil.handleException(e);
- }
- }
- }
- }
+ return null;
+ }
- /**
- *
- * @param preferenceKey
- * @return
- */
- public static String getPreference(String preferenceKey)
- {
- String preference = null;
+ /**
+ *
+ *
+ */
+ public static void executeNotifications() {
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (!JSFUtil.isAnonymous() && o instanceof PortletRequest)
- {
- PortletRequest request = (PortletRequest) o;
- PortletPreferences pp = request.getPreferences();
- preference = pp.getValue(preferenceKey, "");
- }
+ Object responseObj = FacesContext.getCurrentInstance()
+ .getExternalContext().getResponse();
- return preference;
- }
+ Object requestObj = FacesContext.getCurrentInstance()
+ .getExternalContext().getRequest();
- /**
- *
- *
- */
- public static void setPreferences(Map preferences) throws Exception
- {
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (!JSFUtil.isAnonymous() && o instanceof PortletRequest)
- {
- PortletRequest request = (PortletRequest) o;
- PortletPreferences pp = request.getPreferences();
- for (Iterator itr = preferences.keySet().iterator(); itr.hasNext();)
- {
- String preferenceKey = (String) itr.next();
- String value = (String) preferences.get(preferenceKey);
- if (!pp.isReadOnly(preferenceKey))
- {
- pp.setValue(preferenceKey, value);
- }
- }
- pp.store();
- }
- }
+ // Initializing url values
+ String postUrl = "";
+ String replyUrl = "";
- /**
- * Get a <code>SimpleDateFormat</code> object from the session. The object
- * is stored in the session because it is expensive to create and we want to
- * reuse it as much as we can. Also it is configured with the date format
- * taken from the preference of the user if it exists.
- *
- * @param req
- * the request that maybe contains the format object
- * @return the format object
- */
- public static SimpleDateFormat getSDF()
- {
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (o instanceof PortletRequest)
- {
- PortletRequest req = (PortletRequest) FacesContext
- .getCurrentInstance().getExternalContext().getRequest();
+ if (requestObj instanceof RenderRequest) {
- // Get the pattern
- String pattern = req.getPreferences().getValue("dateformat",
- ForumsConstants.DEFAULT_DATE_PATTERN);
+ PortletRequest request = (PortletRequest) requestObj;
- // Get the simple date format if it exists
- SimpleDateFormat sdf = (SimpleDateFormat) FacesContext
- .getCurrentInstance().getExternalContext().getSessionMap()
- .get("SDF");
+ // Checking whether there is watched post id in RenderParameters and
+ // scheduling notification e-mails.
+ String watchedPostId = request
+ .getParameter(Constants.p_notified_post_id);
+ String watchedType = request
+ .getParameter(Constants.p_notified_watch_type);
- // Do we have it ?
- if (sdf == null)
- {
- // Create a new one
- sdf = new SimpleDateFormat(pattern, req.getLocale());
+ if (watchedPostId != null && watchedPostId.trim().length() > 0
+ && watchedType != null && watchedType.trim().length() > 0) {
- // Put it in the session
- FacesContext.getCurrentInstance().getExternalContext()
- .getSessionMap().put("SDF", sdf);
- } else
- {
- // Check if config has not changed
- if (!sdf.toPattern().equals(pattern))
- {
- sdf.applyPattern(pattern);
- }
- }
- return sdf;
- } else
- {
- SimpleDateFormat sdf = new SimpleDateFormat();
- sdf.applyPattern(ForumsConstants.DEFAULT_DATE_PATTERN);
- return sdf;
- }
- }
+ // Creating permament link to post
+ PortletURL portletURL = ((RenderResponse) responseObj)
+ .createActionURL();
+ postUrl = portletURL.toString();
+ if (postUrl.indexOf("/auth") != -1) {
+ postUrl = postUrl.replaceFirst("/auth", "");
+ }
+ postUrl += "&" + Constants.p_viewId + "=t&"
+ + Constants.p_postId + "=" + watchedPostId + "#"
+ + watchedPostId;
- /**
- *
- * @return
- * @throws Exception
- */
- public static User getUser() throws Exception
- {
- User user = null;
- String userName = FacesContext.getCurrentInstance()
- .getExternalContext().getRemoteUser();
- if (userName != null && userName.trim().length() > 0)
- {
- UserModule userModule = (UserModule) new InitialContext()
- .lookup(ModuleConstants.USERMODULE_JNDINAME);
- user = userModule.findUserByUserName(userName);
- }
- return user;
- }
+ portletURL = ((RenderResponse) responseObj).createRenderURL();
+ replyUrl = portletURL.toString();
+ replyUrl += "&" + Constants.p_viewId + "=z&"
+ + Constants.p_postId + "=" + watchedPostId;
- /**
- *
- * @return
- * @throws Exception
- */
- public static String userProperty(User user, String propertyName)
- throws Exception
- {
- String property = null;
- String valueStr = null;
- try
- {
- property = user.getClass().getField(propertyName).get(user)
- .toString();
- Object value = upm.getProperty(user, property);
- if (value != null && value.toString().trim().length() != 0)
- {
- valueStr = value.toString();
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- return valueStr;
- }
-
- public static Date getUserLastLoginDate()
- {
- try
- {
- User user = PortalUtil.getUser();
- if (user == null)
- {
- return null;
- }
- Object property = upm.getProperty(user, User.INFO_USER_LAST_LOGIN_DATE);
- if (property!=null)
- {
- Date date = sdfForLastLoginDate.parse(property.toString());
- return date;
- }
- } catch (Exception e)
- {
- JSFUtil.handleException(e);
- }
- return null;
- }
+ // Generate hostUrl to servlet
+ String hostURL = ((request.isSecure()) ? "https" : "http")
+ + "://"
+ + request.getServerName()
+ + ((request.getServerPort() == 80) ? "" : ":"
+ + request.getServerPort());
- /**
- *
- * @return
- * @throws Exception
- */
- public static Poster getPoster() throws Exception
- {
- Poster poster = null;
+ postUrl = hostURL + postUrl;
+ replyUrl = hostURL + replyUrl;
- if (!JSFUtil.isAnonymous())
- {
- User user = PortalUtil.getUser();
+ Integer postId = new Integer(watchedPostId);
+ int type = Integer.parseInt(watchedType);
- Long userId = (Long) user.getId();
- poster = BaseController.getForumsModule().findPosterByUserId(
- String.valueOf(userId));
+ try {
+ BaseController.getForumsModule().processNotifications(
+ postId, type, postUrl, replyUrl);
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ }
+ }
+ }
- if (poster == null)
- {
- poster = new PosterImpl(userId.toString());
- }
- }
+ /**
+ *
+ * @param preferenceKey
+ * @return
+ */
+ public static String getPreference(String preferenceKey) {
+ String preference = null;
- return poster;
- }
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (!JSFUtil.isAnonymous() && o instanceof PortletRequest) {
+ PortletRequest request = (PortletRequest) o;
+ PortletPreferences pp = request.getPreferences();
+ preference = pp.getValue(preferenceKey, "");
+ }
- /**
- * Method used for parsing bbcode and return properly formated text of
- * message.
- *
- * @return
- */
- public static String formatMessage(String text, boolean allowHTML)
- {
+ return preference;
+ }
- try
- {
- Object req = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
+ /**
+ *
+ *
+ */
+ public static void setPreferences(Map preferences) throws Exception {
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (!JSFUtil.isAnonymous() && o instanceof PortletRequest) {
+ PortletRequest request = (PortletRequest) o;
+ PortletPreferences pp = request.getPreferences();
+ for (Iterator itr = preferences.keySet().iterator(); itr.hasNext();) {
+ String preferenceKey = (String) itr.next();
+ String value = (String) preferences.get(preferenceKey);
+ if (!pp.isReadOnly(preferenceKey)) {
+ pp.setValue(preferenceKey, value);
+ }
+ }
+ pp.store();
+ }
+ }
- if (allowHTML)
- {
- getToHTMLRenderer(req).getConfig().setFilterMode(
- ToHTMLConfig.FILTER_MODE_ALWAYS_PRINT);
- getToHTMLRenderer(req).getConfig().setOuputMode(
- ToHTMLConfig.OUTPUT_MODE_REMOVE);
- getToHTMLRenderer(req).getConfig().setMaxTextWidth(
- Integer.MAX_VALUE);
- } else
- {
- getToHTMLRenderer(req).getConfig().setFilterMode(
- ToHTMLConfig.FILTER_MODE_NEVER_PRINT);
- getToHTMLRenderer(req).getConfig().setOuputMode(
- ToHTMLConfig.OUTPUT_MODE_REMOVE);
- getToHTMLRenderer(req).getConfig().setMaxTextWidth(
- Integer.MAX_VALUE);
- }
- return formatTitle(req, text);
- } catch (Exception e)
- {
- // Now if something goes wrong it just returns message with bbcode.
- return text;
- }
+ /**
+ * Get a <code>SimpleDateFormat</code> object from the session. The object
+ * is stored in the session because it is expensive to create and we want to
+ * reuse it as much as we can. Also it is configured with the date format
+ * taken from the preference of the user if it exists.
+ *
+ * @param req
+ * the request that maybe contains the format object
+ * @return the format object
+ */
+ public static SimpleDateFormat getSDF() {
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (o instanceof PortletRequest) {
+ PortletRequest req = (PortletRequest) FacesContext
+ .getCurrentInstance().getExternalContext().getRequest();
- }
+ // Get the pattern
+ String pattern = req.getPreferences().getValue("dateformat",
+ ForumsConstants.DEFAULT_DATE_PATTERN);
- /**
- *
- * @param text
- * @return
- */
- public static String formatTitle(Object req, String text)
- {
+ // Get the simple date format if it exists
+ SimpleDateFormat sdf = (SimpleDateFormat) FacesContext
+ .getCurrentInstance().getExternalContext().getSessionMap()
+ .get("SDF");
- StringWriter stringWriter = new StringWriter();
- getToHTMLRenderer(req).setWriter(stringWriter);
- getToHTMLRenderer(req).render(text.toCharArray(), 0, text.length());
- getToHTMLRenderer(req).getConfig().setMaxTextWidth(Integer.MAX_VALUE);
- return stringWriter.toString();
+ // Do we have it ?
+ if (sdf == null) {
+ // Create a new one
+ sdf = new SimpleDateFormat(pattern, req.getLocale());
- }
+ // Put it in the session
+ FacesContext.getCurrentInstance().getExternalContext()
+ .getSessionMap().put("SDF", sdf);
+ } else {
+ // Check if config has not changed
+ if (!sdf.toPattern().equals(pattern)) {
+ sdf.applyPattern(pattern);
+ }
+ }
+ return sdf;
+ } else {
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ sdf.applyPattern(ForumsConstants.DEFAULT_DATE_PATTERN);
+ return sdf;
+ }
+ }
- /**
- *
- * @return
- */
- private static ToHTMLRenderer getToHTMLRenderer(Object req)
- {
- ToHTMLRenderer renderer = null;
- PortletRequest porReq = null;
- HttpServletRequest serReq = null;
- if (req instanceof PortletRequest)
- {
- porReq = (PortletRequest) req;
- renderer = (ToHTMLRenderer) porReq.getPortletSession()
- .getAttribute("RENDERER");
- } else
- {
- serReq = (HttpServletRequest) req;
- // TODO: GETTING RENDERER FROM APPLICATION SCOPE ATTRIBUTE
- }
- if (renderer == null)
- {
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ public static User getUser() throws Exception {
+ User user = null;
+ String userName = FacesContext.getCurrentInstance()
+ .getExternalContext().getRemoteUser();
+ if (userName != null && userName.trim().length() > 0) {
+ UserModule userModule = (UserModule) new InitialContext()
+ .lookup(ModuleConstants.USERMODULE_JNDINAME);
+ user = userModule.findUserByUserName(userName);
+ }
+ return user;
+ }
- // Getting ResourceBundle with current Locale
- FacesContext ctx = FacesContext.getCurrentInstance();
- UIViewRoot uiRoot = ctx.getViewRoot();
- Locale locale = uiRoot.getLocale();
- ClassLoader ldr = Thread.currentThread().getContextClassLoader();
- ResourceBundle bundle = ResourceBundle.getBundle("ResourceJSF",
- locale, ldr);
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ public static String userProperty(User user, String propertyName)
+ throws Exception {
+ String property = null;
+ String valueStr = null;
+ try {
+ property = user.getClass().getField(propertyName).get(user)
+ .toString();
+ Object value = upm.getProperty(user, property);
+ if (value != null && value.toString().trim().length() != 0) {
+ valueStr = value.toString();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ return valueStr;
+ }
- // Create the HTMLRenderer for BBCode
- ToHTMLConfig config = new ToHTMLConfig();
- config.setLoader(loader);
- renderer = new ToHTMLRenderer(config, bundle);
- if (porReq != null)
- {
- porReq.getPortletSession().setAttribute("RENDERER", renderer);
- } else if (serReq != null)
- {
- // TODO: SETTING RENDERER IN APPLICATION SCOPE ATTRIBUTE
- }
- }
- return renderer;
- }
+ public static Date getUserLastLoginDate() {
+ try {
+ User user = PortalUtil.getUser();
+ if (user == null) {
+ return null;
+ }
+ Object property = upm.getProperty(user,
+ User.INFO_USER_LAST_LOGIN_DATE);
+ if (property != null) {
+ Date date = sdfForLastLoginDate.parse(property.toString());
+ return date;
+ }
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return null;
+ }
- /**
- *
- * @return
- */
- public static Poll createPoll()
- {
- Poll poll = new PollImpl();
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ public static Poster getPoster() throws Exception {
+ Poster poster = null;
- poll.setTitle("");
- poll.setCreationDate(new Date());
+ if (!JSFUtil.isAnonymous()) {
+ User user = PortalUtil.getUser();
- return poll;
- }
+ Long userId = (Long) user.getId();
+ poster = BaseController.getForumsModule().findPosterByUserId(
+ String.valueOf(userId));
- /**
- *
- * @return
- */
- public static PollOption createPollOption()
- {
- PollOption pollOption = new PollOptionImpl();
- return pollOption;
- }
+ if (poster == null) {
+ poster = new PosterImpl(userId.toString());
+ }
+ }
- /**
- *
- * @author sshah
- *
- *
- */
- public static Message createMessage()
- {
- Message message = new MessageImpl();
- return message;
- }
+ return poster;
+ }
- /**
- *
- *
- */
- public static float getVotePercent(Poll poll, PollOption option)
- {
- float votePercent = 0;
+ /**
+ * Method used for parsing bbcode and return properly formated text of
+ * message.
+ *
+ * @return
+ */
+ public static String formatMessage(String text, boolean allowHTML) {
- float votesSum = poll.getVotesSum();
- if (votesSum > 0)
- {
- votePercent = (option.getVotes() / votesSum);
- }
+ try {
+ Object req = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
- return votePercent;
- }
+ if (allowHTML) {
+ getToHTMLRenderer(req).getConfig().setFilterMode(
+ ToHTMLConfig.FILTER_MODE_ALWAYS_PRINT);
+ getToHTMLRenderer(req).getConfig().setOuputMode(
+ ToHTMLConfig.OUTPUT_MODE_REMOVE);
+ getToHTMLRenderer(req).getConfig().setMaxTextWidth(
+ Integer.MAX_VALUE);
+ } else {
+ getToHTMLRenderer(req).getConfig().setFilterMode(
+ ToHTMLConfig.FILTER_MODE_NEVER_PRINT);
+ getToHTMLRenderer(req).getConfig().setOuputMode(
+ ToHTMLConfig.OUTPUT_MODE_REMOVE);
+ getToHTMLRenderer(req).getConfig().setMaxTextWidth(
+ Integer.MAX_VALUE);
+ }
+ return formatTitle(req, text);
+ } catch (Exception e) {
+ // Now if something goes wrong it just returns message with bbcode.
+ return text;
+ }
- /**
- *
- *
- */
- public static String isWatchingForum(Forum forum)
- {
- String watchId = null;
-
- try
- {
- User user = PortalUtil.getUser();
- if (user==null)
- {
- return null;
- }
-
- Watch watch = BaseController.getForumsModule().findForumWatchByUserAndForum( user , forum.getId().intValue() );
-
- if (watch!=null)
- {
- return watch.getId().toString();
- }
-
- } catch (Exception e)
- {
- JSFUtil.handleException(e);
- }
-
-
- return watchId;
- }
+ }
- /**
- *
- * This is for handling attachments in the portal environment Created on Jul
- * 13, 2006
- *
- * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
- */
- private static ThreadLocal uploadedAttachment = new ThreadLocal();
+ /**
+ *
+ * @param text
+ * @return
+ */
+ public static String formatTitle(Object req, String text) {
- /**
- *
- *
- */
- public static void setUploadedAttachment(TempFileBinding attachment)
- {
- PortalUtil.uploadedAttachment.set(attachment);
- }
+ StringWriter stringWriter = new StringWriter();
+ getToHTMLRenderer(req).setWriter(stringWriter);
+ getToHTMLRenderer(req).render(text.toCharArray(), 0, text.length());
+ getToHTMLRenderer(req).getConfig().setMaxTextWidth(Integer.MAX_VALUE);
+ return stringWriter.toString();
- /**
- *
- *
- */
- public static TempFileBinding getUploadedAttachment()
- {
- return (TempFileBinding) PortalUtil.uploadedAttachment.get();
- }
-
- public static User getUserNA() {
- return userNA;
- }
-
+ }
+
+ /**
+ *
+ * @return
+ */
+ private static ToHTMLRenderer getToHTMLRenderer(Object req) {
+ ToHTMLRenderer renderer = null;
+ PortletRequest porReq = null;
+ HttpServletRequest serReq = null;
+ if (req instanceof PortletRequest) {
+ porReq = (PortletRequest) req;
+ renderer = (ToHTMLRenderer) porReq.getPortletSession()
+ .getAttribute("RENDERER");
+ } else {
+ serReq = (HttpServletRequest) req;
+ // TODO: GETTING RENDERER FROM APPLICATION SCOPE ATTRIBUTE
+ }
+ if (renderer == null) {
+
+ // Getting ResourceBundle with current Locale
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ UIViewRoot uiRoot = ctx.getViewRoot();
+ Locale locale = uiRoot.getLocale();
+ ClassLoader ldr = Thread.currentThread().getContextClassLoader();
+ ResourceBundle bundle = ResourceBundle.getBundle("ResourceJSF",
+ locale, ldr);
+
+ // Create the HTMLRenderer for BBCode
+ ToHTMLConfig config = new ToHTMLConfig();
+ config.setLoader(loader);
+ renderer = new ToHTMLRenderer(config, bundle);
+ if (porReq != null) {
+ porReq.getPortletSession().setAttribute("RENDERER", renderer);
+ } else if (serReq != null) {
+ // TODO: SETTING RENDERER IN APPLICATION SCOPE ATTRIBUTE
+ }
+ }
+ return renderer;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static Poll createPoll() {
+ Poll poll = new PollImpl();
+
+ poll.setTitle("");
+ poll.setCreationDate(new Date());
+
+ return poll;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static PollOption createPollOption() {
+ PollOption pollOption = new PollOptionImpl();
+ return pollOption;
+ }
+
+ /**
+ *
+ * @author sshah
+ *
+ *
+ */
+ public static Message createMessage() {
+ Message message = new MessageImpl();
+ return message;
+ }
+
+ /**
+ *
+ *
+ */
+ public static float getVotePercent(Poll poll, PollOption option) {
+ float votePercent = 0;
+
+ float votesSum = poll.getVotesSum();
+ if (votesSum > 0) {
+ votePercent = (option.getVotes() / votesSum);
+ }
+
+ return votePercent;
+ }
+
+ /**
+ *
+ *
+ */
+ public static String isWatchingForum(Forum forum) {
+ String watchId = null;
+
+ try {
+ User user = PortalUtil.getUser();
+ if (user == null) {
+ return null;
+ }
+
+ Watch watch = BaseController.getForumsModule()
+ .findForumWatchByUserAndForum(user,
+ forum.getId().intValue());
+
+ if (watch != null) {
+ return watch.getId().toString();
+ }
+
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+
+ return watchId;
+ }
+
+ /**
+ *
+ * This is for handling attachments in the portal environment Created on Jul
+ * 13, 2006
+ *
+ * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ */
+ private static ThreadLocal uploadedAttachment = new ThreadLocal();
+
+ /**
+ *
+ *
+ */
+ public static void setUploadedAttachment(TempFileBinding attachment) {
+ PortalUtil.uploadedAttachment.set(attachment);
+ }
+
+ /**
+ *
+ *
+ */
+ public static TempFileBinding getUploadedAttachment() {
+ return (TempFileBinding) PortalUtil.uploadedAttachment.get();
+ }
+
+ public static User getUserNA() {
+ return userNA;
+ }
+
}
Modified: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java 2007-06-27 11:06:19 UTC (rev 12889)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.portlet.forums.ui.view;
import java.util.Collection;
@@ -37,354 +37,364 @@
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.core.modules.ModuleException;
import org.jboss.portlet.forums.ForumsModule;
+import org.jboss.portlet.forums.feeds.FeedConstants;
import org.jboss.portlet.forums.model.Forum;
import org.jboss.portlet.forums.model.Topic;
import org.jboss.portlet.forums.ui.Constants;
import org.jboss.portlet.forums.ui.BaseController;
import org.jboss.portlet.forums.ui.JSFUtil;
import org.jboss.portlet.forums.ui.ForumUtil;
+import org.jboss.portlet.forums.ui.PortalUtil;
import org.jboss.portlet.forums.ui.action.PreferenceController;
-//jsf imports
+// jsf imports
-
/**
* @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 ViewForum extends BaseController
-{
- //preference related data
- private PreferenceController userPreferences = null;
-
-
- //business data being generated in this bean by executing ui actions
- //this is data is created such that it can be consumed by the view components
- //like facelets
- private Forum forum = null;
- private PageNavigator pageNavigator = null;
- private Collection page = new ArrayList();
- private Map topicNavigator = new HashMap();
- private Map topicLastPosts = null;
- private List stickyThreads = null;
- private List announcements = null;
-
- //----------------business data being generated for use by the view components like facelets---------------------------------------------------------------------------------------
- /**
- *
- */
- public Forum getForum()
- {
- return this.forum;
- }
- //page navigation related methods on this bean--------------------------------------------------------------------------------------------
- /**
- *
- */
- public PageNavigator getPageNavigator()
- {
- return this.pageNavigator;
- }
-
- /**
- *
- *
- */
- public Map getTopicNavigator()
- {
- return this.topicNavigator;
- }
- //--------------------------------------------------------------------------------------------
- /**
- *
- *
- */
- public Collection getAnnouncements()
- {
- if (announcements!=null) {
- return announcements;
- }
- announcements = new ArrayList();
- try {
- announcements = BaseController.getForumsModule().findTopicsDesc(forum,
- Constants.POST_ANNOUNCE,
- -1,
- Integer.MAX_VALUE);
- } catch (Exception e) {
- JSFUtil.handleException(e);
- }
- return announcements;
- }
-
- /**
- *
- * TODO: Make a special method in ForumsModule for that.
- */
- public boolean isAnnouncementsPresent()
- {
- if (announcements!=null) {
- if (announcements.size()>0) {
- return true;
- } else {
- return false;
- }
- }
- boolean present = false;
- try {
- announcements= BaseController.getForumsModule().findTopicsDesc(forum,
- Constants.POST_ANNOUNCE,
- -1,
- Integer.MAX_VALUE);
- if (announcements!=null && announcements.size()>0) {
- present = true;
- }
- } catch (Exception e) {
- JSFUtil.handleException(e);
- }
- return present;
- }
-
- /**
- *
- * TODO: Make a special method in ForumsModule for that.
- */
- public Collection getStickyThreads()
- {
- if (this.pageNavigator!=null && this.pageNavigator.getCurrentPage()!=0) {
- return new ArrayList();
- }
- if (stickyThreads !=null) {
- return stickyThreads;
- }
- stickyThreads = new ArrayList();
- try {
- //ForumsModule fm = this.getForumsModule();
- stickyThreads = BaseController.getForumsModule().findTopicsDesc(forum,
- Constants.POST_STICKY,
- -1,
- Integer.MAX_VALUE);
- } catch (Exception e) {
- JSFUtil.handleException(e);
- }
- return stickyThreads;
- }
-
- /**
- *
- * TODO: Make a special method in ForumsModule for that.
- */
- public boolean isStickyThreadsPresent()
- {
- if (this.pageNavigator!=null && this.pageNavigator.getCurrentPage()!=0) {
- return false;
- }
- if (stickyThreads !=null) {
- if (stickyThreads.size()>0) {
- return true;
- } else {
- return false;
- }
- }
- boolean present = false;
- try {
- stickyThreads = BaseController.getForumsModule().findTopicsDesc(forum,
- Constants.POST_STICKY,
- -1,
- Integer.MAX_VALUE);
- if (stickyThreads!=null && stickyThreads.size()>0) {
- present = true;
- }
- } catch (Exception e) {
- JSFUtil.handleException(e);
- }
- return present;
- }
-
- /**
- *
- */
- public Collection getNormalThreads()
- {
- return this.page;
- }
-
- /**
- *
- */
- public boolean isNormalThreadsPresent()
- {
- return this.page.size()>0;
- }
-
- /**
- * @return Returns the a Map which contains TopicId:LastPost pairs.
- */
- public Map getTopicLastPosts()
- {
- if(this.topicLastPosts==null)
- {
- this.topicLastPosts = new HashMap();
- }
- return this.topicLastPosts;
- }
-
- //------------user preferences-------------------------------------------------------------------------------------------------------------
- /**
- * @return Returns the userPreferences.
- */
- public PreferenceController getUserPreferences()
- {
- return userPreferences;
- }
- /**
- * @param userPreferences The userPreferences to set.
- */
- public void setUserPreferences(PreferenceController userPreferences)
- {
- this.userPreferences = userPreferences;
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
-
-
- /**
- *
- * @author sshah
- */
- public ViewForum()
- {
- super();
- }
-
- //ui actions supported by this bean----------------------------------------------------------------------------------------------------
- /**
- *
- */
- public boolean isInitialized()
- {
- boolean initialized = false;
- try
- {
- this.execute();
- initialized = true;
- }
- catch(Exception e)
- {
- JSFUtil.handleException(e);
- }
- return initialized;
- }
-
- /**
- *
- *
- */
- private void execute() throws Exception
- {
- //parse the input parameters
- String page = ForumUtil.getParameter(Constants.p_page);
- int forumId = -1;
- String f = ForumUtil.getParameter(Constants.p_forumId);
- if(f!=null && f.trim().length()>0)
- {
- forumId = Integer.parseInt(f);
- }
-
- // ForumsModule is stored as a final variable so that anonymous class could use it.
- final ForumsModule fm = BaseController.getForumsModule();
-
- //grab the data to be displayed for this page
- if(forumId!=-1)
- {
- //setup the business objects like the forum, topics etc that will be displayed
- this.forum = fm.findForumById(new Integer(forumId));
-
- int pageNumber = 0;
-
- if(page!=null && page.trim().length()>0)
- {
- //setup the page data
- pageNumber = Integer.parseInt(page);
- }
-
- // clearing previous PageNavigator
- this.pageNavigator=null;
-
- int ads = 0;
- ads+=getAnnouncements().size();
- ads+=getStickyThreads().size();
-
- //setup the pageNavigator for this forum
- this.pageNavigator = new PageNavigator(
- forum.getTopicCount()-ads, //total number of entries without annoucements and stickies to be split up into pages
- Integer.parseInt(this.userPreferences.getPreference(Constants.TOPICS_FORUM_KEY)),
- pageNumber //currently selected page being displayed, first page by default
- ) {
-
- protected Collection initializePage() {
-
- int beginIndex = this.getBeginIndex();
- int totalEntries = this.getNumberOfEntries();
- int pageSize = this.getPageSize();
-
- //reset the page navigation if the start cursor is outside the range (both forward and backward)
- if(beginIndex >= totalEntries || beginIndex < 0)
- {
- this.setCurrentPage(0); //go to the first page
- beginIndex = this.getBeginIndex();
- }
-
- try {
- return fm.findTopicsDesc(forum,
- Constants.POST_NORMAL,
- beginIndex,
- pageSize);
- } catch (ModuleException e) {
- JSFUtil.handleException(e);
- }
- return new ArrayList();
-
- }
-
- };
-
- this.page = this.pageNavigator.getPage();
-
- // Getting sticky topics for this page
- Collection stickies = getStickyThreads();
-
- // Getting announcements
- Collection announcements = getAnnouncements();
-
- Collection listOfTopics = new LinkedList();
-
- listOfTopics.addAll(stickies);
- listOfTopics.addAll(announcements);
- listOfTopics.addAll(this.page);
+public class ViewForum extends BaseController {
+ // preference related data
+ private PreferenceController userPreferences = null;
- // Getting sticky topics for this page
- this.topicLastPosts = fm.findLastPostsOfTopics(listOfTopics);
-
- // setup dummy pageNavigators for all topics being displayed for topic minipaging
- for(Iterator itr=listOfTopics.iterator();itr.hasNext();)
- {
- Topic cour = (Topic)itr.next();
- if(cour.getReplies()>0)
- {
- PageNavigator topicNav = new PageNavigator(cour.getReplies()+1,
- Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)), //this is user's posts per page preference
- 0 //current page of the navigator
- ) {
+ // business data being generated in this bean by executing ui actions
+ // this is data is created such that it can be consumed by the view
+ // components
+ // like facelets
+ private Forum forum = null;
- protected Collection initializePage() {
- return null;
- }
-
- };
- this.topicNavigator.put(cour.getId(),topicNav);
- }
- }
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
+ private PageNavigator pageNavigator = null;
+
+ private Collection page = new ArrayList();
+
+ private Map topicNavigator = new HashMap();
+
+ private Map topicLastPosts = null;
+
+ private List stickyThreads = null;
+
+ private List announcements = null;
+
+ // ----------------business data being generated for use by the view
+ // components like
+ // facelets---------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public Forum getForum() {
+ return this.forum;
+ }
+
+ // page navigation related methods on this
+ // bean--------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public PageNavigator getPageNavigator() {
+ return this.pageNavigator;
+ }
+
+ /**
+ *
+ *
+ */
+ public Map getTopicNavigator() {
+ return this.topicNavigator;
+ }
+
+ // --------------------------------------------------------------------------------------------
+ /**
+ *
+ *
+ */
+ public Collection getAnnouncements() {
+ if (announcements != null) {
+ return announcements;
+ }
+ announcements = new ArrayList();
+ try {
+ announcements = BaseController.getForumsModule().findTopicsDesc(
+ forum, Constants.POST_ANNOUNCE, -1, Integer.MAX_VALUE);
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return announcements;
+ }
+
+ /**
+ *
+ * TODO: Make a special method in ForumsModule for that.
+ */
+ public boolean isAnnouncementsPresent() {
+ if (announcements != null) {
+ if (announcements.size() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ boolean present = false;
+ try {
+ announcements = BaseController.getForumsModule().findTopicsDesc(
+ forum, Constants.POST_ANNOUNCE, -1, Integer.MAX_VALUE);
+ if (announcements != null && announcements.size() > 0) {
+ present = true;
+ }
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return present;
+ }
+
+ /**
+ *
+ * TODO: Make a special method in ForumsModule for that.
+ */
+ public Collection getStickyThreads() {
+ if (this.pageNavigator != null
+ && this.pageNavigator.getCurrentPage() != 0) {
+ return new ArrayList();
+ }
+ if (stickyThreads != null) {
+ return stickyThreads;
+ }
+ stickyThreads = new ArrayList();
+ try {
+ // ForumsModule fm = this.getForumsModule();
+ stickyThreads = BaseController.getForumsModule().findTopicsDesc(
+ forum, Constants.POST_STICKY, -1, Integer.MAX_VALUE);
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return stickyThreads;
+ }
+
+ /**
+ *
+ * TODO: Make a special method in ForumsModule for that.
+ */
+ public boolean isStickyThreadsPresent() {
+ if (this.pageNavigator != null
+ && this.pageNavigator.getCurrentPage() != 0) {
+ return false;
+ }
+ if (stickyThreads != null) {
+ if (stickyThreads.size() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ boolean present = false;
+ try {
+ stickyThreads = BaseController.getForumsModule().findTopicsDesc(
+ forum, Constants.POST_STICKY, -1, Integer.MAX_VALUE);
+ if (stickyThreads != null && stickyThreads.size() > 0) {
+ present = true;
+ }
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return present;
+ }
+
+ /**
+ *
+ */
+ public Collection getNormalThreads() {
+ return this.page;
+ }
+
+ /**
+ *
+ */
+ public boolean isNormalThreadsPresent() {
+ return this.page.size() > 0;
+ }
+
+ /**
+ * @return Returns the a Map which contains TopicId:LastPost pairs.
+ */
+ public Map getTopicLastPosts() {
+ if (this.topicLastPosts == null) {
+ this.topicLastPosts = new HashMap();
+ }
+ return this.topicLastPosts;
+ }
+
+ // ------------user
+ // preferences-------------------------------------------------------------------------------------------------------------
+ /**
+ * @return Returns the userPreferences.
+ */
+ public PreferenceController getUserPreferences() {
+ return userPreferences;
+ }
+
+ /**
+ * @param userPreferences
+ * The userPreferences to set.
+ */
+ public void setUserPreferences(PreferenceController userPreferences) {
+ this.userPreferences = userPreferences;
+ }
+
+ // -------------------------------------------------------------------------------------------------------------------------------------
+
+ /**
+ *
+ * @author sshah
+ */
+ public ViewForum() {
+ super();
+ }
+
+ // ui actions supported by this
+ // bean----------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public boolean isInitialized() {
+ boolean initialized = false;
+ try {
+ this.execute();
+ initialized = true;
+ } catch (Exception e) {
+ JSFUtil.handleException(e);
+ }
+ return initialized;
+ }
+
+ /**
+ *
+ *
+ */
+ private void execute() throws Exception {
+ // parse the input parameters
+ String page = ForumUtil.getParameter(Constants.p_page);
+ int forumId = -1;
+ String f = ForumUtil.getParameter(Constants.p_forumId);
+ if (f != null && f.trim().length() > 0) {
+ forumId = Integer.parseInt(f);
+ }
+
+ // ForumsModule is stored as a final variable so that anonymous class
+ // could use it.
+ final ForumsModule fm = BaseController.getForumsModule();
+
+ // grab the data to be displayed for this page
+ if (forumId != -1) {
+ // setup the business objects like the forum, topics etc that will
+ // be displayed
+ this.forum = fm.findForumById(new Integer(forumId));
+
+ int pageNumber = 0;
+
+ if (page != null && page.trim().length() > 0) {
+ // setup the page data
+ pageNumber = Integer.parseInt(page);
+ }
+
+ // clearing previous PageNavigator
+ this.pageNavigator = null;
+
+ int ads = 0;
+ ads += getAnnouncements().size();
+ ads += getStickyThreads().size();
+
+ // setup the pageNavigator for this forum
+ this.pageNavigator = new PageNavigator(
+ forum.getTopicCount() - ads, // total number of entries
+ // without annoucements and
+ // stickies to be split up
+ // into pages
+ Integer.parseInt(this.userPreferences
+ .getPreference(Constants.TOPICS_FORUM_KEY)),
+ pageNumber // currently selected page being displayed,
+ // first page by default
+ ) {
+
+ protected Collection initializePage() {
+
+ int beginIndex = this.getBeginIndex();
+ int totalEntries = this.getNumberOfEntries();
+ int pageSize = this.getPageSize();
+
+ // reset the page navigation if the start cursor is outside
+ // the range (both forward and backward)
+ if (beginIndex >= totalEntries || beginIndex < 0) {
+ this.setCurrentPage(0); // go to the first page
+ beginIndex = this.getBeginIndex();
+ }
+
+ try {
+ return fm.findTopicsDesc(forum, Constants.POST_NORMAL,
+ beginIndex, pageSize);
+ } catch (ModuleException e) {
+ JSFUtil.handleException(e);
+ }
+ return new ArrayList();
+
+ }
+
+ };
+
+ this.page = this.pageNavigator.getPage();
+
+ // Getting sticky topics for this page
+ Collection stickies = getStickyThreads();
+
+ // Getting announcements
+ Collection announcements = getAnnouncements();
+
+ Collection listOfTopics = new LinkedList();
+
+ listOfTopics.addAll(stickies);
+ listOfTopics.addAll(announcements);
+ listOfTopics.addAll(this.page);
+
+ // Getting sticky topics for this page
+ this.topicLastPosts = fm.findLastPostsOfTopics(listOfTopics);
+
+ // setup dummy pageNavigators for all topics being displayed for
+ // topic minipaging
+ for (Iterator itr = listOfTopics.iterator(); itr.hasNext();) {
+ Topic cour = (Topic) itr.next();
+ if (cour.getReplies() > 0) {
+ PageNavigator topicNav = new PageNavigator(cour
+ .getReplies() + 1, Integer
+ .parseInt(this.userPreferences
+ .getPreference(Constants.POSTS_TOPIC_KEY)), // this
+ // is
+ // user's
+ // posts
+ // per
+ // page
+ // preference
+ 0 // current page of the navigator
+ ) {
+
+ protected Collection initializePage() {
+ return null;
+ }
+
+ };
+ this.topicNavigator.put(cour.getId(), topicNav);
+ }
+ }
+ }
+ }
+
+ public String getRssFeed() {
+ return PortalUtil.createFeedLink(FeedConstants.RSS,
+ FeedConstants.FORUM, forum.getId());
+ }
+
+ public String getAtomFeed() {
+ return PortalUtil.createFeedLink(FeedConstants.ATOM,
+ FeedConstants.FORUM, forum.getId());
+ }
+
+ // -------------------------------------------------------------------------------------------------------------------------------------
}
Modified: labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml 2007-06-27 08:07:01 UTC (rev 12888)
+++ labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml 2007-06-27 11:06:19 UTC (rev 12889)
@@ -106,7 +106,10 @@
<h4>
${forum.forum.name}
</h4>
- </div>
+ </div>
+
+ <a href="#{forum.rssFeed}">RSS</a>
+ <a href="#{forum.atomFeed}">ATOM</a>
<!-- PAGINATION -->
<c:if test="#{forum.pageNavigator.totalPages gt 1}">
More information about the jboss-svn-commits
mailing list