[jboss-svn-commits] JBL Code SVN: r13180 - 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
Fri Jul 6 14:43:32 EDT 2007
Author: unibrew
Date: 2007-07-06 14:43:31 -0400 (Fri, 06 Jul 2007)
New Revision: 13180
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-sar/conf/hibernate/setup.txt
Log:
[JBFORUMS] Clearing up the code.
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-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ForumsModule.java 2007-07-06 18:43:31 UTC (rev 13180)
@@ -28,688 +28,643 @@
* @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
* @version $Revision: 3217 $
*/
-public interface ForumsModule {
+public interface ForumsModule
+{
- public HibernateProvider getHibernate();
+ public HibernateProvider getHibernate();
+ /**
+ *
+ */
+ int getFloodInterval();
- /**
- *
- */
- int getFloodInterval();
+ /**
+ *
+ */
+ void setFloodInterval(int floodInterval);
- /**
- *
- */
- void setFloodInterval(int floodInterval);
+ /**
+ *
+ */
+ String getFromAddress();
- /**
- *
- */
- String getFromAddress();
+ /**
+ *
+ */
+ void setFromAddress(String fromAddress);
- /**
- *
- */
- void setFromAddress(String fromAddress);
+ /**
+ * 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 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
- *
- * @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 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
+ *
+ * @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;
- /**
- * 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 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 findCategoryByIdFetchForums(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 source
- * DOCUMENT_ME
- * @param target
- * DOCUMENT_ME
- * @throws ModuleException
- * DOCUMENT_ME
- */
- void addAllForums(Category source, Category target) throws ModuleException;
+ /**
+ * @param topicID
+ * @return DOCUMENT_ME
+ */
+ Topic findTopicById(Integer topicID)
+ throws ModuleException;
- /**
- * @param topicID
- * @return DOCUMENT_ME
- */
- Topic findTopicById(Integer topicID) 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
- * @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 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 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 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 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 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 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 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 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 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 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 findPostsByTopicIdDesc(Integer topicID, int start, int limit)
- throws ModuleException;
+ Date findLastPostDateForUser(User user) throws ModuleException;
- Date findLastPostDateForUser(User user) throws ModuleException;
+ Post findLastPost(Forum forum) throws ModuleException;
- Post findLastPost(Forum forum) throws ModuleException;
+ Post findFirstPost(Topic topic) throws ModuleException;
- Post findFirstPost(Topic topic) throws ModuleException;
+ Post findLastPost(Topic topic) throws ModuleException;
+
+ Map findLastPostsOfTopics(Collection topics) throws ModuleException;
+
+ Map findLastPostsOfForums() throws ModuleException;
- Post findLastPost(Topic topic) throws ModuleException;
+ List findForumWatchByUser(User user) throws ModuleException;
- Map findLastPostsOfTopics(Collection topics) throws ModuleException;
+ List findForumWatchedByUser(User user) throws ModuleException;
+
+ List findTopicWatchedByUser(User user) throws ModuleException;
+
+ List findTopicWatchedByUser(User user,Date date) throws ModuleException;
+
+ List findPostsFromForumAsc(Forum forum, int limit) throws ModuleException;
+
+ 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;
- Map findLastPostsOfForums() throws ModuleException;
- List findForumWatchByUser(User user) throws ModuleException;
+ Poster createPoster(String userID) throws ModuleException;
- List findForumWatchedByUser(User user) throws ModuleException;
+ /**
+ * @param poster
+ * @param forum
+ * @param i
+ */
+ void createWatch(Poster poster, Forum forum, int i) throws ModuleException;
- List findTopicWatchedByUser(User user) throws ModuleException;
+ /**
+ * @param forumWatchID
+ * @return DOCUMENT_ME
+ */
+ ForumWatch findForumWatchById(Integer forumWatchID) throws ModuleException;
- List findTopicWatchedByUser(User user, Date date) 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 findPostsFromForumAsc(Forum forum, int limit) throws ModuleException;
+ /**
+ * @param topicWatchID
+ * @return DOCUMENT_ME
+ */
+ TopicWatch findTopicWatchById(Integer topicWatchID) throws ModuleException;
- List findPostsFromForumDesc(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();
+
+ /**
+ *
+ * @return
+ */
+ public List findPostsDesc(int limit) throws ModuleException;
+
+ /**
+ *
+ * @return
+ */
+ public List findPostsAsc(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-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java 2007-07-06 18:43:31 UTC (rev 13180)
@@ -162,7 +162,7 @@
private void createGlobalFeed(SyndFeed feed, Integer id)
throws ModuleException {
feed.setTitle("JBoss Forums Global Feed");
- feed.setLink(PortalUtil.globalPermlink());
+ feed.setLink(PortalUtil.globalLink());
feed.setDescription("Messages posted in JBoss Forums");
List entries = new ArrayList();
@@ -182,7 +182,7 @@
Forum forum = forumsModule.findForumById(id);
feed.setTitle("JBoss Forums Forum Feed: " + forum.getName());
- feed.setLink(PortalUtil.categoryPermlink(id.toString()));
+ feed.setLink(PortalUtil.categoryLink(id.toString()));
feed.setDescription("Messages posted in forum " + forum.getName()
+ " in category " + forum.getCategory().getTitle());
@@ -204,7 +204,7 @@
Topic topic = forumsModule.findTopicById(id);
feed.setTitle("JBoss Forums Topic Feed: " + topic.getSubject());
- feed.setLink(PortalUtil.topicPermlink(id.toString()));
+ feed.setLink(PortalUtil.topicLink(id.toString()));
feed.setDescription("Messages posted in topic " + topic.getSubject()
+ " in forum " + topic.getForum().getName() + " in category "
+ topic.getForum().getCategory().getTitle());
@@ -238,7 +238,7 @@
Category category = forumsModule.findCategoryById(id);
feed.setTitle("JBoss Forums Category Feed: " + category.getTitle());
- feed.setLink(PortalUtil.categoryPermlink(id.toString()));
+ feed.setLink(PortalUtil.categoryLink(id.toString()));
feed.setDescription("Messages posted in category "
+ category.getTitle());
@@ -262,7 +262,7 @@
entry = new SyndEntryImpl();
entry.setTitle(post.getMessage().getSubject() + " by "
+ post.getPoster().getUser().getUserName());
- entry.setLink(PortalUtil.postPermlink(post.getId().toString()));
+ entry.setLink(PortalUtil.postLink(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-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java 2007-07-06 18:43:31 UTC (rev 13180)
@@ -47,6 +47,7 @@
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>
@@ -55,1565 +56,1991 @@
* @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 HibernateProvider hibernate;
+ private SessionFactory factory;
+ private UserProfileModule userProfileModule;
- private SessionFactory factory;
+ private NotificationEngine notificationEngine;
+
+ private int floodInterval;
- private UserProfileModule userProfileModule;
+ private String fromAddress;
- private NotificationEngine notificationEngine;
+// private final ResourceCacheInvalidatorInterceptor resourceInterceptor;
+// private final IndexInterceptor indexInterceptor;
+// private CompositeFilter compositeInterceptor;
+// private NotificationInterceptor notificationInterceptor;
+// private FloodControlInterceptor floodControlInterceptor;
+// private ExecuteFilter executeInterceptor;
+// private CommandFilter chain;
- private int floodInterval;
+ protected void startService() throws Exception
+ {
+ super.startService();
- private String fromAddress;
+ 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 final ResourceCacheInvalidatorInterceptor resourceInterceptor;
- // private final IndexInterceptor indexInterceptor;
- // private CompositeFilter compositeInterceptor;
- // private NotificationInterceptor notificationInterceptor;
- // private FloodControlInterceptor floodControlInterceptor;
- // private ExecuteFilter executeInterceptor;
- // private CommandFilter chain;
+ // Assemble the chain
+// compositeInterceptor.setNext(resourceInterceptor);
+// resourceInterceptor.setNext(indexInterceptor);
+// indexInterceptor.setNext(notificationInterceptor);
- protected void startService() throws Exception {
- super.startService();
+// compositeInterceptor.setNext(executeInterceptor);
+// notificationInterceptor.setNext(floodControlInterceptor);
+// floodControlInterceptor.setNext(executeInterceptor);
+ }
- 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 HibernateProvider getHibernate()
+ {
+ return hibernate;
+ }
- // Assemble the chain
- // compositeInterceptor.setNext(resourceInterceptor);
- // resourceInterceptor.setNext(indexInterceptor);
- // indexInterceptor.setNext(notificationInterceptor);
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setHibernate(HibernateProvider hibernate)
+ {
+ this.hibernate = hibernate;
+ }
- // compositeInterceptor.setNext(executeInterceptor);
- // notificationInterceptor.setNext(floodControlInterceptor);
- // floodControlInterceptor.setNext(executeInterceptor);
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public int getFloodInterval()
+ {
+ return floodInterval;
+ }
- /**
- * @jmx.managed-attribute
- */
- public HibernateProvider getHibernate() {
- return hibernate;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setFloodInterval(int floodInterval)
+ {
+ this.floodInterval = floodInterval;
+ }
- /**
- * @jmx.managed-attribute
- */
- public void setHibernate(HibernateProvider hibernate) {
- this.hibernate = hibernate;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public String getFromAddress()
+ {
+ return fromAddress;
+ }
- /**
- * @jmx.managed-attribute
- */
- public int getFloodInterval() {
- return floodInterval;
- }
+ /**
+ * @jmx.managed-attribute
+ */
+ public void setFromAddress(String fromAddress)
+ {
+ this.fromAddress = fromAddress;
+ }
- /**
- * @jmx.managed-attribute
- */
- public void setFloodInterval(int floodInterval) {
- this.floodInterval = 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 String getFromAddress() {
- return fromAddress;
- }
+ 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 void setFromAddress(String fromAddress) {
- this.fromAddress = 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);
+ }
- 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);
- }
+ 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");
+ }
+ }
- 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 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 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);
- }
+ 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");
+ }
+ }
- 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 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 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");
+ }
+ }
- 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 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 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 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);
+ }
+ }
- 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 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);
+ }
+ }
- 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 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 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 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 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 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 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);
- }
- }
+ }
- 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);
- }
- }
+ /**
+ *
+ * @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 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 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);
- }
+ /**
+ *
+ * @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");
+ }
- /**
- *
- * @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);
- }
- }
- /**
- *
- * @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 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");
+ }
- 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 type, int start, int perPage)
- throws ModuleException {
- return findTopics(forum, type, start, perPage, "desc");
- }
+ public List findTopicsDesc(Forum forum,
+ int start,
+ int perPage)
+ throws ModuleException
+ {
+ return findTopics(forum, start, perPage, "desc");
+ }
- public List findTopicsAsc(Forum forum, int start, int perPage)
- throws ModuleException {
- return findTopics(forum, start, perPage, "asc");
- }
+ public List findTopicsBefore(Forum forum,
+ int type,
+ int start,
+ int perPage,
+ Date date)
+ throws ModuleException
+ {
+ return null;
+ }
- public List findTopicsDesc(Forum forum, int start, int perPage)
- throws ModuleException {
- return findTopics(forum, start, perPage, "desc");
- }
+ 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 findTopicsBefore(Forum forum, int type, int start, int perPage,
- Date date) throws ModuleException {
- return null;
- }
+ 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 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);
- }
- }
+ 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 findTopicsByLatestPosts(int limit) throws ModuleException {
- try {
- // SELECT DISTINCT OBJECT(t) FROM topic AS t ORDER BY t.lastPostDate
- // DESC LIMIT ?1"
+ 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);
+ }
+ }
- 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 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);
+ }
+ }
- 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 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);
- }
- }
+ public Post createTopic(Forum forum,
+ Message message,
+ Date creationDate,
+ Poster poster,
+ Poll poll,
+ List attachments,
+ int type)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- 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);
- 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);
- forum.addTopicSize();
- forum.addPostSize();
+ session.save(topic);
- 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);
- }
- }
+ forum.addTopicSize();
+ forum.addPostSize();
- public Topic createTopic(Forum forum, String userId, String subject,
- int type) throws ModuleException {
- try {
- Session session = getSession();
+ 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);
+ }
+ }
- Poster poster = findPosterByUserId(userId);
+ public Topic createTopic(Forum forum,
+ String userId,
+ String subject,
+ int type)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- if (poster == null) {
- poster = createPoster(userId);
- }
- session.save(poster);
+ Poster poster = findPosterByUserId(userId);
- 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);
+ if (poster == null)
+ {
+ poster = createPoster(userId);
+ }
+ session.save(poster);
- topic.setPoll(null);
+ 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);
- session.save(topic);
- // forum.addTopicSize();
- // forum.addPostSize();
+ topic.setPoll(null);
- return topic;
- } catch (HibernateException e) {
- String errorMessage = "Cannot create topic";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
- public Post createPost(Topic topic, Forum forum, Message message,
- Date creationDate, Poster poster, List attachments)
- throws ModuleException {
- try {
- Session session = getSession();
- session.save(poster);
+ session.save(topic);
+ //forum.addTopicSize();
+ //forum.addPostSize();
- 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);
+ return topic;
+ }
+ catch (HibernateException e)
+ {
+ String errorMessage = "Cannot create topic";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- topic.addPost(post);
- // post.setTopic(topic);
- // 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 Post createPost(Topic topic,
+ Forum forum,
+ Message message,
+ Date creationDate,
+ Poster poster,
+ List attachments)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
+ session.save(poster);
- 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);
- }
- }
- 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;
- }
- }
+ 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);
+ }
- public Category createCategory(String name) throws ModuleException {
- try {
- Session session = getSession();
- 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);
- }
- }
+ session.save(post);
- 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.addPost(post);
+ //post.setTopic(topic);
- 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);
- }
+ //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);
+ }
+ }
- // session.flush();
- } catch (HibernateException e) {
- String errorMessage = "Cannot delete forum";
- 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);
+ }
+ }
- 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);
- }
- }
+ 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 removePollInTopic(Topic topic) throws ModuleException {
- Session session = getSession();
- try {
- // session.flush();
- Poll poll = topic.getPoll();
- topic.setPoll(null);
- session.delete(poll);
+ public Category createCategory(String name)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- } catch (HibernateException e) {
- String errorMessage = "Cannot delete poll";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ 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);
+ }
+ }
- 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 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);
+ }
+ }
- 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 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 Forum createForum(Category category, String name, String description)
- throws ModuleException {
- try {
- Session session = getSession();
+ //session.flush();
+ }
+ catch (HibernateException e)
+ {
+ String errorMessage = "Cannot delete forum";
+ 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 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 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 void removePollInTopic(Topic topic)
+ throws ModuleException
+ {
+ Session session = getSession();
+ try
+ {
+ //session.flush();
+ Poll poll = topic.getPoll();
+ topic.setPoll(null);
+ session.delete(poll);
- 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");
- }
- }
+ }
+ catch (HibernateException e)
+ {
+ String errorMessage = "Cannot delete poll";
+ 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");
- }
- }
+ 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 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 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 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);
- }
+ public Forum createForum(Category category,
+ String name,
+ String description)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- 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");
- }
- }
+ 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 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 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);
+ }
- 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");
- }
- }
+ 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");
+ }
+ }
- 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 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 findPostsByIdsFetchAttachmentsAndPosters(Collection postIds,
- String order) throws ModuleException {
+ 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);
+ }
+ }
- if (postIds == null || postIds.size() == 0) {
- return new LinkedList();
- }
+ 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);
+ }
- 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);
- }
- }
+ 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 List findPostsByIdsAscFetchAttachmentsAndPosters(Collection postIds)
- throws ModuleException {
- return findPostsByIdsFetchAttachmentsAndPosters(postIds, "asc");
- }
+ 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 findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
- throws ModuleException {
- return findPostsByIdsFetchAttachmentsAndPosters(postIds, "desc");
- }
+ 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");
+ }
+ }
- 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 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 findPostIdsAsc(Integer topicId, int start, int limit)
- throws ModuleException {
- return findPostIds(topicId, start, limit, "asc");
- }
+ 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 findPostIdsDesc(Integer topicId, int start, int limit)
- throws ModuleException {
- return findPostIds(topicId, start, limit, "desc");
- }
+ public List findPostsByIdsDescFetchAttachmentsAndPosters(Collection postIds)
+ throws ModuleException
+ {
+ return findPostsByIdsFetchAttachmentsAndPosters( postIds , "desc");
+ }
- 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);
- }
- }
+ 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 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 findPostIdsDesc(Integer topicId,
+ int start,
+ int limit)
+ throws ModuleException
+ {
+ return findPostIds(topicId, start, limit, "desc");
+ }
- public List findPostsByTopicIdAsc(Integer topicId, int start, int limit)
- throws ModuleException {
- return findPostsByTopicId(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 findPostsByTopicIdDesc(Integer topicId, int start, int limit)
- throws ModuleException {
- return findPostsByTopicId(topicId, start, limit, "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;
- }
- }
+ 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 Post findLastPost(Forum forum) throws ModuleException {
- try {
- Session session = getSession();
- Query query =
+ public List findPostsByTopicIdAsc(Integer topicId,
+ int start,
+ int limit)
+ throws ModuleException
+ {
+ return findPostsByTopicId(topicId, start, limit, "asc");
+ }
- // 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 List findPostsByTopicIdDesc(Integer topicId,
+ int start,
+ int limit)
+ throws ModuleException
+ {
+ return findPostsByTopicId(topicId, start, limit, "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 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 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 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;
+ }
+ }
- 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 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;
+ }
+ }
- 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 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 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 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;
+ }
+ }
- // if there are no createDates then we return an empty map
- if (dates.size() == 0) {
- return new HashMap(0);
- }
+ 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 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;
- }
- }
+ query.setString("forumId", forum.getId().toString());
- 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]);
- }
+ query.setFirstResult(0);
- // if there are no posts in all forums then return empty map
- if (dates.size() == 0) {
- return new HashMap(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);
+ }
+ }
- 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 List findPostsFromForumAsc(Forum forum, int limit)
+ throws ModuleException
+ {
+ return findPostsFromForum(forum, limit, "asc");
+ }
- 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 findPostsFromForumDesc(Forum forum, int limit)
+ throws ModuleException
+ {
+ return findPostsFromForum(forum, limit, "desc");
+ }
- 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);
- }
- }
+ 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);
- 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);
- }
- }
+ query.setString("categoryId", category.getId().toString());
- 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);
- }
- }
+ query.setFirstResult(0);
- /**
- *
- * 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 (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 void createWatch(Poster poster, Forum forum, int mode)
- throws ModuleException {
- try {
- Session session = getSession();
+ public List findPostsFromCategoryAsc(Category category, int limit)
+ throws ModuleException
+ {
+ return findPostsFromCategory(category, limit, "asc");
+ }
- if (poster == null) {
- throw new ModuleException("poster must not be null");
- }
+ public List findPostsFromCategoryDesc(Category category, int limit)
+ throws ModuleException
+ {
+ return findPostsFromCategory(category, limit, "desc");
+ }
- if (forum == null) {
- throw new ModuleException("forum must not be null");
- }
+ 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);
- session.save(poster);
+ query.setFirstResult(0);
- ForumWatch forumWatch = new ForumWatchImpl();
- forumWatch.setPoster(poster);
- forumWatch.setForum(forum);
- forumWatch.setMode(mode);
- session.save(forumWatch);
+ 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);
+ }
+ }
- } catch (HibernateException e) {
- String errorMessage = "Cannot create forum watch";
- log.error(errorMessage, e);
- throw new ModuleException(errorMessage, e);
- }
- }
+ public List findPostsAsc(int limit) throws ModuleException
+ {
+ return findPosts(limit, "asc");
+ }
- 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 findPostsDesc(int limit) throws ModuleException
+ {
+ return findPosts(limit, "desc");
+ }
+
+ 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);
+ }
+ }
- 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);
- }
- }
+ public void createWatch(Poster poster, Forum forum, int mode) throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- /**
- *
- * 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);
- }
- }
+ if (poster == null)
+ {
+ throw new ModuleException("poster must not be null");
+ }
- 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);
- }
- }
+ if (forum == null)
+ {
+ throw new ModuleException("forum must not be null");
+ }
- 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);
- }
- }
+ session.save(poster);
+
+ ForumWatch forumWatch = new ForumWatchImpl();
+ forumWatch.setPoster(poster);
+ forumWatch.setForum(forum);
+ forumWatch.setMode(mode);
+ session.save(forumWatch);
- public void createWatch(Poster poster, Topic topic, int mode)
- throws ModuleException {
- try {
- Session session = getSession();
+ }
+ catch (HibernateException e)
+ {
+ String errorMessage = "Cannot create forum watch";
+ log.error(errorMessage, e);
+ throw new ModuleException(errorMessage, e);
+ }
+ }
- if (poster == null) {
- throw new ModuleException("poster must not be null");
- }
+ 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);
+ }
+ }
- if (topic == null) {
- throw new ModuleException("topic must not be null");
- }
+ 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);
+ }
+ }
- session.save(poster);
+ public void createWatch(Poster poster, Topic topic,int mode)
+ throws ModuleException
+ {
+ try
+ {
+ Session session = getSession();
- 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);
- }
- }
+ if (topic == null)
+ {
+ throw new ModuleException("topic must not be null");
+ }
- public void processNotifications(Integer postId, int watchType,
- String postUrl, String replyUrl) {
- notificationEngine.schedule(postId, watchType, postUrl, replyUrl);
- }
+ 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 UserProfileModule getUserProfileModule() {
- return this.userProfileModule;
- }
+ 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();
+ }
+}
- 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-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2007-07-06 18:43:31 UTC (rev 13180)
@@ -52,7 +52,6 @@
import org.jboss.portal.identity.UserProfileModule;
import org.jboss.portlet.forums.ForumsConstants;
import org.jboss.portlet.forums.feeds.FeedConstants;
-import org.jboss.portlet.forums.feeds.FeedsServlet;
import org.jboss.portlet.forums.helper.TempFileBinding;
import org.jboss.portlet.forums.impl.MessageImpl;
import org.jboss.portlet.forums.impl.PollImpl;
@@ -70,645 +69,766 @@
* @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 Logger log = Logger.getLogger(PortalUtil.class);
+
+ private static SimpleDateFormat sdfForLastLoginDate;
- private static SimpleDateFormat sdfForLastLoginDate;
+ private static User user = new User()
+ {
+ public Object getId()
+ {
+ return null;
+ }
- private static User user = new User() {
- public Object getId() {
- return null;
- }
+ public void updatePassword(String string)
+ {
+ }
- public void updatePassword(String string) {
- }
+ public boolean validatePassword(String string)
+ {
+ return false;
+ }
- public boolean validatePassword(String string) {
- return false;
- }
+ public String getUserName()
+ {
+ return null;
+ }
+ };
- public String getUserName() {
- return null;
- }
- };
+ private static User userNA = new User()
+ {
+ {
+ this.id = new Long(-1);
+ this.userName = "N/A";
+ }
+
+ protected Object id;
+
+ protected String userName;
- private static User userNA = new User() {
- {
- this.id = new Long(-1);
- this.userName = "N/A";
- }
+ public Object getId() {
+ return id;
+ }
- protected Object id;
+ public String getUserName() {
+ return userName;
+ }
- protected String userName;
+ public void updatePassword(String password) {
+ }
- public Object getId() {
- return id;
- }
+ public boolean validatePassword(String password) {
+ return false;
+ }
+ };
+
+ private final static UserProfileModule upm;
- public String getUserName() {
- return userName;
- }
+ 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 void updatePassword(String password) {
- }
+ /**
+ *
+ *
+ */
+ public static boolean isRunningInPortal()
+ {
+ boolean isRunningInPortal = false;
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (o instanceof PortletRequest)
+ {
+ isRunningInPortal = true;
+ }
+ return isRunningInPortal;
+ }
- public boolean validatePassword(String password) {
- return false;
- }
- };
+ /**
+ *
+ * @author sshah
+ *
+ */
+ public static String outputLink(String outputLink, boolean isAction)
+ {
+ try
+ {
+ String url = null;
- private final static UserProfileModule upm;
+ Object response = FacesContext.getCurrentInstance()
+ .getExternalContext().getResponse();
- static {
- UserProfileModule temporary = null;
- try {
- temporary = (UserProfileModule) new InitialContext()
- .lookup("java:portal/UserProfileModule");
- } catch (NamingException e) {
- JSFUtil.handleException(e);
- } finally {
- upm = temporary;
- }
+ if (!outputLink.startsWith("/"))
+ {
+ outputLink = "/" + outputLink;
+ }
- sdfForLastLoginDate = new SimpleDateFormat(
- "EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
- }
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse renderResponse = (RenderResponse) response;
- /**
- *
- *
- */
- public static boolean isRunningInPortal() {
- boolean isRunningInPortal = false;
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (o instanceof PortletRequest) {
- isRunningInPortal = true;
- }
- return isRunningInPortal;
- }
+ PortletURL portletURL = null;
- /**
- *
- * @author sshah
- *
- */
- public static String outputLink(String outputLink, boolean isAction) {
- try {
- String url = null;
+ if (isAction)
+ {
+ portletURL = renderResponse.createActionURL();
+ } else
+ {
+ portletURL = renderResponse.createRenderURL();
+ }
- Object response = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ String jsfUrl = portletURL.toString();
+ jsfUrl += "&"
+ + ForumsJSFPortlet.VIEW
+ + "="
+ + URLEncoder.encode(ForumsJSFPortlet
+ .getIdForName(outputLink), "UTF-8");
- if (!outputLink.startsWith("/")) {
- outputLink = "/" + outputLink;
- }
+ url = jsfUrl;
+ } else
+ {
+ String contextPath = JSFUtil.getContextPath();
+ url = contextPath + outputLink;
+ }
- if (response instanceof RenderResponse) {
- RenderResponse renderResponse = (RenderResponse) response;
+ return url;
+ } catch (Exception e)
+ {
+ log.error(PortalUtil.class.getName(), e);
+ return null;
+ }
+ }
+
+ /**
+ *
+ */
+ public static String globalLink()
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ BaseController bc = (BaseController) fc.getApplication().
+ getVariableResolver().
+ resolveVariable(fc,"shared");
+ return outputLink(bc.getLinks().get("category").toString(),true);
+ }
+
+ /**
+ *
+ */
+ public static String categoryLink(String categoryId)
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ BaseController bc = (BaseController) fc.getApplication().
+ getVariableResolver().
+ resolveVariable(fc,"shared");
+ return outputLink(bc.getLinks().get("category").toString(),true) +"&"+ Constants.p_categoryId + "=" + categoryId;
+ }
+
+ /**
+ *
+ */
+ public static String forumLink(String forumId)
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ BaseController bc = (BaseController) fc.getApplication().
+ getVariableResolver().
+ resolveVariable(fc,"shared");
+ return outputLink(bc.getLinks().get("forum").toString(),true) +"&"+ Constants.p_forumId + "=" + forumId;
+ }
+
+ /**
+ *
+ */
+ public static String postLink(String postId)
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ BaseController bc = (BaseController) fc.getApplication().
+ getVariableResolver().
+ resolveVariable(fc,"shared");
+ return outputLink(bc.getLinks().get("topic").toString(),true) +"&"+ Constants.p_postId + "=" + postId + "#"+ postId;
+ }
+
+ /**
+ *
+ */
+ public static String topicLink(String topicId)
+ {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ BaseController bc = (BaseController) fc.getApplication().
+ getVariableResolver().
+ resolveVariable(fc,"shared");
+ return outputLink(bc.getLinks().get("topic").toString(),true) +"&"+ Constants.p_topicId + "=" + topicId;
+ }
+
+ /**
+ *
+ */
+ 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;
+ }
+
+ /**
+ * 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();
+
+ if (rreq instanceof RenderRequest)
+ {
+ RenderRequest req = (RenderRequest) rreq;
+ return req.getContextPath()
+ + "/feeds/"
+ + type
+ + "/"
+ + what
+ + (FeedConstants.GLOBAL.equals(what) ? "" : "/"
+ + id.toString());
+ }
+ return null;
+ }
+
+ /**
+ *
+ *
+ */
+ public static void executeNotifications()
+ {
- return url;
- } catch (Exception e) {
- log.error(PortalUtil.class.getName(), e);
- return null;
- }
- }
+ Object responseObj = FacesContext.getCurrentInstance()
+ .getExternalContext().getResponse();
- public static String globalPermlink() {
- return permlink("category");
- }
+ Object requestObj = FacesContext.getCurrentInstance()
+ .getExternalContext().getRequest();
- public static String categoryPermlink(String categoryId) {
- return permlink("category") + Constants.p_categoryId + "=" + categoryId;
- }
+ // Initializing url values
+ String postUrl = "";
+ String replyUrl = "";
- public static String forumPermlink(String forumId) {
- return permlink("forum") + Constants.p_forumId + "=" + forumId;
- }
+ if (requestObj instanceof RenderRequest)
+ {
- public static String postPermlink(String postId) {
- return permlink("topic") + Constants.p_postId + "=" + postId + "#"
- + postId;
- }
+ PortletRequest request = (PortletRequest) requestObj;
- public static String topicPermlink(String topicId) {
- return permlink("topic") + Constants.p_topicId + "=" + topicId;
- }
+ // 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);
- private static String permlink(String type) {
+ if (watchedPostId != null && watchedPostId.trim().length() > 0
+ && watchedType != null && watchedType.trim().length() > 0)
+ {
- Object response = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ // 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;
- String url = "";
+ portletURL = ((RenderResponse) responseObj).createRenderURL();
+ replyUrl = portletURL.toString();
+ replyUrl += "&" + Constants.p_viewId + "=z&"
+ + Constants.p_postId + "=" + 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 += "?";
- }
+ // Generate hostUrl to servlet
+ String hostURL = ((request.isSecure()) ? "https" : "http")
+ + "://"
+ + request.getServerName()
+ + ((request.getServerPort() == 80) ? "" : ":"
+ + request.getServerPort());
- return url;
- }
+ postUrl = hostURL + postUrl;
+ replyUrl = hostURL + replyUrl;
- /**
- * 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();
+ Integer postId = new Integer(watchedPostId);
+ int type = Integer.parseInt(watchedType);
- if (rreq instanceof RenderRequest) {
- RenderRequest req = (RenderRequest) rreq;
+ try
+ {
+ BaseController.getForumsModule().processNotifications(
+ postId, type, postUrl, replyUrl);
+ } catch (Exception e)
+ {
+ JSFUtil.handleException(e);
+ }
+ }
+ }
+ }
- return req.getContextPath()
- + "/feeds/"
- + type
- + "/"
- + what
- + (FeedConstants.GLOBAL.equals(what) ? "" : "/"
- + id.toString());
- }
+ /**
+ *
+ * @param preferenceKey
+ * @return
+ */
+ public static String getPreference(String preferenceKey)
+ {
+ String preference = null;
- return null;
- }
+ Object o = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
+ if (!JSFUtil.isAnonymous() && o instanceof PortletRequest)
+ {
+ PortletRequest request = (PortletRequest) o;
+ PortletPreferences pp = request.getPreferences();
+ preference = pp.getValue(preferenceKey, "");
+ }
- /**
- *
- *
- */
- public static void executeNotifications() {
+ return preference;
+ }
- Object responseObj = FacesContext.getCurrentInstance()
- .getExternalContext().getResponse();
+ /**
+ *
+ *
+ */
+ 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();
+ }
+ }
- Object requestObj = FacesContext.getCurrentInstance()
- .getExternalContext().getRequest();
+ /**
+ * 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();
- // Initializing url values
- String postUrl = "";
- String replyUrl = "";
+ // Get the pattern
+ String pattern = req.getPreferences().getValue("dateformat",
+ ForumsConstants.DEFAULT_DATE_PATTERN);
- if (requestObj instanceof RenderRequest) {
+ // Get the simple date format if it exists
+ SimpleDateFormat sdf = (SimpleDateFormat) FacesContext
+ .getCurrentInstance().getExternalContext().getSessionMap()
+ .get("SDF");
- PortletRequest request = (PortletRequest) requestObj;
+ // Do we have it ?
+ if (sdf == null)
+ {
+ // Create a new one
+ sdf = new SimpleDateFormat(pattern, req.getLocale());
- // 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);
+ // 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;
+ }
+ }
- if (watchedPostId != null && watchedPostId.trim().length() > 0
- && watchedType != null && watchedType.trim().length() > 0) {
+ /**
+ *
+ * @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;
+ }
- // 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 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;
+ }
- portletURL = ((RenderResponse) responseObj).createRenderURL();
- replyUrl = portletURL.toString();
- replyUrl += "&" + Constants.p_viewId + "=z&"
- + Constants.p_postId + "=" + watchedPostId;
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ public static Poster getPoster() throws Exception
+ {
+ Poster poster = null;
- // Generate hostUrl to servlet
- String hostURL = ((request.isSecure()) ? "https" : "http")
- + "://"
- + request.getServerName()
- + ((request.getServerPort() == 80) ? "" : ":"
- + request.getServerPort());
+ if (!JSFUtil.isAnonymous())
+ {
+ User user = PortalUtil.getUser();
- postUrl = hostURL + postUrl;
- replyUrl = hostURL + replyUrl;
+ Long userId = (Long) user.getId();
+ poster = BaseController.getForumsModule().findPosterByUserId(
+ String.valueOf(userId));
- Integer postId = new Integer(watchedPostId);
- int type = Integer.parseInt(watchedType);
+ if (poster == null)
+ {
+ poster = new PosterImpl(userId.toString());
+ }
+ }
- try {
- BaseController.getForumsModule().processNotifications(
- postId, type, postUrl, replyUrl);
- } catch (Exception e) {
- JSFUtil.handleException(e);
- }
- }
- }
- }
+ return poster;
+ }
- /**
- *
- * @param preferenceKey
- * @return
- */
- public static String getPreference(String preferenceKey) {
- String preference = null;
+ /**
+ * Method used for parsing bbcode and return properly formated text of
+ * message.
+ *
+ * @return
+ */
+ public static String formatMessage(String text, boolean allowHTML)
+ {
- Object o = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
- if (!JSFUtil.isAnonymous() && o instanceof PortletRequest) {
- PortletRequest request = (PortletRequest) o;
- PortletPreferences pp = request.getPreferences();
- preference = pp.getValue(preferenceKey, "");
- }
+ try
+ {
+ Object req = FacesContext.getCurrentInstance().getExternalContext()
+ .getRequest();
- return preference;
- }
+ 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 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();
- }
- }
+ }
- /**
- * 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();
+ /**
+ *
+ * @param text
+ * @return
+ */
+ public static String formatTitle(Object req, String text)
+ {
- // Get the pattern
- String pattern = req.getPreferences().getValue("dateformat",
- ForumsConstants.DEFAULT_DATE_PATTERN);
+ 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();
- // Get the simple date format if it exists
- SimpleDateFormat sdf = (SimpleDateFormat) FacesContext
- .getCurrentInstance().getExternalContext().getSessionMap()
- .get("SDF");
+ }
- // Do we have it ?
- if (sdf == null) {
- // Create a new one
- sdf = new SimpleDateFormat(pattern, req.getLocale());
+ /**
+ *
+ * @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)
+ {
- // 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;
- }
- }
+ // 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 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;
- }
+ // 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
- * @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;
- }
+ /**
+ *
+ * @return
+ */
+ public static Poll createPoll()
+ {
+ Poll poll = new PollImpl();
- 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;
- }
+ poll.setTitle("");
+ poll.setCreationDate(new Date());
- /**
- *
- * @return
- * @throws Exception
- */
- public static Poster getPoster() throws Exception {
- Poster poster = null;
+ return poll;
+ }
- if (!JSFUtil.isAnonymous()) {
- User user = PortalUtil.getUser();
+ /**
+ *
+ * @return
+ */
+ public static PollOption createPollOption()
+ {
+ PollOption pollOption = new PollOptionImpl();
+ return pollOption;
+ }
- Long userId = (Long) user.getId();
- poster = BaseController.getForumsModule().findPosterByUserId(
- String.valueOf(userId));
+ /**
+ *
+ * @author sshah
+ *
+ *
+ */
+ public static Message createMessage()
+ {
+ Message message = new MessageImpl();
+ return message;
+ }
- if (poster == null) {
- poster = new PosterImpl(userId.toString());
- }
- }
+ /**
+ *
+ *
+ */
+ public static float getVotePercent(Poll poll, PollOption option)
+ {
+ float votePercent = 0;
- return poster;
- }
+ float votesSum = poll.getVotesSum();
+ if (votesSum > 0)
+ {
+ votePercent = (option.getVotes() / votesSum);
+ }
- /**
- * Method used for parsing bbcode and return properly formated text of
- * message.
- *
- * @return
- */
- public static String formatMessage(String text, boolean allowHTML) {
+ return votePercent;
+ }
- try {
- Object req = FacesContext.getCurrentInstance().getExternalContext()
- .getRequest();
+ /**
+ *
+ *
+ */
+ 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;
+ }
- 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;
- }
+ /**
+ *
+ * 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);
+ }
- /**
- *
- * @param text
- * @return
- */
- public static String formatTitle(Object req, String text) {
-
- 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();
-
- }
-
- /**
- *
- * @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;
- }
-
+ /**
+ *
+ *
+ */
+ 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-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java 2007-07-06 18:43:31 UTC (rev 13180)
@@ -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,364 +37,367 @@
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;
+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);
- // 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;
+ // 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
+ ) {
- 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());
- }
-
- // -------------------------------------------------------------------------------------------------------------------------------------
+ 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-sar/conf/hibernate/setup.txt
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt 2007-07-06 18:38:07 UTC (rev 13179)
+++ labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt 2007-07-06 18:43:31 UTC (rev 13180)
@@ -55,5 +55,5 @@
}
finally
{
- Tools.safeClose(session);
+ session.close();
}
More information about the jboss-svn-commits
mailing list