KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > user > ThreadWebHandler


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ThreadWebHandler.java,v 1.55 2006/04/14 17:05:27 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.55 $
5  * $Date: 2006/04/14 17:05:27 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.user;
42
43 import java.sql.Timestamp JavaDoc;
44 import java.util.*;
45
46 import javax.servlet.http.HttpServletRequest JavaDoc;
47
48 import com.mvnforum.*;
49 import com.mvnforum.auth.*;
50 import com.mvnforum.common.StatisticsUtil;
51 import com.mvnforum.db.*;
52 import com.mvnforum.search.post.DeletePostIndexTask;
53 import com.mvnforum.search.post.PostIndexer;
54 import net.myvietnam.mvncore.exception.*;
55 import net.myvietnam.mvncore.util.*;
56 import net.myvietnam.mvncore.web.GenericRequest;
57 import org.apache.commons.logging.Log;
58 import org.apache.commons.logging.LogFactory;
59
60 public class ThreadWebHandler {
61
62     private static Log log = LogFactory.getLog(ThreadWebHandler.class);
63
64     private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
65
66     public ThreadWebHandler() {
67     }
68
69     public void prepareDelete(GenericRequest request)
70         throws BadInputException, ObjectNotFoundException, DatabaseException,
71         AuthenticationException, AssertionException {
72
73         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
74         MVNForumPermission permission = onlineUser.getPermission();
75
76         // primary key column(s)
77
int threadID = GenericParamUtil.getParameterInt(request, "thread");
78
79         Locale locale = I18nUtil.getLocaleInRequest(request);
80
81         ThreadBean threadBean = null;
82         try {
83             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
84         } catch (ObjectNotFoundException e) {
85             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
86             throw new ObjectNotFoundException(localizedMessage);
87         }
88         int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
89
90         // check constraint
91
int forumID = threadBean.getForumID();
92         try {
93             ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
94         } catch (ObjectNotFoundException e) {
95             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(forumID)});
96             throw new ObjectNotFoundException(localizedMessage);
97         }
98         int logonMemberID = onlineUser.getMemberID();
99         String JavaDoc authorName = threadBean.getMemberName();
100         int authorID = 0;
101         try {
102             authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName);
103         } catch (ObjectNotFoundException e) {
104             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object JavaDoc[] {authorName});
105             throw new ObjectNotFoundException(localizedMessage);
106         }
107         if (permission.canDeletePost(forumID)) {
108             // have permission, just do nothing, that is dont check the max day contraint
109
} else if (logonMemberID == authorID) {// same author
110
// check date here, usually must not older than 7 days
111
Timestamp JavaDoc now = DateUtil.getCurrentGMTTimestamp();
112             Timestamp JavaDoc postDate = threadBean.getThreadCreationDate();
113             int maxDays = MVNForumConfig.getMaxDeleteDays();
114             if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
115                 /** @todo choose a better Exception here */
116                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object JavaDoc[] {new Integer JavaDoc(maxDays)});
117                 throw new BadInputException(localizedMessage);
118                 //throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
119
}
120
121             //Check to make sure that "no reply" for this post
122
if (numberOfPosts > 1) {
123                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.thread_has_reply");
124                 throw new BadInputException(localizedMessage);
125                 //throw new BadInputException("Cannot delete a thread that has reply!");
126
}
127
128             /** @todo check status of this thread */
129             /*
130             if (postBean.getPostStatus() == ?) {
131                 throw new BadInputException("Cannot delete message which is disable.");
132             }*/

