1 41 package com.mvnforum.user; 42 43 import java.sql.Timestamp ; 44 import java.util.*; 45 46 import javax.servlet.http.HttpServletRequest ; 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 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 86 throw new ObjectNotFoundException(localizedMessage); 87 } 88 int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID); 89 90 int forumID = threadBean.getForumID(); 92 try { 93 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 94 } catch (ObjectNotFoundException e) { 95 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 96 throw new ObjectNotFoundException(localizedMessage); 97 } 98 int logonMemberID = onlineUser.getMemberID(); 99 String authorName = threadBean.getMemberName(); 100 int authorID = 0; 101 try { 102 authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName); 103 } catch (ObjectNotFoundException e) { 104 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object [] {authorName}); 105 throw new ObjectNotFoundException(localizedMessage); 106 } 107 if (permission.canDeletePost(forumID)) { 108 } else if (logonMemberID == authorID) { Timestamp now = DateUtil.getCurrentGMTTimestamp(); 112 Timestamp postDate = threadBean.getThreadCreationDate(); 113 int maxDays = MVNForumConfig.getMaxDeleteDays(); 114 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 115 116 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object [] {new Integer (maxDays)}); 117 throw new BadInputException(localizedMessage); 118 } 120 121 if (numberOfPosts > 1) { 123 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.thread_has_reply"); 124 throw new BadInputException(localizedMessage); 125 } 127 128 129 133 } else { permission.ensureCanDeletePost(forumID); } 136 137 int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID); 138 139 request.setAttribute("ThreadBean", threadBean); 140 request.setAttribute("NumberOfPosts", new Integer (numberOfPosts)); 141 request.setAttribute("NumberOfPendingPosts", new Integer (numberOfPendingPosts)); 142 } 143 144 public void processDelete(GenericRequest request) 145 throws BadInputException, ObjectNotFoundException, DatabaseException, 146 AuthenticationException, AssertionException { 147 148 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 157 throw new ObjectNotFoundException(localizedMessage); 158 } 159 160 ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum(); 161 162 MyUtil.ensureCorrectCurrentPassword(request); 164 165 deleteThread(request, threadBean); 166 167 int forumID = threadBean.getForumID(); 169 StatisticsUtil.updateForumStatistics(forumID); 170 171 ThreadCache.getInstance().clear(); 173 PostCache.getInstance().clear(); 175 request.setAttribute("ForumID", String.valueOf(forumID)); 176 } 177 178 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 permission.ensureIsAuthenticated(); 189 190 int threadID = threadBean.getThreadID(); 192 193 Locale locale = I18nUtil.getLocaleInRequest(request); 194 195 int forumID = threadBean.getForumID(); 197 int logonMemberID = onlineUser.getMemberID(); 198 String authorName = threadBean.getMemberName(); 199 int authorID = 0; 200 try { 201 authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName); 202 } catch (ObjectNotFoundException e) { 203 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object [] {authorName}); 204 throw new ObjectNotFoundException(localizedMessage); 205 } 206 if (permission.canDeletePost(forumID)) { 207 } else if (logonMemberID == authorID) { Timestamp now = DateUtil.getCurrentGMTTimestamp(); 211 Timestamp postDate = threadBean.getThreadCreationDate(); 212 int maxDays = MVNForumConfig.getMaxDeleteDays(); 213 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 214 215 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object [] {new Integer (maxDays)}); 216 throw new BadInputException(localizedMessage); 217 } 219 220 int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID); 222 if (numberOfPosts > 1) { 223 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.thread_has_reply"); 224 throw new BadInputException(localizedMessage); 225 } 227 228 if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) { 229 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_disabled_thread"); 230 throw new BadInputException(localizedMessage); 231 } 233 } else { permission.ensureCanDeletePost(forumID); } 236 237 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 DAOFactory.getThreadDAO().delete(threadID); 250 251 PostIndexer.scheduleDeletePostTask(threadID, DeletePostIndexTask.OBJECT_TYPE_THREAD); 254 255 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 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 276 throw new ObjectNotFoundException(localizedMessage); 277 } 278 279 ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum(); 280 281 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 (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 permission.ensureIsAuthenticated(); 300 301 Locale locale = I18nUtil.getLocaleInRequest(request); 302 303 int threadID = GenericParamUtil.getParameterInt(request, "thread"); 305 306 ThreadBean threadBean = null; 308 try { 309 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 310 } catch (ObjectNotFoundException e) { 311 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (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 MyUtil.ensureCorrectCurrentPassword(request); 321 322 int destForumID = GenericParamUtil.getParameterInt(request, "destforum"); 323 324 if (destForumID == forumID) { 326 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_move_thread_to_the_same_forum"); 327 throw new BadInputException(localizedMessage); 328 } 330 331 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 StatisticsUtil.updateForumStatistics(forumID); 340 StatisticsUtil.updateForumStatistics(destForumID); 341 342 PostIndexer.scheduleUpdateThreadTask(threadID); 345 346 ThreadCache.getInstance().clear(); 348 PostCache.getInstance().clear(); 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 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 370 throw new ObjectNotFoundException(localizedMessage); 371 } 372 373 ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum(); 374 375 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 (numberOfPosts)); 384 request.setAttribute("NumberOfPendingPosts", new Integer (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 permission.ensureIsAuthenticated(); 396 397 Locale locale = I18nUtil.getLocaleInRequest(request); 398 399 int threadID = GenericParamUtil.getParameterInt(request, "thread"); 401 402 ThreadBean threadBean = null; 404 try { 405 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 406 } catch (ObjectNotFoundException e) { 407 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (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 MyUtil.ensureCorrectCurrentPassword(request); 418 419 int threadStatus = GenericParamUtil.getParameterInt(request, "ThreadStatus"); 420 421 ThreadBean.validateThreadStatus(threadStatus); 422 423 if ((threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) && 426 (threadStatus != ThreadBean.THREAD_STATUS_DISABLED)) { 427 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 428 DAOFactory.getThreadDAO().updateLastPostDate(threadID, now); 429 } 430 431 DAOFactory.getThreadDAO().updateThreadStatus(threadID, threadStatus); 432 StatisticsUtil.updateForumStatistics(forumID); 433 435 ThreadCache.getInstance().clear(); 437 PostCache.getInstance().clear(); 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 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 460 throw new ObjectNotFoundException(localizedMessage); 461 } 462 463 ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum(); 464 465 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 (numberOfPosts)); 474 request.setAttribute("NumberOfPendingPosts", new Integer (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 permission.ensureIsAuthenticated(); 486 487 Locale locale = I18nUtil.getLocaleInRequest(request); 488 489 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (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 ) { 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 MyUtil.ensureCorrectCurrentPassword(request); 517 518 DAOFactory.getThreadDAO().updateThreadType(threadID, threadType); 519 521 ThreadCache.getInstance().clear(); 523 PostCache.getInstance().clear(); 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 ForumBean forumBean = ForumCache.getInstance().getBean(forumID); 543 544 forumBean.ensureNotDisabledForum(); 545 546 permission.ensureCanReadPost(forumID); 548 549 String sort = GenericParamUtil.getParameter(request, "sort"); 551 String 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 } 562 563 int totalThreads = ThreadCache.getInstance().getNumberOfEnableThreads_inForum(forumID); 564 int totalNormalThreads = ThreadCache.getInstance().getNumberOfNormalEnableThreads_inForum(forumID); 565 if (offset > totalNormalThreads) { 566 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 567 throw new BadInputException(localizedMessage); 568 } 570 571 Collection threadBeans = ThreadCache.getInstance().getNormalEnableThreads_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order); 572 573 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 (totalThreads)); 598 request.setAttribute("TotalNormalThreads", new Integer (totalNormalThreads)); 599 request.setAttribute("TotalPosts", new Integer (totalPosts)); 600 request.setAttribute("PendingThreadCount", new Integer (pendingThreadCount)); 601 request.setAttribute("ThreadsWithPendingPostsCount", new Integer (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 String sort = GenericParamUtil.getParameter(request, "sort"); 615 String 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 } 626 627 int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreads(); 628 if (offset > totalThreads) { 629 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 630 throw new BadInputException(localizedMessage); 631 } 633 634 Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(offset, postsPerPage, sort, order); 635 636 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 (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 permission.ensureIsAuthenticated(); 659 permission.ensureCanModerateThreadInAnyForum(); 660 661 Locale locale = I18nUtil.getLocaleInRequest(request); 662 663 String sort = GenericParamUtil.getParameter(request, "sort"); 665 String 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 } 676 677 int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads(); 678 if (offset > totalThreads) { 679 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 680 throw new BadInputException(localizedMessage); 681 } 683 684 Collection threadBeans = DAOFactory.getThreadDAO().getDisableBeans_withSortSupport_limit(offset, postsPerPage, sort, order); 685 686 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 (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 permission.ensureIsAuthenticated(); 709 permission.ensureCanModerateThreadInAnyForum(); 710 711 Collection pendingThreadBeans = DAOFactory.getThreadDAO().getDisableBeans_withSortSupport_limit(0, 10000, "ThreadLastPostDate", "DESC"); 712 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 permission.ensureIsAuthenticated(); 743 permission.ensureCanModerateThreadInAnyForum(); 744 745 Locale locale = I18nUtil.getLocaleInRequest(request); 746 747 String sort = GenericParamUtil.getParameter(request, "sort"); 749 String 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 } 760 761 int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts(); 762 if (offset > totalThreads) { 763 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 764 throw new BadInputException(localizedMessage); 765 } 767 768 Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreadsWithPendingPosts_withSortSupport_limit(offset, postsPerPage, sort, order); 769 770 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 (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 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 String sort = GenericParamUtil.getParameter(request, "sort"); 803 String 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 } 814 815 int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID); 816 if (offset > totalThreads) { 817 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 818 throw new BadInputException(localizedMessage); 819 } 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 (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 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 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 request.setAttribute("ForumBeans", forumBeans); 865 request.setAttribute("PendingThreadCount", new Integer (pendingThreadCount)); 866 request.setAttribute("ThreadsWithPendingPostsCount", new Integer (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 permission.ensureIsAuthenticated(); 878 879 int forumID = GenericParamUtil.getParameterInt(request, "forum"); 880 881 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 884 permission.ensureCanModerateThread(forumID); 885 886 Locale locale = I18nUtil.getLocaleInRequest(request); 887 888 String sort = GenericParamUtil.getParameter(request, "sort"); 890 String 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 } 901 902 int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID); 903 if (offset > totalThreads) { 904 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 905 throw new BadInputException(localizedMessage); 906 } 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 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 if (postAttachCount != actualAttachCount) { 932 if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) { 933 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count"); 934 throw new AssertionException(localizedMessage); 935 } 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 (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 permission.ensureIsAuthenticated(); 961 962 Locale locale = I18nUtil.getLocaleInRequest(request); 963 964 int forumID = -1; 968 try { 969 forumID = GenericParamUtil.getParameterInt(request, "forum"); 970 ForumCache.getInstance().getBean(forumID); permission.ensureCanModerateThread(forumID); 972 973 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 974 } catch (BadInputException ex) { 975 } 977 permission.ensureCanModerateThreadInAnyForum(); 978 979 try { 980 String prefix = "modthreadaction_"; 981 for (Enumeration enumeration = request.getParameterNames(); enumeration.hasMoreElements(); ) { 982 String param = (String ) enumeration.nextElement(); 983 if (param.startsWith(prefix)) { 984 String modValue = GenericParamUtil.getParameter(request, param, true); 985 String 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (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 if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED ) { 1002 Timestamp 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 localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 1011 throw new ObjectNotFoundException(localizedMessage); 1012 } 1013 deleteThread(request, threadBean); 1014 } else { 1015 } 1017 } 1018 } 1019 } finally { 1020 if (forumID != -1) { 1022 StatisticsUtil.updateForumStatistics(forumID); 1023 } 1024 } 1025 1026 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 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 (ratio * 100)); 1067 request.setAttribute("ThreadBeans", threadBeans); 1068 } 1069 1070 public void prepareRSSSummary(GenericRequest request) 1071 throws DatabaseException { 1072 1073 String sort = GenericParamUtil.getParameter(request, "sort"); 1075 String order = GenericParamUtil.getParameter(request, "order"); 1076 if (sort.length() == 0) sort = "ThreadLastPostDate"; 1077 if (order.length()== 0) order = "DESC"; 1078 1079 DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(0, 1, sort, order); 1081 } 1082 1083 void prepareListRSS(HttpServletRequest request) 1084 throws DatabaseException, AssertionException, 1085 AuthenticationException, ObjectNotFoundException { 1086 1087 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 1088 MVNForumPermission permission = onlineUser.getPermission(); 1089 1090 String sort = ParamUtil.getParameter(request, "sort"); 1092 String order = ParamUtil.getParameter(request, "order"); 1093 if (sort.length() == 0) sort = "ThreadLastPostDate"; 1094 if (order.length()== 0) order = "DESC"; 1095 1096 int offset = 0; int rows = MVNForumConfig.getRowsPerRSS(); 1098 try { 1099 rows = ParamUtil.getParameterInt(request, "rows"); 1100 if (rows <= 0) rows = MVNForumConfig.getRowsPerRSS(); 1101 } catch (Exception ex) { 1102 } 1104 1105 int forumID = -1; 1107 int categoryID = -1; 1108 1109 try { 1110 forumID = ParamUtil.getParameterInt(request, "forum"); 1111 } catch (Exception ex) { 1112 try { 1113 categoryID = ParamUtil.getParameterInt(request, "category"); 1114 } catch (Exception 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 threadBeans = new ArrayList(); 1124 } 1125 } else if (categoryID > 0) { 1126 } else { threadBeans = DAOFactory.getThreadDAO().getEnableThreads_withSortSupport_limit(offset, rows, sort, order); 1129 1130 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 (forumID)); 1144 request.setAttribute("CategoryID", new Integer (categoryID)); 1145 } 1146 1147} 1148 | Popular Tags |