133         } else {//not an author, so this user must have Edit Permission
134
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
135
}
136
137         int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
138
139         request.setAttribute("ThreadBean", threadBean);
140         request.setAttribute("NumberOfPosts", new Integer JavaDoc(numberOfPosts));
141         request.setAttribute("NumberOfPendingPosts", new Integer JavaDoc(numberOfPendingPosts));
142     }
143
144     public void processDelete(GenericRequest request)
145         throws BadInputException, ObjectNotFoundException, DatabaseException,
146         AuthenticationException, AssertionException {
147
148         // primary key column(s)
149
Locale locale = I18nUtil.getLocaleInRequest(request);
150
151         int threadID = GenericParamUtil.getParameterInt(request, "thread");
152         ThreadBean threadBean = null;
153         try {
154             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
155         } catch (ObjectNotFoundException e) {
156             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
157             throw new ObjectNotFoundException(localizedMessage);
158         }
159
160         ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
161
162         // now check the password
163
MyUtil.ensureCorrectCurrentPassword(request);
164
165         deleteThread(request, threadBean);
166
167         //now, update the statistics in the forum and member
168
int forumID = threadBean.getForumID();
169         StatisticsUtil.updateForumStatistics(forumID);
170
171         // Clear the cache
172
ThreadCache.getInstance().clear();
173         PostCache.getInstance().clear();// affect mostActiveThreads in Post
174

175         request.setAttribute("ForumID", String.valueOf(forumID));
176     }
177
178     // Note that this method does not update the forum statistics
179
// The caller must call method to update the forum statistics
180
public void deleteThread(GenericRequest request, ThreadBean threadBean)
181         throws BadInputException, ObjectNotFoundException, DatabaseException,
182         AuthenticationException, AssertionException {
183
184         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
185         MVNForumPermission permission = onlineUser.getPermission();
186
187         // user must have been authenticated before he can delete
188
permission.ensureIsAuthenticated();
189
190         // primary key column(s)
191
int threadID = threadBean.getThreadID();
192
193         Locale locale = I18nUtil.getLocaleInRequest(request);
194
195         // now, check the permission
196
int forumID = threadBean.getForumID();
197         int logonMemberID = onlineUser.getMemberID();
198         String JavaDoc authorName = threadBean.getMemberName();
199         int authorID = 0;
200         try {
201             authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName);
202         } catch (ObjectNotFoundException e) {
203             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object JavaDoc[] {authorName});
204             throw new ObjectNotFoundException(localizedMessage);
205         }
206         if (permission.canDeletePost(forumID)) {
207             // have permission, just do nothing, that is dont check the max day contraint
208
} else if (logonMemberID == authorID) {// same author
209
// check date here, usually must not older than 7 days
210
Timestamp JavaDoc now = DateUtil.getCurrentGMTTimestamp();
211             Timestamp JavaDoc postDate = threadBean.getThreadCreationDate();
212             int maxDays = MVNForumConfig.getMaxDeleteDays();
213             if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
214                 /** @todo choose a better Exception here */
215                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object JavaDoc[] {new Integer JavaDoc(maxDays)});
216                 throw new BadInputException(localizedMessage);
217                 //throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
218
}
219
220             //Check to make sure that "no reply" for this post
221
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
222             if (numberOfPosts > 1) {
223                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.thread_has_reply");
224                 throw new BadInputException(localizedMessage);
225                 //throw new BadInputException("Cannot delete a thread that has reply!");
226
}
227
228             if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
229                 String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_disabled_thread");
230                 throw new BadInputException(localizedMessage);
231                 //throw new BadInputException("Cannot delete your own disabled thread.");
232
}
233         } else {//not an author, so this user must have Edit Permission
234
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
235
}
236
237         // Delete all attachments in this thread,
238
// we must call this before any attempt to delete the thread
239
// That is, the order when delete is VERY IMPORTANT
240
AttachmentWebHandler.deleteAttachments_inThread(threadID);
241
242         DAOFactory.getFavoriteThreadDAO().delete_inThread(threadID);
243
244         DAOFactory.getWatchDAO().delete_inThread(threadID);
245
246         DAOFactory.getPostDAO().delete_inThread(threadID);
247
248         // now delete the thread, note that we delete it after delete all child objects
249
DAOFactory.getThreadDAO().delete(threadID);
250
251         // now update the search index
252
// @todo : what if the above methods throw exception, then no thread is deleted from index ???
253
PostIndexer.scheduleDeletePostTask(threadID, DeletePostIndexTask.OBJECT_TYPE_THREAD);
254
255         //now, update the statistics in the member
256
StatisticsUtil.updateMemberStatistics(authorID);
257     }
258
259     public void prepareMoveThread(GenericRequest request)
260         throws BadInputException, ObjectNotFoundException, DatabaseException,
261         AuthenticationException, AssertionException {
262
263         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
264         MVNForumPermission permission = onlineUser.getPermission();
265
266         Locale locale = I18nUtil.getLocaleInRequest(request);
267
268         // primary key column(s)
269
int threadID = GenericParamUtil.getParameterInt(request, "thread");
270
271         ThreadBean threadBean = null;
272         try {
273             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
274         } catch (ObjectNotFoundException e) {
275             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
276             throw new ObjectNotFoundException(localizedMessage);
277         }
278
279         ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
280
281         // now, check the permission
282
// @todo: is it the correct permission ???
283
permission.ensureCanDeletePost(threadBean.getForumID());
284
285         int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
286
287         request.setAttribute("ThreadBean", threadBean);
288         request.setAttribute("NumberOfPosts", new Integer JavaDoc(numberOfPosts));
289     }
290
291     public void processMoveThread(GenericRequest request)
292         throws BadInputException, ObjectNotFoundException, DatabaseException,
293         ForeignKeyNotFoundException, AuthenticationException, AssertionException {
294
295         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
296         MVNForumPermission permission = onlineUser.getPermission();
297
298         // user must have been authenticated before he can delete
299
permission.ensureIsAuthenticated();
300
301         Locale locale = I18nUtil.getLocaleInRequest(request);
302
303         // primary key column(s)
304
int threadID = GenericParamUtil.getParameterInt(request, "thread");
305
306         // now, check the permission
307
ThreadBean threadBean = null;
308         try {
309             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
310         } catch (ObjectNotFoundException e) {
311             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
312             throw new ObjectNotFoundException(localizedMessage);
313         }
314         int forumID = threadBean.getForumID();
315         permission.ensureCanDeletePost(forumID);
316
317         ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
318
319         // now check the password
320
MyUtil.ensureCorrectCurrentPassword(request);
321
322         int destForumID = GenericParamUtil.getParameterInt(request, "destforum");
323
324         // make sure that we dont move to the same forum (meaningless)
325
if (destForumID == forumID) {
326             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_move_thread_to_the_same_forum");
327             throw new BadInputException(localizedMessage);
328             //throw new AssertionException("Cannot move thread to the same forum.");
329
}
330
331         // now make sure that the dest forum is existed
332
ForumCache.getInstance().getBean(destForumID);
333
334         DAOFactory.getThreadDAO().updateForumID(threadID, destForumID);
335         DAOFactory.getPostDAO().update_ForumID_inThread(threadID, destForumID);
336         DAOFactory.getFavoriteThreadDAO().update_ForumID_inThread(threadID, destForumID);
337
338         //now, update the statistics in the source forum and dest forum
339
StatisticsUtil.updateForumStatistics(forumID);
340         StatisticsUtil.updateForumStatistics(destForumID);
341
342         // now update the search index
343
// @todo : what if the above methods throw exception, then no thread is deleted from index ???
344
PostIndexer.scheduleUpdateThreadTask(threadID);
345
346         // Clear the cache
347
ThreadCache.getInstance().clear();
348         PostCache.getInstance().clear();// affect mostActiveThreads in Post
349

350         request.setAttribute("ForumID", String.valueOf(forumID));
351     }
352
353     public void prepareEditThreadStatus(GenericRequest request)
354         throws BadInputException, ObjectNotFoundException, DatabaseException,
355         AuthenticationException, AssertionException {
356
357         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
358         MVNForumPermission permission = onlineUser.getPermission();
359
360         Locale locale = I18nUtil.getLocaleInRequest(request);
361
362         // primary key column(s)
363
int threadID = GenericParamUtil.getParameterInt(request, "thread");
364
365         ThreadBean threadBean = null;
366         try {
367             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
368         } catch (ObjectNotFoundException e) {
369             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
370             throw new ObjectNotFoundException(localizedMessage);
371         }
372
373         ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
374
375         // now, check the permission
376
permission.ensureCanModerateThread(threadBean.getForumID());
377
378         int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
379
380         int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
381
382         request.setAttribute("ThreadBean", threadBean);
383         request.setAttribute("NumberOfPosts", new Integer JavaDoc(numberOfPosts));
384         request.setAttribute("NumberOfPendingPosts", new Integer JavaDoc(numberOfPendingPosts));
385     }
386
387     public void processEditThreadStatus(GenericRequest request)
388         throws BadInputException, ObjectNotFoundException, DatabaseException,
389         AuthenticationException, AssertionException {
390
391         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
392         MVNForumPermission permission = onlineUser.getPermission();
393
394         // user must have been authenticated before he can edit thread status
395
permission.ensureIsAuthenticated();
396
397         Locale locale = I18nUtil.getLocaleInRequest(request);
398
399         // primary key column(s)
400
int threadID = GenericParamUtil.getParameterInt(request, "thread");
401
402         // now, check the permission
403
ThreadBean threadBean = null;
404         try {
405             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
406         } catch (ObjectNotFoundException e) {
407             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
408             throw new ObjectNotFoundException(localizedMessage);
409         }
410         int forumID = threadBean.getForumID();
411
412         ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
413
414         permission.ensureCanModerateThread(forumID);
415
416         // now check the password
417
MyUtil.ensureCorrectCurrentPassword(request);
418
419         int threadStatus = GenericParamUtil.getParameterInt(request, "ThreadStatus");
420
421         ThreadBean.validateThreadStatus(threadStatus);
422
423         // now if change from Disable to Enable, update the lastpostdate so
424
// that the Watch will see this thread as a new thread
425
if ((threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) &&
426             (threadStatus != ThreadBean.THREAD_STATUS_DISABLED)) {
427             Timestamp JavaDoc now = DateUtil.getCurrentGMTTimestamp();
428             DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
429         }
430
431         DAOFactory.getThreadDAO().updateThreadStatus(threadID, threadStatus);
432         StatisticsUtil.updateForumStatistics(forumID);
433         //@todo: should update other info ???
434

435         // Clear the cache
436
ThreadCache.getInstance().clear();
437         PostCache.getInstance().clear();// affect mostActiveThreads in Post
438

439         request.setAttribute("ThreadID", String.valueOf(threadID));
440         request.setAttribute("ForumID", String.valueOf(forumID));
441     }
442
443     public void prepareEditThreadType(GenericRequest request)
444         throws BadInputException, ObjectNotFoundException, DatabaseException,
445         AuthenticationException, AssertionException {
446
447         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
448         MVNForumPermission permission = onlineUser.getPermission();
449
450         Locale locale = I18nUtil.getLocaleInRequest(request);
451
452         // primary key column(s)
453
int threadID = GenericParamUtil.getParameterInt(request, "thread");
454
455         ThreadBean threadBean = null;
456         try {
457             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
458         } catch (ObjectNotFoundException e) {
459             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
460             throw new ObjectNotFoundException(localizedMessage);
461         }
462
463         ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
464
465         // now, check the permission
466
permission.ensureCanModerateThread(threadBean.getForumID());
467
468         int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
469
470         int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
471
472         request.setAttribute("ThreadBean", threadBean);
473         request.setAttribute("NumberOfPosts", new Integer JavaDoc(numberOfPosts));
474         request.setAttribute("NumberOfPendingPosts", new Integer JavaDoc(numberOfPendingPosts));
475     }
476
477     public void processEditThreadType(GenericRequest request)
478         throws BadInputException, ObjectNotFoundException, DatabaseException,
479         AuthenticationException, AssertionException {
480
481         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
482         MVNForumPermission permission = onlineUser.getPermission();
483
484         // user must have been authenticated before he can edit thread status
485
permission.ensureIsAuthenticated();
486
487         Locale locale = I18nUtil.getLocaleInRequest(request);
488
489         // primary key column(s)
490
int threadID = GenericParamUtil.getParameterInt(request, "thread");
491         int threadType = GenericParamUtil.getParameterUnsignedInt(request, "ThreadType", ThreadBean.THREAD_TYPE_DEFAULT);
492
493         ThreadBean threadBean = null;
494         try {
495             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
496         } catch (ObjectNotFoundException e) {
497             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
498             throw new ObjectNotFoundException(localizedMessage);
499         }
500         int forumID = threadBean.getForumID();
501
502         ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
503
504         if (threadType > ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT /* 3 */) {
505             throw new BadInputException("Not support this thread type");
506         }
507
508         if ((threadType == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT) ||
509             (threadBean.getThreadType() == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT)) {
510             permission.ensureCanAdminSystem();
511         } else {
512             permission.ensureCanModerateThread(forumID);
513         }
514
515         // now check the password
516
MyUtil.ensureCorrectCurrentPassword(request);
517
518         DAOFactory.getThreadDAO().updateThreadType(threadID, threadType);
519         //@todo: should update other info ???
520

521         // Clear the cache
522
ThreadCache.getInstance().clear();
523         PostCache.getInstance().clear();// affect mostActiveThreads in Post
524

525         request.setAttribute("ThreadID", String.valueOf(threadID));
526         request.setAttribute("ForumID", String.valueOf(forumID));
527     }
528
529     public void prepareList_limit(GenericRequest request)
530         throws BadInputException, ObjectNotFoundException, DatabaseException,
531         AssertionException, AuthenticationException {
532
533         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
534         MVNForumPermission permission = onlineUser.getPermission();
535
536         Locale locale = I18nUtil.getLocaleInRequest(request);
537
538         int forumID = GenericParamUtil.getParameterInt(request, "forum");
539
540         // make sure there is the forum
541
// will throw an BadInputException if there is not this forum
542
ForumBean forumBean = ForumCache.getInstance().getBean(forumID);
543
544         forumBean.ensureNotDisabledForum();
545
546         // make sure user can read post in this forum
547
permission.ensureCanReadPost(forumID);
548
549         // for sort and order stuff
550
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
551         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
552         if (sort.length() == 0) sort = "ThreadLastPostDate";
553         if (order.length()== 0) order = "DESC";
554
555         int postsPerPage = onlineUser.getPostsPerPage();
556         int offset = 0;
557         try {
558             offset = GenericParamUtil.getParameterInt(request, "offset");
559         } catch (BadInputException e) {
560             // do nothing
561
}
562
563         int totalThreads = ThreadCache.getInstance().getNumberOfEnableThreads_inForum(forumID);
564         int totalNormalThreads = ThreadCache.getInstance().getNumberOfNormalEnableThreads_inForum(forumID);
565         if (offset > totalNormalThreads) {
566             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
567             throw new BadInputException(localizedMessage);
568             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
569
}
570
571         Collection threadBeans = ThreadCache.getInstance().getNormalEnableThreads_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);
572
573         // the correct value is the enable posts - disable threads, so we could get directly from the ForumBean
574
//int totalPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);
575
int totalPosts = forumBean.getForumPostCount();
576
577         int pendingThreadCount = 0;
578         int threadsWithPendingPostsCount = 0;
579         if (permission.canModerateThread(forumID)) {
580             pendingThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
581             threadsWithPendingPostsCount = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID);
582         }
583
584         Collection allThreadBeans = new ArrayList();
585
586         Collection globalAnnounces = ThreadCache.getInstance().getEnableGlobalAnnouncements();
587         allThreadBeans.addAll(globalAnnounces);
588         Collection announcements = ThreadCache.getInstance().getEnableForumAnnouncements_inForum(forumID);
589         allThreadBeans.addAll(announcements);
590         if (offset == 0) {
591             Collection stickies = ThreadCache.getInstance().getEnableStickies_inForum(forumID);
592             allThreadBeans.addAll(stickies);
593         }
594         allThreadBeans.addAll(threadBeans);
595
596         request.setAttribute("ThreadBeans", allThreadBeans);
597         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
598         request.setAttribute("TotalNormalThreads", new Integer JavaDoc(totalNormalThreads));
599         request.setAttribute("TotalPosts", new Integer JavaDoc(totalPosts));
600         request.setAttribute("PendingThreadCount", new Integer JavaDoc(pendingThreadCount));
601         request.setAttribute("ThreadsWithPendingPostsCount", new Integer JavaDoc(threadsWithPendingPostsCount));
602     }
603
604     public void prepareListRecentThreads_limit(GenericRequest request)
605         throws DatabaseException, AssertionException, BadInputException,
606         AuthenticationException, ObjectNotFoundException, DatabaseException {
607
608         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
609         MVNForumPermission permission = onlineUser.getPermission();
610
611         Locale locale = I18nUtil.getLocaleInRequest(request);
612
613         // for sort and order stuff
614
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
615         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
616         if (sort.length() == 0) sort = "ThreadLastPostDate";
617         if (order.length()== 0) order = "DESC";
618
619         int postsPerPage = onlineUser.getPostsPerPage();
620         int offset = 0;
621         try {
622             offset = GenericParamUtil.getParameterInt(request, "offset");
623         } catch (BadInputException e) {
624             // do nothing
625
}
626
627         int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreads();
628         if (offset > totalThreads) {
629             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
630             throw new BadInputException(localizedMessage);
631             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
632
}
633
634         Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(offset, postsPerPage, sort, order);
635
636         // now remove thread that current user does not have permission
637
for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
638             ThreadBean threadBean = (ThreadBean)iterator.next();
639             int currentForumID = threadBean.getForumID();
640             if (permission.canReadPost(currentForumID) == false) {
641                 iterator.remove();
642             } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
643                 iterator.remove();
644             }
645         }
646
647         request.setAttribute("ThreadBeans", threadBeans);
648         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
649     }
650
651     public void prepareListRecentDisabledThreads_limit(GenericRequest request)
652         throws DatabaseException, AssertionException, BadInputException, AuthenticationException, ObjectNotFoundException {
653
654         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
655         MVNForumPermission permission = onlineUser.getPermission();
656
657         // user must have been authenticated before he can view pending/disabled threads
658
permission.ensureIsAuthenticated();
659         permission.ensureCanModerateThreadInAnyForum();
660
661         Locale locale = I18nUtil.getLocaleInRequest(request);
662
663         // for sort and order stuff
664
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
665         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
666         if (sort.length() == 0) sort = "ThreadLastPostDate";
667         if (order.length()== 0) order = "DESC";
668
669         int postsPerPage = onlineUser.getPostsPerPage();
670         int offset = 0;
671         try {
672             offset = GenericParamUtil.getParameterInt(request, "offset");
673         } catch (BadInputException e) {
674             // do nothing
675
}
676
677         int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads();
678         if (offset > totalThreads) {
679             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
680             throw new BadInputException(localizedMessage);
681             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
682
}
683
684         Collection threadBeans = DAOFactory.getThreadDAO().getDisableBeans_withSortSupport_limit(offset, postsPerPage, sort, order);
685
686         // now remove thread that current user does not have permission
687
for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
688             ThreadBean threadBean = (ThreadBean)iterator.next();
689             int currentForumID = threadBean.getForumID();
690             if (permission.canModerateThread(currentForumID) == false) {
691                 iterator.remove();
692             } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
693                 iterator.remove();
694             }
695         }
696
697         request.setAttribute("ThreadBeans", threadBeans);
698         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
699     }
700
701     public void prepareListDisabledThreads_limit_xml(GenericRequest request)
702         throws DatabaseException, AssertionException, AuthenticationException, ObjectNotFoundException {
703
704         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
705         MVNForumPermission permission = onlineUser.getPermission();
706
707         // user must have been authenticated before he can view pending/disabled threads
708
permission.ensureIsAuthenticated();
709         permission.ensureCanModerateThreadInAnyForum();
710
711         Collection pendingThreadBeans = DAOFactory.getThreadDAO().getDisableBeans_withSortSupport_limit(0, 10000, "ThreadLastPostDate", "DESC");
712         // now remove thread that current user does not have permission
713
for (Iterator iterator = pendingThreadBeans.iterator(); iterator.hasNext(); ) {
714             ThreadBean threadBean = (ThreadBean)iterator.next();
715             if (permission.canModerateThread(threadBean.getForumID()) == false) {
716                 iterator.remove();
717             }
718         }
719
720         Collection threadWithPendingPostsBeans = DAOFactory.getThreadDAO().getEnableThreadsWithPendingPosts_withSortSupport_limit(0, 10000, "ForumID", "DESC");
721         for (Iterator iterator = threadWithPendingPostsBeans.iterator(); iterator.hasNext(); ) {
722             ThreadBean threadBean = (ThreadBean)iterator.next();
723             if (permission.canModerateThread(threadBean.getForumID()) == false) {
724                 iterator.remove();
725             } else {
726                 Collection pendingPosts = DAOFactory.getPostDAO().getDisablePosts_inThread_limit(threadBean.getThreadID(), 0, 10000);
727                 threadBean.setPendingPosts(pendingPosts);
728             }
729         }
730
731         request.setAttribute("PendingThreadBeans", pendingThreadBeans);
732         request.setAttribute("ThreadWithPendingPostsBeans", threadWithPendingPostsBeans);
733     }
734
735     public void prepareListRecentEnableThreadsWithPendingPosts_limit(GenericRequest request)
736         throws DatabaseException, AssertionException, BadInputException, AuthenticationException, ObjectNotFoundException {
737
738         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
739         MVNForumPermission permission = onlineUser.getPermission();
740
741         // user must have been authenticated before he can view enable threads with pending posts
742
permission.ensureIsAuthenticated();
743         permission.ensureCanModerateThreadInAnyForum();
744
745         Locale locale = I18nUtil.getLocaleInRequest(request);
746
747         // for sort and order stuff
748
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
749         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
750         if (sort.length() == 0) sort = "ThreadLastPostDate";
751         if (order.length()== 0) order = "DESC";
752
753         int postsPerPage = onlineUser.getPostsPerPage();
754         int offset = 0;
755         try {
756             offset = GenericParamUtil.getParameterInt(request, "offset");
757         } catch (BadInputException e) {
758             // do nothing
759
}
760
761         int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts();
762         if (offset > totalThreads) {
763             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
764             throw new BadInputException(localizedMessage);
765             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
766
}
767
768         Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreadsWithPendingPosts_withSortSupport_limit(offset, postsPerPage, sort, order);
769
770         // now remove thread that current user does not have permission
771
for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
772             ThreadBean threadBean = (ThreadBean)iterator.next();
773             int currentForumID = threadBean.getForumID();
774             if (permission.canModerateThread(currentForumID) == false) {
775                 iterator.remove();
776             } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
777                 iterator.remove();
778             }
779         }
780
781         request.setAttribute("ThreadBeans", threadBeans);
782         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
783     }
784
785     public void prepareListEnableThreadsWithPendingPosts_inForum_limit(GenericRequest request)
786         throws DatabaseException, AssertionException, BadInputException, AuthenticationException, ObjectNotFoundException {
787
788         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
789         MVNForumPermission permission = onlineUser.getPermission();
790
791         // user must have been authenticated before he can view enable threads with pending posts
792
permission.ensureIsAuthenticated();
793
794         int forumID = GenericParamUtil.getParameterInt(request, "forum");
795         permission.ensureCanModerateThread(forumID);
796
797         ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
798
799         Locale locale = I18nUtil.getLocaleInRequest(request);
800
801         // for sort and order stuff
802
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
803         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
804         if (sort.length() == 0) sort = "ThreadLastPostDate";
805         if (order.length()== 0) order = "DESC";
806
807         int postsPerPage = onlineUser.getPostsPerPage();
808         int offset = 0;
809         try {
810             offset = GenericParamUtil.getParameterInt(request, "offset");
811         } catch (BadInputException e) {
812             // do nothing
813
}
814
815         int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID);
816         if (offset > totalThreads) {
817             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
818             throw new BadInputException(localizedMessage);
819             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
820
}
821
822         Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreadsWithPendingPosts_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);
823
824         request.setAttribute("ThreadBeans", threadBeans);
825         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
826     }
827
828     public void prepareModerationControlPanel(GenericRequest request)
829         throws DatabaseException, DatabaseException, AssertionException, DatabaseException, AuthenticationException {
830
831         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
832         MVNForumPermission permission = onlineUser.getPermission();
833
834         // user must have been authenticated before he can view enable threads with pending posts
835
permission.ensureIsAuthenticated();
836         permission.ensureCanModerateThreadInAnyForum();
837
838         Collection forumBeans = ForumCache.getInstance().getBeans();
839         for (Iterator iter = forumBeans.iterator(); iter.hasNext(); ) {
840             ForumBean forumBean = (ForumBean)iter.next();
841             int forumID = forumBean.getForumID();
842
843             int pendingThreadCount = 0;
844             int threadsWithPendingPostsCount = 0;
845             int pendingPostCount = 0;
846
847             if (permission.canModerateThread(forumID) && (forumBean.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED) ) {
848                 pendingThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
849                 threadsWithPendingPostsCount = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID);
850                 pendingPostCount = DAOFactory.getPostDAO().getNumberOfDisablePosts_inForum(forumID);
851             }
852
853             // note that if user does not have permission on this forum, then the value is 0
854
forumBean.setPendingThreadCount(pendingThreadCount);
855             forumBean.setThreadsWithPendingPostsCount(threadsWithPendingPostsCount);
856             forumBean.setPendingPostCount(pendingPostCount);
857         }
858
859         int pendingThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableThreads();
860         int threadsWithPendingPostsCount = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts();
861
862         // Note that because this forumBeans is a new instance
863
// we have to put it in session instead of get it again from the ForumCache
864
request.setAttribute("ForumBeans", forumBeans);
865         request.setAttribute("PendingThreadCount", new Integer JavaDoc(pendingThreadCount));
866         request.setAttribute("ThreadsWithPendingPostsCount", new Integer JavaDoc(threadsWithPendingPostsCount));
867     }
868
869     public void prepareModeratePendingThreads_inForum_limit(GenericRequest request)
870         throws AssertionException, DatabaseException, AuthenticationException, BadInputException,
871         DatabaseException, ObjectNotFoundException {
872
873         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
874         MVNForumPermission permission = onlineUser.getPermission();
875
876         // user must have been authenticated before he can view pending/disabled threads
877
permission.ensureIsAuthenticated();
878
879         int forumID = GenericParamUtil.getParameterInt(request, "forum");
880
881         // make sure there is the forum
882
// will throw an BadInputException if there is not this forum
883
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
884         permission.ensureCanModerateThread(forumID);
885
886         Locale locale = I18nUtil.getLocaleInRequest(request);
887
888         // for sort and order stuff
889
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
890         String JavaDoc order = GenericParamUtil.getParameter(request, "order");
891         if (sort.length() == 0) sort = "ThreadLastPostDate";
892         if (order.length()== 0) order = "DESC";
893
894         int postsPerPage = onlineUser.getPostsPerPage();
895         int offset = 0;
896         try {
897             offset = GenericParamUtil.getParameterInt(request, "offset");
898         } catch (BadInputException e) {
899             // do nothing
900
}
901
902         int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
903         if (offset > totalThreads) {
904             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
905             throw new BadInputException(localizedMessage);
906             //throw new BadInputException("The offset is not allowed to be greater than total rows.");
907
}
908
909         Collection threadBeans = DAOFactory.getThreadDAO().getDisableThreads_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);
910         Collection firstPostBeans = new ArrayList();
911
912         for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
913             ThreadBean threadBean = (ThreadBean)iterator.next();
914             PostBean postBean = DAOFactory.getPostDAO().getFirstPost_inThread(threadBean.getThreadID());
915             firstPostBeans.add(postBean);
916
917             MemberBean memberBean = null;
918             if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
919                 // Use cache for maximum performance
920
memberBean = MemberCache.getInstance().getMember_forPublic(postBean.getMemberID());
921             }
922             postBean.setMemberBean(memberBean);
923
924             int postAttachCount = postBean.getPostAttachCount();
925             if ((postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) {
926                 int postID = postBean.getPostID();
927                 Collection attachBeans = DAOFactory.getAttachmentDAO().getAttachments_inPost(postID);
928                 int actualAttachCount = attachBeans.size();
929
930                 // now check if the attachCount in talbe Post equals to the actual attachCount in table Attachment
931
if (postAttachCount != actualAttachCount) {
932                     if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) {
933                         String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count");
934                         throw new AssertionException(localizedMessage);
935                         //throw new AssertionException("AssertionException: Serious error: cannot process Attachment Count in table Attachment");
936
}
937                     log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " +
938                             postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount);
939                     DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount);
940                 }
941                 if (actualAttachCount > 0) {
942                     postBean.setAttachmentBeans(attachBeans);
943                 }
944             }
945         }
946
947         request.setAttribute("FirstPostBeans", firstPostBeans);
948         request.setAttribute("ThreadBeans", threadBeans);
949         request.setAttribute("TotalThreads", new Integer JavaDoc(totalThreads));
950     }
951
952     public void processModeratePendingThreads(GenericRequest request)
953         throws AssertionException, DatabaseException, AuthenticationException,
954         BadInputException, DatabaseException, ObjectNotFoundException {
955
956         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
957         MVNForumPermission permission = onlineUser.getPermission();
958
959         // user must have been authenticated before he can moderate pending/disabled threads
960
permission.ensureIsAuthenticated();
961
962         Locale locale = I18nUtil.getLocaleInRequest(request);
963
964         // check normal permission, note that we dont check
965
// permission on a forumID because we allow moderate posts
966
// in multiple forums even if the web interface does not support it
967
int forumID = -1;
968         try {
969             forumID = GenericParamUtil.getParameterInt(request, "forum");
970             ForumCache.getInstance().getBean(forumID);// check valid forumID
971
permission.ensureCanModerateThread(forumID);
972
973             ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
974         } catch (BadInputException ex) {
975             // just ignore, in case of use customized client
976
}
977         permission.ensureCanModerateThreadInAnyForum();
978
979         try {
980             String JavaDoc prefix = "modthreadaction_";
981             for (Enumeration enumeration = request.getParameterNames(); enumeration.hasMoreElements(); ) {
982                 String JavaDoc param = (String JavaDoc) enumeration.nextElement();
983                 if (param.startsWith(prefix)) {
984                     String JavaDoc modValue = GenericParamUtil.getParameter(request, param, true);
985                     String JavaDoc strThreadID = param.substring(prefix.length());
986                     int threadID = Integer.parseInt(strThreadID);
987                     if (modValue.equals("approve")) {
988                         ThreadBean threadBean = null;
989                         try {
990                             threadBean = DAOFactory.getThreadDAO().getThread(threadID);
991                         } catch (ObjectNotFoundException e) {
992                             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
993                             throw new ObjectNotFoundException(localizedMessage);
994                         }
995                         int currentForumID = threadBean.getForumID();
996                         permission.ensureCanModerateThread(currentForumID);
997                         DAOFactory.getThreadDAO().updateThreadStatus(threadID, ThreadBean.THREAD_STATUS_DEFAULT);
998
999                         // now if change from Disable to Enable, update the lastpostdate so
1000
// that the Watch will see this thread as a new thread
1001
if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED ) {
1002                            Timestamp JavaDoc now = DateUtil.getCurrentGMTTimestamp();
1003                            DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
1004                        }
1005                    } else if (modValue.equals("delete")) {
1006                        ThreadBean threadBean = null;
1007                        try {
1008                            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
1009                        } catch (ObjectNotFoundException e) {
1010                            String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object JavaDoc[] {new Integer JavaDoc(threadID)});
1011                            throw new ObjectNotFoundException(localizedMessage);
1012                        }
1013                        deleteThread(request, threadBean);
1014                    } else {
1015                        // it means ignore, do nothing
1016
}
1017                }
1018            }
1019        } finally {
1020            // now update the forum statistics
1021
if (forumID != -1) {
1022                StatisticsUtil.updateForumStatistics(forumID);
1023            }
1024        }
1025
1026        // Now clear the cache
1027
PostCache.getInstance().clear();
1028        ThreadCache.getInstance().clear();
1029
1030        request.setAttribute("ForumID", String.valueOf(forumID));
1031    }
1032
1033    public void prepareList_inFavorite(GenericRequest request)
1034        throws DatabaseException, AssertionException, AuthenticationException, ObjectNotFoundException {
1035
1036        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
1037        MVNForumPermission permission = onlineUser.getPermission();
1038        permission.ensureIsAuthenticated();
1039
1040        int memberID = onlineUser.getMemberID();
1041
1042        Collection threadBeans = DAOFactory.getThreadDAO().getThreads_inFavorite_inMember(memberID);
1043
1044        //remove threads that current user dont have permission
1045
for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
1046            ThreadBean threadBean = (ThreadBean)iter.next();
1047            int currentForumID = threadBean.getForumID();
1048            if (permission.canReadPost(currentForumID) == false) {
1049                iter.remove();
1050            } else if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
1051                if (permission.canModerateThread(currentForumID) == false) {
1052                    iter.remove();
1053                }
1054            } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1055                iter.remove();
1056            }
1057        }
1058        int max = MVNForumConfig.getMaxFavoriteThread();
1059        int favoriteThreadCount = threadBeans.size();
1060        double ratio = 0;
1061        if (max == 0) {
1062            ratio = 1.0;
1063        } else {
1064            ratio = (double)favoriteThreadCount / max;
1065        }
1066        request.setAttribute("QuotaRatio", new Double JavaDoc(ratio * 100));
1067        request.setAttribute("ThreadBeans", threadBeans);
1068    }
1069
1070    public void prepareRSSSummary(GenericRequest request)
1071        throws DatabaseException {
1072
1073        // for sort and order stuff
1074
String JavaDoc sort = GenericParamUtil.getParameter(request, "sort");
1075        String JavaDoc order = GenericParamUtil.getParameter(request, "order");
1076        if (sort.length() == 0) sort = "ThreadLastPostDate";
1077        if (order.length()== 0) order = "DESC";
1078
1079        // call this to check the parameter sort and order
1080
DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(0/*offset*/, 1/*rows*/, sort, order);
1081    }
1082
1083    void prepareListRSS(HttpServletRequest JavaDoc request)
1084        throws DatabaseException, AssertionException,
1085        AuthenticationException, ObjectNotFoundException {
1086
1087        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
1088        MVNForumPermission permission = onlineUser.getPermission();
1089
1090        // for sort and order stuff
1091
String JavaDoc sort = ParamUtil.getParameter(request, "sort");
1092        String JavaDoc order = ParamUtil.getParameter(request, "order");
1093        if (sort.length() == 0) sort = "ThreadLastPostDate";
1094        if (order.length()== 0) order = "DESC";
1095
1096        int offset = 0;// offset MUST always equals 0, please dont change !!!
1097
int rows = MVNForumConfig.getRowsPerRSS();
1098        try {
1099            rows = ParamUtil.getParameterInt(request, "rows");
1100            if (rows <= 0) rows = MVNForumConfig.getRowsPerRSS();
1101        } catch (Exception JavaDoc ex) {
1102            //just ignore
1103
}
1104
1105        // now find that user want global/category/forum RSS
1106
int forumID = -1;
1107        int categoryID = -1;
1108
1109        try {
1110            forumID = ParamUtil.getParameterInt(request, "forum");
1111        } catch (Exception JavaDoc ex) {
1112            try {
1113                categoryID = ParamUtil.getParameterInt(request, "category");
1114            } catch (Exception JavaDoc ex1) { }
1115        }
1116
1117        Collection threadBeans = null;
1118        if (forumID > 0) {
1119            if (permission.canReadPost(forumID)) {
1120                threadBeans = DAOFactory.getThreadDAO().getAllEnableThreads_inForum_withSortSupport_limit(forumID, offset, rows, sort, order);
1121            } else {
1122                // dont have permission on this forum, just create empty Collection
1123
threadBeans = new ArrayList();
1124            }
1125        } else if (categoryID > 0) {
1126            //@todo implement later
1127
} else {// global RSS
1128
threadBeans = DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(offset, rows, sort, order);
1129
1130            //remove threads that current user dont have permission
1131
for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
1132                ThreadBean threadBean = (ThreadBean)iter.next();
1133                int currentForumID = threadBean.getForumID();
1134                if (permission.canReadPost(currentForumID) == false) {
1135                    iter.remove();
1136                } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1137                    iter.remove();
1138                }
1139            }
1140        }
1141
1142        request.setAttribute("ThreadBeans", threadBeans);
1143        request.setAttribute("ForumID", new Integer JavaDoc(forumID));
1144        request.setAttribute("CategoryID", new Integer JavaDoc(categoryID));
1145    }
1146
1147}
1148
Popular Tags