0001: /*
0002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ThreadWebHandler.java,v 1.138 2008/01/28 10:55:12 phuongpdd Exp $
0003: * $Author: phuongpdd $
0004: * $Revision: 1.138 $
0005: * $Date: 2008/01/28 10:55:12 $
0006: *
0007: * ====================================================================
0008: *
0009: * Copyright (C) 2002-2007 by MyVietnam.net
0010: *
0011: * All copyright notices regarding mvnForum MUST remain
0012: * intact in the scripts and in the outputted HTML.
0013: * The "powered by" text/logo with a link back to
0014: * http://www.mvnForum.com and http://www.MyVietnam.net in
0015: * the footer of the pages MUST remain visible when the pages
0016: * are viewed on the internet or intranet.
0017: *
0018: * This program is free software; you can redistribute it and/or modify
0019: * it under the terms of the GNU General Public License as published by
0020: * the Free Software Foundation; either version 2 of the License, or
0021: * any later version.
0022: *
0023: * This program is distributed in the hope that it will be useful,
0024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0026: * GNU General Public License for more details.
0027: *
0028: * You should have received a copy of the GNU General Public License
0029: * along with this program; if not, write to the Free Software
0030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0031: *
0032: * Support can be obtained from support forums at:
0033: * http://www.mvnForum.com/mvnforum/index
0034: *
0035: * Correspondence and Marketing Questions can be sent to:
0036: * info at MyVietnam net
0037: *
0038: * @author: Minh Nguyen
0039: * @author: Mai Nguyen
0040: */
0041: package com.mvnforum.user;
0042:
0043: import java.sql.Timestamp;
0044: import java.util.*;
0045:
0046: import net.myvietnam.mvncore.exception.*;
0047: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
0048: import net.myvietnam.mvncore.interceptor.InterceptorService;
0049: import net.myvietnam.mvncore.security.SecurityUtil;
0050: import net.myvietnam.mvncore.service.EventLogService;
0051: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
0052: import net.myvietnam.mvncore.util.*;
0053: import net.myvietnam.mvncore.web.GenericRequest;
0054: import net.myvietnam.mvncore.web.GenericResponse;
0055:
0056: import org.apache.commons.logging.Log;
0057: import org.apache.commons.logging.LogFactory;
0058:
0059: import com.mvnforum.*;
0060: import com.mvnforum.auth.*;
0061: import com.mvnforum.categorytree.*;
0062: import com.mvnforum.categorytree.impl.CategoryTreePath;
0063: import com.mvnforum.common.OnlineUserUtil;
0064: import com.mvnforum.common.StatisticsUtil;
0065: import com.mvnforum.db.*;
0066: import com.mvnforum.search.post.DeletePostIndexTask;
0067: import com.mvnforum.search.post.PostIndexer;
0068: import com.mvnforum.service.CategoryService;
0069: import com.mvnforum.service.MvnForumServiceFactory;
0070:
0071: public class ThreadWebHandler {
0072:
0073: private static Log log = LogFactory.getLog(ThreadWebHandler.class);
0074:
0075: private OnlineUserManager onlineUserManager = OnlineUserManager
0076: .getInstance();
0077:
0078: private static CategoryService categoryService = MvnForumServiceFactory
0079: .getMvnForumService().getCategoryService();
0080:
0081: private static EventLogService eventLogService = MvnCoreServiceFactory
0082: .getMvnCoreService().getEventLogService();
0083:
0084: public ThreadWebHandler() {
0085: }
0086:
0087: public void prepareSplit(GenericRequest request,
0088: GenericResponse response) throws BadInputException,
0089: ObjectNotFoundException, DatabaseException,
0090: AuthenticationException {
0091:
0092: OnlineUser onlineUser = onlineUserManager
0093: .getOnlineUser(request);
0094: MVNForumPermission permission = onlineUser.getPermission();
0095:
0096: // user must have been authenticated before he can split
0097: permission.ensureIsAuthenticated();
0098:
0099: Locale locale = I18nUtil.getLocaleInRequest(request);
0100:
0101: // int threadID = GenericParamUtil.getParameterInt(request, "thread");
0102: int postID = GenericParamUtil.getParameterInt(request, "post");
0103: PostBean postBean = null;
0104: try {
0105: postBean = DAOFactory.getPostDAO().getPost(postID);
0106: } catch (ObjectNotFoundException ex) {
0107: String localizedMessage = MVNForumResourceBundle
0108: .getString(
0109: locale,
0110: "mvncore.exception.ObjectNotFoundException.postid_not_exists",
0111: new Object[] { new Integer(postID) });
0112: throw new ObjectNotFoundException(localizedMessage);
0113: }
0114:
0115: if (postBean.getParentPostID() == 0) {
0116: String localizedMessage = MVNForumResourceBundle
0117: .getString(locale,
0118: "mvncore.exception.BadInputException.first_post_cannot_be_split");
0119: throw new BadInputException(localizedMessage);
0120: }
0121:
0122: int forumID = postBean.getForumID();
0123:
0124: // permission.ensureCanSplitPost(forumID);
0125: ForumCache.getInstance().getBean(forumID)
0126: .ensureNotDisabledForum();
0127: permission.ensureCanDeletePost(forumID);
0128:
0129: int threadID = postBean.getThreadID();
0130: ThreadBean threadBean = null;
0131: try {
0132: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0133: } catch (ObjectNotFoundException e) {
0134: String localizedMessage = MVNForumResourceBundle
0135: .getString(
0136: locale,
0137: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0138: new Object[] { new Integer(threadID) });
0139: throw new ObjectNotFoundException(localizedMessage);
0140: }
0141:
0142: threadBean.ensureStatusCanEdit();
0143:
0144: // Collection postBeans = PostUtil.getSubPosts(threadID, postID);
0145: int numberOfPosts = DAOFactory.getPostDAO()
0146: .getNumberOfEnablePosts_inThread(threadID);
0147: if (numberOfPosts == 1) {
0148: String localizedMessage = MVNForumResourceBundle
0149: .getString(locale,
0150: "mvncore.exception.BadInputException.cannot_be_split");
0151: throw new BadInputException(localizedMessage);
0152: }
0153:
0154: request.setAttribute("PostBean", postBean);
0155:
0156: ForumBean forumBean = ForumCache.getInstance().getBean(forumID);
0157: forumBean.ensureNotDisabledForum();
0158: forumBean.ensureNotLockedForum();
0159:
0160: String display = MVNForumResourceBundle.getString(locale,
0161: "mvnforum.user.splitthread.title");
0162:
0163: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0164: CategoryTree categorytree = new CategoryTree(treebuilder);
0165: CategoryTreeListener treelistener = new CategoryTreePath(
0166: request, response, forumBean.getForumID(), null, null,
0167: display);
0168: categorytree.addCategeoryTreeListener(treelistener);
0169: request.setAttribute("tree", categorytree.build());
0170:
0171: CategoryBuilder builder = new DefaultCategoryBuilder();
0172: CategoryTree tree = new CategoryTree(builder);
0173: CategoryTreeListener listener = categoryService
0174: .getManagementCategorySelector(request, response,
0175: "assignforumtogroup_movethread", 0);
0176: tree.addCategeoryTreeListener(listener);
0177: request.setAttribute("Result", tree.build());
0178: }
0179:
0180: public void processSplit(GenericRequest request)
0181: throws BadInputException, ObjectNotFoundException,
0182: DatabaseException, ForeignKeyNotFoundException,
0183: AuthenticationException, CreateException,
0184: InterceptorException {
0185:
0186: SecurityUtil.checkHttpPostMethod(request);
0187:
0188: OnlineUser onlineUser = onlineUserManager
0189: .getOnlineUser(request);
0190: MVNForumPermission permission = onlineUser.getPermission();
0191:
0192: // user must have been authenticated before he can split
0193: permission.ensureIsAuthenticated();
0194:
0195: Locale locale = I18nUtil.getLocaleInRequest(request);
0196:
0197: // primary key column(s)
0198: int postID = GenericParamUtil.getParameterInt(request, "post");
0199: PostBean postBean = null;
0200: try {
0201: postBean = DAOFactory.getPostDAO().getPost(postID);
0202: } catch (ObjectNotFoundException ex) {
0203: String localizedMessage = MVNForumResourceBundle
0204: .getString(
0205: locale,
0206: "mvncore.exception.ObjectNotFoundException.postid_not_exists",
0207: new Object[] { new Integer(postID) });
0208: throw new ObjectNotFoundException(localizedMessage);
0209: }
0210:
0211: if (postBean.getParentPostID() == 0) {
0212: String localizedMessage = MVNForumResourceBundle
0213: .getString(locale,
0214: "mvncore.exception.BadInputException.first_post_cannot_be_split");
0215: throw new BadInputException(localizedMessage);
0216: }
0217:
0218: int threadID = postBean.getThreadID();
0219: int forumID = postBean.getForumID();
0220:
0221: permission.ensureCanDeletePost(forumID);
0222:
0223: ForumBean forumBean = ForumCache.getInstance().getBean(forumID);
0224: forumBean.ensureNotDisabledForum();
0225: forumBean.ensureNotLockedForum();
0226: /*
0227: ThreadBean threadBean = null;
0228: try {
0229: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0230: } catch (ObjectNotFoundException e) {
0231: String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
0232: throw new ObjectNotFoundException(localizedMessage);
0233: }
0234: */
0235: // now check the password
0236: MyUtil.ensureCorrectCurrentPassword(request);
0237:
0238: int destForumID = GenericParamUtil.getParameterInt(request,
0239: "destforum");
0240:
0241: // now make sure that the dest forum is existed
0242: ForumBean destForumBean = ForumCache.getInstance().getBean(
0243: destForumID);
0244: destForumBean.ensureNotDisabledForum();
0245: destForumBean.ensureNotClosedForum();
0246: destForumBean.ensureNotLockedForum();
0247:
0248: String threadTopic = GenericParamUtil.getParameter(request,
0249: "PostTopic");
0250: threadTopic = DisableHtmlTagFilter.filter(threadTopic);// always disable HTML
0251: threadTopic = InterceptorService.getInstance().validateContent(
0252: threadTopic);
0253:
0254: //create a new Thread
0255: int newThreadID = DAOFactory.getThreadDAO().createThread(
0256: destForumID, postBean.getMemberName(),
0257: postBean.getMemberName(), threadTopic,
0258: postBean.getPostBody(), 0, 0,
0259: postBean.getPostCreationDate(),
0260: postBean.getPostCreationDate(), 0, 0, 0, 0, 0, 0, 0,
0261: postBean.getPostIcon(), 0, 0);
0262:
0263: Stack stack = new Stack();
0264: Collection postFirstChildrenBeans = PostUtil
0265: .getChildrenPosts(postID);
0266: for (Iterator iterator = postFirstChildrenBeans.iterator(); iterator
0267: .hasNext();) {
0268: PostBean post = (PostBean) iterator.next();
0269: stack.add(post);
0270: }
0271:
0272: int postBeanParentID = postBean.getParentPostID();
0273:
0274: // update split post
0275: postBean.setParentPostID(0);
0276: postBean.setThreadID(newThreadID);
0277: postBean.setForumID(destForumID);
0278: DAOFactory.getPostDAO().update(postBean.getPostID(),
0279: postBean.getParentPostID(), postBean.getForumID(),
0280: postBean.getThreadID());
0281:
0282: String option = request.getParameter("option");
0283: if ("afterthis".equals(option)) {
0284: while (!stack.isEmpty()) {
0285: PostBean currentPost = (PostBean) stack.pop();
0286: int currentParentPostID = currentPost.getPostID();
0287: Collection postBeans = PostUtil
0288: .getChildrenPosts(currentParentPostID);
0289: for (Iterator iterator = postBeans.iterator(); iterator
0290: .hasNext();) {
0291: PostBean post = (PostBean) iterator.next();
0292: stack.add(post);
0293: }
0294: currentPost.setThreadID(newThreadID);
0295: currentPost.setForumID(destForumID);
0296: DAOFactory.getPostDAO().update(currentPost.getPostID(),
0297: currentPost.getParentPostID(),
0298: currentPost.getForumID(),
0299: currentPost.getThreadID());
0300: }
0301: } else if ("onlythis".equals(option)) {
0302: while (!stack.isEmpty()) {
0303: PostBean currentPost = (PostBean) stack.pop();
0304: DAOFactory.getPostDAO().update(currentPost.getPostID(),
0305: postBeanParentID, currentPost.getForumID(),
0306: currentPost.getThreadID());
0307: }
0308: }
0309:
0310: // now, update the statistics in the source thread and new thread
0311: // It updates these information: threadReplyCount, lastPostMemberName, threadLastPostDate
0312: StatisticsUtil.updateThreadStatistics(threadID);
0313: StatisticsUtil.updateThreadStatistics(newThreadID);
0314:
0315: // now, update the statistics in the source forum and dest forum
0316: StatisticsUtil.updateForumStatistics(forumID);
0317: StatisticsUtil.updateForumStatistics(destForumID);
0318:
0319: // now update the search index
0320: PostIndexer.scheduleUpdateThreadTask(threadID);
0321: PostIndexer.scheduleUpdateThreadTask(newThreadID);
0322:
0323: // Clear the cache
0324: ThreadCache.getInstance().clear();
0325: PostCache.getInstance().clear();// affect mostActiveThreads in Post
0326:
0327: String actionDesc = MVNForumResourceBundle
0328: .getString(MVNForumConfig.getEventLogLocale(),
0329: "mvnforum.eventlog.desc.MoveThreadProcess",
0330: new Object[] { new Integer(threadID),
0331: new Integer(forumID),
0332: new Integer(destForumID) });
0333: eventLogService.logEvent(onlineUser.getMemberName(), request
0334: .getRemoteAddr(),
0335: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0336: MVNForumConstant.EVENT_LOG_SUB_MODULE_USER,
0337: "split thread", actionDesc, EventLogService.MEDIUM);
0338:
0339: request
0340: .setAttribute("NewThreadID", String
0341: .valueOf(newThreadID));
0342: }
0343:
0344: public void prepareDelete(GenericRequest request,
0345: GenericResponse response) throws BadInputException,
0346: ObjectNotFoundException, DatabaseException,
0347: AuthenticationException {
0348:
0349: OnlineUser onlineUser = onlineUserManager
0350: .getOnlineUser(request);
0351: MVNForumPermission permission = onlineUser.getPermission();
0352:
0353: // primary key column(s)
0354: int threadID = GenericParamUtil.getParameterInt(request,
0355: "thread");
0356:
0357: Locale locale = I18nUtil.getLocaleInRequest(request);
0358:
0359: ThreadBean threadBean = null;
0360: try {
0361: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0362: } catch (ObjectNotFoundException e) {
0363: String localizedMessage = MVNForumResourceBundle
0364: .getString(
0365: locale,
0366: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0367: new Object[] { new Integer(threadID) });
0368: throw new ObjectNotFoundException(localizedMessage);
0369: }
0370: int numberOfPosts = DAOFactory.getPostDAO()
0371: .getNumberOfEnablePosts_inThread(threadID);
0372:
0373: // check constraint
0374: int forumID = threadBean.getForumID();
0375: try {
0376: ForumCache.getInstance().getBean(forumID)
0377: .ensureNotDisabledForum();
0378: } catch (ObjectNotFoundException e) {
0379: String localizedMessage = MVNForumResourceBundle
0380: .getString(
0381: locale,
0382: "mvncore.exception.ObjectNotFoundException.forumid_not_exists",
0383: new Object[] { new Integer(forumID) });
0384: throw new ObjectNotFoundException(localizedMessage);
0385: }
0386: int logonMemberID = onlineUser.getMemberID();
0387: String authorName = threadBean.getMemberName();
0388: int authorID = 0;
0389: try {
0390: authorID = MemberCache.getInstance()
0391: .getMemberIDFromMemberName(authorName);
0392: } catch (ObjectNotFoundException e) {
0393: String localizedMessage = MVNForumResourceBundle
0394: .getString(
0395: locale,
0396: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
0397: new Object[] { authorName });
0398: throw new ObjectNotFoundException(localizedMessage);
0399: }
0400: if (permission.canDeletePost(forumID)) {
0401: // have permission, just do nothing, that is dont check the max day contraint
0402: } else if (logonMemberID == authorID) {// same author
0403: // check date here, usually must not older than 7 days
0404: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0405: Timestamp postDate = threadBean.getThreadCreationDate();
0406: int maxDays = MVNForumConfig.getMaxDeleteDays();
0407: if ((now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays)) {
0408: /** @todo choose a better Exception here */
0409: String localizedMessage = MVNForumResourceBundle
0410: .getString(
0411: locale,
0412: "mvncore.exception.BadInputException.cannot_delete.post_is_too_old",
0413: new Object[] { new Integer(maxDays) });
0414: throw new BadInputException(localizedMessage);
0415: //throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
0416: }
0417:
0418: //Check to make sure that "no reply" for this post
0419: if (numberOfPosts > 1) {
0420: String localizedMessage = MVNForumResourceBundle
0421: .getString(locale,
0422: "mvncore.exception.BadInputException.cannot_delete.thread_has_reply");
0423: throw new BadInputException(localizedMessage);
0424: //throw new BadInputException("Cannot delete a thread that has reply!");
0425: }
0426:
0427: /** @todo check status of this thread */
0428: /*
0429: if (postBean.getPostStatus() == ?) {
0430: throw new BadInputException("Cannot delete message which is disable.");
0431: }*/
0432: } else {//not an author, so this user must have Edit Permission
0433: permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
0434: }
0435:
0436: int numberOfPendingPosts = DAOFactory.getPostDAO()
0437: .getNumberOfDisablePosts_inThread(threadID);
0438:
0439: request.setAttribute("ThreadBean", threadBean);
0440: request.setAttribute("NumberOfPosts",
0441: new Integer(numberOfPosts));
0442: request.setAttribute("NumberOfPendingPosts", new Integer(
0443: numberOfPendingPosts));
0444:
0445: String title = MVNForumResourceBundle.getString(locale,
0446: "mvnforum.user.deletethread.title");
0447: StringBuffer stb = new StringBuffer();
0448: stb.append(title).append(": ").append(
0449: threadBean.getThreadTopic());
0450:
0451: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0452: CategoryTree categorytree = new CategoryTree(treebuilder);
0453: CategoryTreeListener treelistener = new CategoryTreePath(
0454: request, response, forumID, null, null, stb.toString());
0455: categorytree.addCategeoryTreeListener(treelistener);
0456: request.setAttribute("tree", categorytree.build());
0457:
0458: }
0459:
0460: public void processDelete(GenericRequest request)
0461: throws BadInputException, ObjectNotFoundException,
0462: DatabaseException, AuthenticationException {
0463:
0464: SecurityUtil.checkHttpPostMethod(request);
0465:
0466: OnlineUser onlineUser = onlineUserManager
0467: .getOnlineUser(request);
0468:
0469: // primary key column(s)
0470: Locale locale = I18nUtil.getLocaleInRequest(request);
0471:
0472: int threadID = GenericParamUtil.getParameterInt(request,
0473: "thread");
0474: ThreadBean threadBean = null;
0475: try {
0476: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0477: } catch (ObjectNotFoundException e) {
0478: String localizedMessage = MVNForumResourceBundle
0479: .getString(
0480: locale,
0481: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0482: new Object[] { new Integer(threadID) });
0483: throw new ObjectNotFoundException(localizedMessage);
0484: }
0485:
0486: ForumCache.getInstance().getBean(threadBean.getForumID())
0487: .ensureNotDisabledForum();
0488:
0489: // now check the password
0490: MyUtil.ensureCorrectCurrentPassword(request);
0491:
0492: // Note that this method will check the permission
0493: deleteThread(request, threadBean);
0494:
0495: //now, update the statistics in the forum and member
0496: int forumID = threadBean.getForumID();
0497: StatisticsUtil.updateForumStatistics(forumID);
0498:
0499: // Clear the cache
0500: ThreadCache.getInstance().clear();
0501: PostCache.getInstance().clear();// affect mostActiveThreads in Post
0502:
0503: String actionDesc = MVNForumResourceBundle.getString(
0504: MVNForumConfig.getEventLogLocale(),
0505: "mvnforum.eventlog.desc.DeleteThreadProcess",
0506: new Object[] { new Integer(threadID),
0507: new Integer(forumID) });
0508: eventLogService.logEvent(onlineUser.getMemberName(), request
0509: .getRemoteAddr(),
0510: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0511: MVNForumConstant.EVENT_LOG_SUB_MODULE_USER,
0512: "delete thread", actionDesc, EventLogService.HIGH);
0513:
0514: request.setAttribute("ForumID", String.valueOf(forumID));
0515: }
0516:
0517: // Note that this method does not update the forum statistics
0518: // The caller must call method to update the forum statistics
0519: public void deleteThread(GenericRequest request,
0520: ThreadBean threadBean) throws BadInputException,
0521: ObjectNotFoundException, DatabaseException,
0522: AuthenticationException {
0523:
0524: OnlineUser onlineUser = onlineUserManager
0525: .getOnlineUser(request);
0526: MVNForumPermission permission = onlineUser.getPermission();
0527:
0528: // user must have been authenticated before he can delete
0529: permission.ensureIsAuthenticated();
0530:
0531: // primary key column(s)
0532: int threadID = threadBean.getThreadID();
0533:
0534: Locale locale = I18nUtil.getLocaleInRequest(request);
0535:
0536: // now, check the permission
0537: int forumID = threadBean.getForumID();
0538: int logonMemberID = onlineUser.getMemberID();
0539: String authorName = threadBean.getMemberName();
0540: int authorID = 0;
0541: try {
0542: authorID = MemberCache.getInstance()
0543: .getMemberIDFromMemberName(authorName);
0544: } catch (ObjectNotFoundException e) {
0545: String localizedMessage = MVNForumResourceBundle
0546: .getString(
0547: locale,
0548: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
0549: new Object[] { authorName });
0550: throw new ObjectNotFoundException(localizedMessage);
0551: }
0552: if (permission.canDeletePost(forumID)) {
0553: // have permission, just do nothing, that is dont check the max day contraint
0554: } else if (logonMemberID == authorID) {// same author
0555: // check date here, usually must not older than 7 days
0556: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0557: Timestamp postDate = threadBean.getThreadCreationDate();
0558: int maxDays = MVNForumConfig.getMaxDeleteDays();
0559: if ((now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays)) {
0560: /** @todo choose a better Exception here */
0561: String localizedMessage = MVNForumResourceBundle
0562: .getString(
0563: locale,
0564: "mvncore.exception.BadInputException.cannot_delete.post_is_too_old",
0565: new Object[] { new Integer(maxDays) });
0566: throw new BadInputException(localizedMessage);
0567: //throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
0568: }
0569:
0570: //Check to make sure that "no reply" for this post
0571: int numberOfPosts = DAOFactory.getPostDAO()
0572: .getNumberOfEnablePosts_inThread(threadID);
0573: if (numberOfPosts > 1) {
0574: String localizedMessage = MVNForumResourceBundle
0575: .getString(locale,
0576: "mvncore.exception.BadInputException.cannot_delete.thread_has_reply");
0577: throw new BadInputException(localizedMessage);
0578: //throw new BadInputException("Cannot delete a thread that has reply!");
0579: }
0580:
0581: if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
0582: String localizedMessage = MVNForumResourceBundle
0583: .getString(locale,
0584: "mvncore.exception.BadInputException.cannot_delete_your_own_disabled_thread");
0585: throw new BadInputException(localizedMessage);
0586: //throw new BadInputException("Cannot delete your own disabled thread.");
0587: }
0588: } else {//not an author, so this user must have Edit Permission
0589: permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
0590: }
0591:
0592: // Delete all attachments in this thread,
0593: // we must call this before any attempt to delete the thread
0594: // That is, the order when delete is VERY IMPORTANT
0595: AttachmentWebHandler.deleteAttachments_inThread(threadID);
0596:
0597: DAOFactory.getFavoriteThreadDAO().delete_inThread(threadID);
0598:
0599: DAOFactory.getWatchDAO().delete_inThread(threadID);
0600:
0601: DAOFactory.getPostDAO().delete_inThread(threadID);
0602:
0603: // now delete the thread, note that we delete it after delete all child objects
0604: DAOFactory.getThreadDAO().delete(threadID);
0605:
0606: // now update the search index
0607: // @todo : what if the above methods throw exception, then no thread is deleted from index ???
0608: PostIndexer.scheduleDeletePostTask(threadID,
0609: DeletePostIndexTask.OBJECT_TYPE_THREAD);
0610:
0611: //now, update the statistics in the member
0612: StatisticsUtil.updateMemberStatistics(authorID);
0613: }
0614:
0615: public void deleteSuccessForRender(GenericRequest request,
0616: GenericResponse response) throws DatabaseException,
0617: AuthenticationException, ObjectNotFoundException {
0618:
0619: Locale locale = I18nUtil.getLocaleInRequest(request);
0620:
0621: int forumID = (Integer.valueOf((String) request
0622: .getAttribute("ForumID"))).intValue();
0623:
0624: String deleteSuccessLabel = MVNForumResourceBundle.getString(
0625: locale, "mvnforum.user.deletethreadsuccess.title");
0626:
0627: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0628: CategoryTree categorytree = new CategoryTree(treebuilder);
0629: CategoryTreeListener treelistener = new CategoryTreePath(
0630: request, response, forumID, null, null,
0631: deleteSuccessLabel);
0632: categorytree.addCategeoryTreeListener(treelistener);
0633:
0634: request.setAttribute("tree", categorytree.build());
0635: }
0636:
0637: public void prepareMoveThread(GenericRequest request,
0638: GenericResponse response) throws BadInputException,
0639: ObjectNotFoundException, DatabaseException,
0640: AuthenticationException {
0641:
0642: OnlineUser onlineUser = onlineUserManager
0643: .getOnlineUser(request);
0644: MVNForumPermission permission = onlineUser.getPermission();
0645:
0646: Locale locale = I18nUtil.getLocaleInRequest(request);
0647:
0648: int forumID = -1;
0649: // primary key column(s)
0650: int threadID = GenericParamUtil.getParameterInt(request,
0651: "thread");
0652:
0653: ThreadBean threadBean = null;
0654: try {
0655: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0656: forumID = threadBean.getForumID();
0657: } catch (ObjectNotFoundException e) {
0658: String localizedMessage = MVNForumResourceBundle
0659: .getString(
0660: locale,
0661: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0662: new Object[] { new Integer(threadID) });
0663: throw new ObjectNotFoundException(localizedMessage);
0664: }
0665:
0666: ForumBean forumBean = ForumCache.getInstance().getBean(
0667: threadBean.getForumID());
0668: forumBean.ensureNotDisabledForum();
0669:
0670: // now, check the permission
0671: // @todo: is it the correct permission ???
0672: permission.ensureCanDeletePost(threadBean.getForumID());
0673:
0674: int numberOfPosts = DAOFactory.getPostDAO()
0675: .getNumberOfEnablePosts_inThread(threadID);
0676:
0677: request.setAttribute("ThreadBean", threadBean);
0678: request.setAttribute("NumberOfPosts",
0679: new Integer(numberOfPosts));
0680:
0681: String title = MVNForumResourceBundle.getString(locale,
0682: "mvnforum.user.movethread.title");
0683: StringBuffer stb = new StringBuffer();
0684: stb.append(title).append(": ").append(
0685: threadBean.getThreadTopic());
0686:
0687: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0688: CategoryTree categorytree = new CategoryTree(treebuilder);
0689: CategoryTreeListener treelistener = new CategoryTreePath(
0690: request, response, forumBean.getForumID(), null, null,
0691: stb.toString());
0692: categorytree.addCategeoryTreeListener(treelistener);
0693: request.setAttribute("tree", categorytree.build());
0694:
0695: CategoryBuilder builder = new DefaultCategoryBuilder();
0696: CategoryTree tree = new CategoryTree(builder);
0697: CategoryTreeListener listener = categoryService
0698: .getManagementCategorySelector(request, response,
0699: "assignforumtogroup_movethread", forumID);
0700: tree.addCategeoryTreeListener(listener);
0701: request.setAttribute("Result", tree.build());
0702: }
0703:
0704: public void processMoveThread(GenericRequest request)
0705: throws BadInputException, ObjectNotFoundException,
0706: DatabaseException, ForeignKeyNotFoundException,
0707: AuthenticationException {
0708:
0709: SecurityUtil.checkHttpPostMethod(request);
0710:
0711: OnlineUser onlineUser = onlineUserManager
0712: .getOnlineUser(request);
0713: MVNForumPermission permission = onlineUser.getPermission();
0714:
0715: // user must have been authenticated before he can delete
0716: permission.ensureIsAuthenticated();
0717:
0718: Locale locale = I18nUtil.getLocaleInRequest(request);
0719:
0720: // primary key column(s)
0721: int threadID = GenericParamUtil.getParameterInt(request,
0722: "thread");
0723:
0724: // now, check the permission
0725: ThreadBean threadBean = null;
0726: try {
0727: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0728: } catch (ObjectNotFoundException e) {
0729: String localizedMessage = MVNForumResourceBundle
0730: .getString(
0731: locale,
0732: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0733: new Object[] { new Integer(threadID) });
0734: throw new ObjectNotFoundException(localizedMessage);
0735: }
0736: int forumID = threadBean.getForumID();
0737: permission.ensureCanDeletePost(forumID);
0738:
0739: ForumCache.getInstance().getBean(forumID)
0740: .ensureNotDisabledForum();
0741:
0742: // now check the password
0743: MyUtil.ensureCorrectCurrentPassword(request);
0744:
0745: int destForumID = GenericParamUtil.getParameterInt(request,
0746: "destforum");
0747:
0748: // make sure that we dont move to the same forum (meaningless)
0749: if (destForumID == forumID) {
0750: String localizedMessage = MVNForumResourceBundle
0751: .getString(locale,
0752: "mvncore.exception.BadInputException.cannot_move_thread_to_the_same_forum");
0753: throw new BadInputException(localizedMessage);
0754: //throw new BadInputException("Cannot move thread to the same forum.");
0755: }
0756:
0757: // now make sure that the dest forum is existed
0758: ForumCache.getInstance().getBean(destForumID);
0759:
0760: DAOFactory.getThreadDAO().updateForumID(threadID, destForumID);
0761: DAOFactory.getPostDAO().update_ForumID_inThread(threadID,
0762: destForumID);
0763: DAOFactory.getFavoriteThreadDAO().update_ForumID_inThread(
0764: threadID, destForumID);
0765:
0766: //now, update the statistics in the source forum and dest forum
0767: StatisticsUtil.updateForumStatistics(forumID);
0768: StatisticsUtil.updateForumStatistics(destForumID);
0769:
0770: // now update the search index
0771: // @todo : what if the above methods throw exception, then no thread is deleted from index ???
0772: PostIndexer.scheduleUpdateThreadTask(threadID);
0773:
0774: // Clear the cache
0775: ThreadCache.getInstance().clear();
0776: PostCache.getInstance().clear();// affect mostActiveThreads in Post
0777:
0778: String actionDesc = MVNForumResourceBundle
0779: .getString(MVNForumConfig.getEventLogLocale(),
0780: "mvnforum.eventlog.desc.MoveThreadProcess",
0781: new Object[] { new Integer(threadID),
0782: new Integer(forumID),
0783: new Integer(destForumID) });
0784: eventLogService.logEvent(onlineUser.getMemberName(), request
0785: .getRemoteAddr(),
0786: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0787: MVNForumConstant.EVENT_LOG_SUB_MODULE_USER,
0788: "move thread", actionDesc, EventLogService.MEDIUM);
0789:
0790: request.setAttribute("ForumID", String.valueOf(forumID));
0791: }
0792:
0793: public void prepareEditThreadStatus(GenericRequest request,
0794: GenericResponse response) throws BadInputException,
0795: ObjectNotFoundException, DatabaseException,
0796: AuthenticationException {
0797:
0798: OnlineUser onlineUser = onlineUserManager
0799: .getOnlineUser(request);
0800: MVNForumPermission permission = onlineUser.getPermission();
0801:
0802: Locale locale = I18nUtil.getLocaleInRequest(request);
0803:
0804: // primary key column(s)
0805: int threadID = GenericParamUtil.getParameterInt(request,
0806: "thread");
0807:
0808: ThreadBean threadBean = null;
0809: try {
0810: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0811: } catch (ObjectNotFoundException e) {
0812: String localizedMessage = MVNForumResourceBundle
0813: .getString(
0814: locale,
0815: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0816: new Object[] { new Integer(threadID) });
0817: throw new ObjectNotFoundException(localizedMessage);
0818: }
0819:
0820: ForumBean forumBean = ForumCache.getInstance().getBean(
0821: threadBean.getForumID());
0822: forumBean.ensureNotDisabledForum();
0823:
0824: // now, check the permission
0825: permission.ensureCanModerateThread(threadBean.getForumID());
0826:
0827: int numberOfPosts = DAOFactory.getPostDAO()
0828: .getNumberOfEnablePosts_inThread(threadID);
0829:
0830: int numberOfPendingPosts = DAOFactory.getPostDAO()
0831: .getNumberOfDisablePosts_inThread(threadID);
0832:
0833: request.setAttribute("ThreadBean", threadBean);
0834: request.setAttribute("NumberOfPosts",
0835: new Integer(numberOfPosts));
0836: request.setAttribute("NumberOfPendingPosts", new Integer(
0837: numberOfPendingPosts));
0838:
0839: String title = MVNForumResourceBundle.getString(locale,
0840: "mvnforum.user.editthreadstatus.title");
0841: StringBuffer stb = new StringBuffer();
0842: stb.append(title).append(": ").append(
0843: threadBean.getThreadTopic());
0844:
0845: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0846: CategoryTree categorytree = new CategoryTree(treebuilder);
0847: CategoryTreeListener treelistener = new CategoryTreePath(
0848: request, response, forumBean.getForumID(), null, null,
0849: stb.toString());
0850: categorytree.addCategeoryTreeListener(treelistener);
0851: request.setAttribute("tree", categorytree.build());
0852:
0853: }
0854:
0855: public void processEditThreadStatus(GenericRequest request)
0856: throws BadInputException, ObjectNotFoundException,
0857: DatabaseException, AuthenticationException {
0858:
0859: SecurityUtil.checkHttpPostMethod(request);
0860:
0861: OnlineUser onlineUser = onlineUserManager
0862: .getOnlineUser(request);
0863: MVNForumPermission permission = onlineUser.getPermission();
0864:
0865: // user must have been authenticated before he can edit thread status
0866: permission.ensureIsAuthenticated();
0867:
0868: Locale locale = I18nUtil.getLocaleInRequest(request);
0869:
0870: // primary key column(s)
0871: int threadID = GenericParamUtil.getParameterInt(request,
0872: "thread");
0873:
0874: // now, check the permission
0875: ThreadBean threadBean = null;
0876: try {
0877: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0878: } catch (ObjectNotFoundException e) {
0879: String localizedMessage = MVNForumResourceBundle
0880: .getString(
0881: locale,
0882: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0883: new Object[] { new Integer(threadID) });
0884: throw new ObjectNotFoundException(localizedMessage);
0885: }
0886: int forumID = threadBean.getForumID();
0887:
0888: ForumCache.getInstance().getBean(forumID)
0889: .ensureNotDisabledForum();
0890:
0891: permission.ensureCanModerateThread(forumID);
0892:
0893: // now check the password
0894: MyUtil.ensureCorrectCurrentPassword(request);
0895:
0896: int threadStatus = GenericParamUtil.getParameterInt(request,
0897: "ThreadStatus");
0898:
0899: ThreadBean.validateThreadStatus(threadStatus);
0900:
0901: // now if change from Disable to Enable, update the lastpostdate so
0902: // that the Watch will see this thread as a new thread
0903: if ((threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED)
0904: && (threadStatus != ThreadBean.THREAD_STATUS_DISABLED)) {
0905: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0906: DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
0907: }
0908:
0909: DAOFactory.getThreadDAO().updateThreadStatus(threadID,
0910: threadStatus);
0911: StatisticsUtil.updateForumStatistics(forumID);
0912: //@todo: should update other info ???
0913:
0914: // Clear the cache
0915: ThreadCache.getInstance().clear();
0916: PostCache.getInstance().clear();// affect mostActiveThreads in Post
0917:
0918: request.setAttribute("ThreadID", String.valueOf(threadID));
0919: request.setAttribute("ForumID", String.valueOf(forumID));
0920: }
0921:
0922: public void prepareEditThreadType(GenericRequest request,
0923: GenericResponse response) throws BadInputException,
0924: ObjectNotFoundException, DatabaseException,
0925: AuthenticationException {
0926:
0927: OnlineUser onlineUser = onlineUserManager
0928: .getOnlineUser(request);
0929: MVNForumPermission permission = onlineUser.getPermission();
0930:
0931: Locale locale = I18nUtil.getLocaleInRequest(request);
0932:
0933: // primary key column(s)
0934: int threadID = GenericParamUtil.getParameterInt(request,
0935: "thread");
0936:
0937: ThreadBean threadBean = null;
0938: try {
0939: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
0940: } catch (ObjectNotFoundException e) {
0941: String localizedMessage = MVNForumResourceBundle
0942: .getString(
0943: locale,
0944: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
0945: new Object[] { new Integer(threadID) });
0946: throw new ObjectNotFoundException(localizedMessage);
0947: }
0948:
0949: ForumBean forumBean = ForumCache.getInstance().getBean(
0950: threadBean.getForumID());
0951: forumBean.ensureNotDisabledForum();
0952:
0953: // now, check the permission
0954: permission.ensureCanModerateThread(threadBean.getForumID());
0955:
0956: int numberOfPosts = DAOFactory.getPostDAO()
0957: .getNumberOfEnablePosts_inThread(threadID);
0958:
0959: int numberOfPendingPosts = DAOFactory.getPostDAO()
0960: .getNumberOfDisablePosts_inThread(threadID);
0961:
0962: request.setAttribute("ThreadBean", threadBean);
0963: request.setAttribute("NumberOfPosts",
0964: new Integer(numberOfPosts));
0965: request.setAttribute("NumberOfPendingPosts", new Integer(
0966: numberOfPendingPosts));
0967:
0968: String title = MVNForumResourceBundle.getString(locale,
0969: "mvnforum.user.editthreadtype.title");
0970: StringBuffer stb = new StringBuffer();
0971: stb.append(title).append(": ").append(
0972: threadBean.getThreadTopic());
0973:
0974: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
0975: CategoryTree categorytree = new CategoryTree(treebuilder);
0976: CategoryTreeListener treelistener = new CategoryTreePath(
0977: request, response, forumBean.getForumID(), null, null,
0978: stb.toString());
0979: categorytree.addCategeoryTreeListener(treelistener);
0980: request.setAttribute("tree", categorytree.build());
0981:
0982: }
0983:
0984: public void processEditThreadType(GenericRequest request)
0985: throws BadInputException, ObjectNotFoundException,
0986: DatabaseException, AuthenticationException {
0987:
0988: SecurityUtil.checkHttpPostMethod(request);
0989:
0990: OnlineUser onlineUser = onlineUserManager
0991: .getOnlineUser(request);
0992: MVNForumPermission permission = onlineUser.getPermission();
0993:
0994: // user must have been authenticated before he can edit thread status
0995: permission.ensureIsAuthenticated();
0996:
0997: Locale locale = I18nUtil.getLocaleInRequest(request);
0998:
0999: // primary key column(s)
1000: int threadID = GenericParamUtil.getParameterInt(request,
1001: "thread");
1002: int threadType = GenericParamUtil.getParameterUnsignedInt(
1003: request, "ThreadType", ThreadBean.THREAD_TYPE_DEFAULT);
1004:
1005: ThreadBean threadBean = null;
1006: try {
1007: threadBean = DAOFactory.getThreadDAO().getThread(threadID);
1008: } catch (ObjectNotFoundException e) {
1009: String localizedMessage = MVNForumResourceBundle
1010: .getString(
1011: locale,
1012: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
1013: new Object[] { new Integer(threadID) });
1014: throw new ObjectNotFoundException(localizedMessage);
1015: }
1016: int forumID = threadBean.getForumID();
1017:
1018: ForumCache.getInstance().getBean(forumID)
1019: .ensureNotDisabledForum();
1020:
1021: if (threadType > ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT /* 3 */) {
1022: throw new BadInputException("Not support this thread type");
1023: }
1024:
1025: if ((threadType == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT)
1026: || (threadBean.getThreadType() == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT)) {
1027: permission.ensureCanAdminSystem();
1028: } else {
1029: permission.ensureCanModerateThread(forumID);
1030: }
1031:
1032: // now check the password
1033: MyUtil.ensureCorrectCurrentPassword(request);
1034:
1035: DAOFactory.getThreadDAO()
1036: .updateThreadType(threadID, threadType);
1037: //@todo: should update other info ???
1038:
1039: // Clear the cache
1040: ThreadCache.getInstance().clear();
1041: PostCache.getInstance().clear();// affect mostActiveThreads in Post
1042:
1043: request.setAttribute("ThreadID", String.valueOf(threadID));
1044: request.setAttribute("ForumID", String.valueOf(forumID));
1045: }
1046:
1047: public void prepareList_limit(GenericRequest request,
1048: GenericResponse response, String requestURI)
1049: throws AuthenticationException, DatabaseException,
1050: BadInputException, ObjectNotFoundException,
1051: MissingURLMapEntryException {
1052:
1053: OnlineUserUtil.updateOnlineUserAction(request, requestURI);
1054:
1055: OnlineUser onlineUser = onlineUserManager
1056: .getOnlineUser(request);
1057: MVNForumPermission permission = onlineUser.getPermission();
1058:
1059: Locale locale = I18nUtil.getLocaleInRequest(request);
1060:
1061: int forumID = GenericParamUtil
1062: .getParameterInt(request, "forum");
1063:
1064: // make sure there is the forum
1065: // will throw an BadInputException if there is not this forum
1066: ForumBean forumBean = ForumCache.getInstance().getBean(forumID);
1067:
1068: CategoryBuilder treebuilder = new DefaultCategoryBuilder();
1069: CategoryTree categorytree = new CategoryTree(treebuilder);
1070: CategoryTreeListener treelistener = new CategoryTreePath(
1071: request, response, forumID, 0, null);
1072: categorytree.addCategeoryTreeListener(treelistener);
1073: request.setAttribute("tree", categorytree.build());
1074:
1075: forumBean.ensureNotDisabledForum();
1076:
1077: // make sure user can read post in this forum
1078: permission.ensureCanReadPost(forumID);
1079:
1080: // for sort and order stuff
1081: String sort = GenericParamUtil.getParameter(request, "sort");
1082: String order = GenericParamUtil.getParameter(request, "order");
1083: if (sort.length() == 0)
1084: sort = "ThreadLastPostDate";
1085: if (order.length() == 0)
1086: order = "DESC";
1087:
1088: int postsPerPage = onlineUser.getPostsPerPage();
1089: int offset = 0;
1090: try {
1091: offset = GenericParamUtil.getParameterUnsignedInt(request,
1092: "offset");
1093: } catch (BadInputException e) {
1094: // do nothing
1095: }
1096:
1097: int totalThreads = ThreadCache.getInstance()
1098: .getNumberOfEnableThreads_inForum(forumID);
1099: int totalNormalThreads = ThreadCache.getInstance()
1100: .getNumberOfNormalEnableThreads_inForum(forumID);
1101: if (offset > totalNormalThreads) {
1102: String localizedMessage = MVNForumResourceBundle
1103: .getString(locale,
1104: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1105: throw new BadInputException(localizedMessage);
1106: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1107: }
1108:
1109: Collection threadBeans = ThreadCache.getInstance()
1110: .getNormalEnableThreads_inForum_withSortSupport_limit(
1111: forumID, offset, postsPerPage, sort, order);
1112:
1113: // the correct value is the enable posts - disable threads, so we could get directly from the ForumBean
1114: //int totalPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);
1115: int totalPosts = forumBean.getForumPostCount();
1116:
1117: int pendingThreadCount = 0;
1118: int threadsWithPendingPostsCount = 0;
1119: if (permission.canModerateThread(forumID)) {
1120: pendingThreadCount = DAOFactory.getThreadDAO()
1121: .getNumberOfDisableThreads_inForum(forumID);
1122: threadsWithPendingPostsCount = DAOFactory.getThreadDAO()
1123: .getNumberOfEnableThreadsWithPendingPosts_inForum(
1124: forumID);
1125: }
1126:
1127: Collection allThreadBeans = new ArrayList();
1128:
1129: Collection globalAnnounces = ThreadCache.getInstance()
1130: .getEnableGlobalAnnouncements();
1131: allThreadBeans.addAll(globalAnnounces);
1132: Collection announcements = ThreadCache.getInstance()
1133: .getEnableForumAnnouncements_inForum(forumID);
1134: allThreadBeans.addAll(announcements);
1135: if (offset == 0) {
1136: Collection stickies = ThreadCache.getInstance()
1137: .getEnableStickies_inForum(forumID);
1138: allThreadBeans.addAll(stickies);
1139: }
1140: allThreadBeans.addAll(threadBeans);
1141:
1142: request.setAttribute("ThreadBeans", allThreadBeans);
1143: request.setAttribute("TotalThreads", new Integer(totalThreads));
1144: request.setAttribute("TotalNormalThreads", new Integer(
1145: totalNormalThreads));
1146: request.setAttribute("TotalPosts", new Integer(totalPosts));
1147: request.setAttribute("PendingThreadCount", new Integer(
1148: pendingThreadCount));
1149: request.setAttribute("ThreadsWithPendingPostsCount",
1150: new Integer(threadsWithPendingPostsCount));
1151:
1152: CategoryBuilder builder = new DefaultCategoryBuilder();
1153: CategoryTree tree = new CategoryTree(builder);
1154: CategoryTreeListener listener = categoryService
1155: .getManagementCategorySelector(request, response,
1156: "viewthread", forumID);
1157: tree.addCategeoryTreeListener(listener);
1158: request.setAttribute("Result", tree.build());
1159:
1160: if (MVNForumConfig.getEnableOnlineUsers()) {
1161: OnlineUserUtil.setRequestAttributeOfOnlineActions(request,
1162: Action.PAGE_ID_LISTTHREADS, new Integer(forumID));
1163: }
1164:
1165: if (MVNForumConfig.getEnableEasyWatching()) {
1166: // check whether this forum is being watched
1167: Boolean isWatched = Boolean.FALSE;
1168: if (onlineUser.isMember()) {
1169: isWatched = new Boolean(WatchUtil.isForumWatched(
1170: onlineUser.getMemberID(), forumBean));
1171: }
1172: request.setAttribute("isWatched", isWatched);
1173: }
1174: }
1175:
1176: public void prepareListRecentThreads_limit(GenericRequest request,
1177: GenericResponse response) throws DatabaseException,
1178: BadInputException, AuthenticationException,
1179: ObjectNotFoundException, DatabaseException {
1180:
1181: OnlineUser onlineUser = onlineUserManager
1182: .getOnlineUser(request);
1183: MVNForumPermission permission = onlineUser.getPermission();
1184:
1185: Locale locale = I18nUtil.getLocaleInRequest(request);
1186:
1187: // for sort and order stuff
1188: String sort = GenericParamUtil.getParameter(request, "sort");
1189: String order = GenericParamUtil.getParameter(request, "order");
1190: if (sort.length() == 0)
1191: sort = "ThreadLastPostDate";
1192: if (order.length() == 0)
1193: order = "DESC";
1194:
1195: int postsPerPage = onlineUser.getPostsPerPage();
1196: int offset = 0;
1197: try {
1198: offset = GenericParamUtil.getParameterUnsignedInt(request,
1199: "offset");
1200: } catch (BadInputException e) {
1201: // do nothing
1202: }
1203:
1204: int totalThreads = DAOFactory.getThreadDAO()
1205: .getNumberOfEnableThreads(false, -1, -1, -1);
1206: if (offset > totalThreads) {
1207: String localizedMessage = MVNForumResourceBundle
1208: .getString(locale,
1209: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1210: throw new BadInputException(localizedMessage);
1211: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1212: }
1213:
1214: Collection threadBeans = DAOFactory.getThreadDAO()
1215: .getEnableThreads_withSortSupport_limit(offset,
1216: postsPerPage, sort, order, false, -1, -1, -1);
1217:
1218: // now remove thread that current user does not have permission
1219: for (Iterator iterator = threadBeans.iterator(); iterator
1220: .hasNext();) {
1221: ThreadBean threadBean = (ThreadBean) iterator.next();
1222: int currentForumID = threadBean.getForumID();
1223: if (permission.canReadPost(currentForumID) == false) {
1224: iterator.remove();
1225: } else if (ForumCache.getInstance().getBean(currentForumID)
1226: .getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1227: iterator.remove();
1228: }
1229: }
1230:
1231: request.setAttribute("ThreadBeans", threadBeans);
1232: request.setAttribute("TotalThreads", new Integer(totalThreads));
1233:
1234: CategoryBuilder builder = new DefaultCategoryBuilder();
1235: CategoryTree tree = new CategoryTree(builder);
1236: CategoryTreeListener listener = categoryService
1237: .getManagementCategorySelector(request, response,
1238: "listrecentthreads");
1239: tree.addCategeoryTreeListener(listener);
1240: request.setAttribute("Result", tree.build());
1241: }
1242:
1243: public void prepareListRecentDisabledThreads_limit(
1244: GenericRequest request) throws DatabaseException,
1245: BadInputException, AuthenticationException,
1246: ObjectNotFoundException {
1247:
1248: OnlineUser onlineUser = onlineUserManager
1249: .getOnlineUser(request);
1250: MVNForumPermission permission = onlineUser.getPermission();
1251:
1252: // user must have been authenticated before he can view pending/disabled threads
1253: permission.ensureIsAuthenticated();
1254: permission.ensureCanModerateThreadInAnyForum();
1255:
1256: Locale locale = I18nUtil.getLocaleInRequest(request);
1257:
1258: // for sort and order stuff
1259: String sort = GenericParamUtil.getParameter(request, "sort");
1260: String order = GenericParamUtil.getParameter(request, "order");
1261: if (sort.length() == 0)
1262: sort = "ThreadLastPostDate";
1263: if (order.length() == 0)
1264: order = "DESC";
1265:
1266: int postsPerPage = onlineUser.getPostsPerPage();
1267: int offset = 0;
1268: try {
1269: offset = GenericParamUtil.getParameterUnsignedInt(request,
1270: "offset");
1271: } catch (BadInputException e) {
1272: // do nothing
1273: }
1274:
1275: int totalThreads = DAOFactory.getThreadDAO()
1276: .getNumberOfDisableThreads();
1277: if (offset > totalThreads) {
1278: String localizedMessage = MVNForumResourceBundle
1279: .getString(locale,
1280: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1281: throw new BadInputException(localizedMessage);
1282: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1283: }
1284:
1285: Collection threadBeans = DAOFactory.getThreadDAO()
1286: .getDisableBeans_withSortSupport_limit(offset,
1287: postsPerPage, sort, order);
1288:
1289: // now remove thread that current user does not have permission
1290: for (Iterator iterator = threadBeans.iterator(); iterator
1291: .hasNext();) {
1292: ThreadBean threadBean = (ThreadBean) iterator.next();
1293: int currentForumID = threadBean.getForumID();
1294: if (permission.canModerateThread(currentForumID) == false) {
1295: iterator.remove();
1296: } else if (ForumCache.getInstance().getBean(currentForumID)
1297: .getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1298: iterator.remove();
1299: }
1300: }
1301:
1302: request.setAttribute("ThreadBeans", threadBeans);
1303: request.setAttribute("TotalThreads", new Integer(totalThreads));
1304: }
1305:
1306: public void prepareListDisabledThreads_limit_xml(
1307: GenericRequest request) throws DatabaseException,
1308: AuthenticationException, ObjectNotFoundException {
1309:
1310: OnlineUser onlineUser = onlineUserManager
1311: .getOnlineUser(request);
1312: MVNForumPermission permission = onlineUser.getPermission();
1313:
1314: // user must have been authenticated before he can view pending/disabled threads
1315: permission.ensureIsAuthenticated();
1316: permission.ensureCanModerateThreadInAnyForum();
1317:
1318: Collection pendingThreadBeans = DAOFactory.getThreadDAO()
1319: .getDisableBeans_withSortSupport_limit(0, 10000,
1320: "ThreadLastPostDate", "DESC");
1321: // now remove thread that current user does not have permission
1322: for (Iterator iterator = pendingThreadBeans.iterator(); iterator
1323: .hasNext();) {
1324: ThreadBean threadBean = (ThreadBean) iterator.next();
1325: if (permission.canModerateThread(threadBean.getForumID()) == false) {
1326: iterator.remove();
1327: }
1328: }
1329:
1330: Collection threadWithPendingPostsBeans = DAOFactory
1331: .getThreadDAO()
1332: .getEnableThreadsWithPendingPosts_withSortSupport_limit(
1333: 0, 10000, "ForumID", "DESC");
1334: for (Iterator iterator = threadWithPendingPostsBeans.iterator(); iterator
1335: .hasNext();) {
1336: ThreadBean threadBean = (ThreadBean) iterator.next();
1337: if (permission.canModerateThread(threadBean.getForumID()) == false) {
1338: iterator.remove();
1339: } else {
1340: Collection pendingPosts = DAOFactory.getPostDAO()
1341: .getDisablePosts_inThread_limit(
1342: threadBean.getThreadID(), 0, 10000);
1343: threadBean.setPendingPosts(pendingPosts);
1344: }
1345: }
1346:
1347: request.setAttribute("PendingThreadBeans", pendingThreadBeans);
1348: request.setAttribute("ThreadWithPendingPostsBeans",
1349: threadWithPendingPostsBeans);
1350: }
1351:
1352: public void prepareListRecentEnableThreadsWithPendingPosts_limit(
1353: GenericRequest request) throws DatabaseException,
1354: BadInputException, AuthenticationException,
1355: ObjectNotFoundException {
1356:
1357: OnlineUser onlineUser = onlineUserManager
1358: .getOnlineUser(request);
1359: MVNForumPermission permission = onlineUser.getPermission();
1360:
1361: // user must have been authenticated before he can view enable threads with pending posts
1362: permission.ensureIsAuthenticated();
1363: permission.ensureCanModerateThreadInAnyForum();
1364:
1365: Locale locale = I18nUtil.getLocaleInRequest(request);
1366:
1367: // for sort and order stuff
1368: String sort = GenericParamUtil.getParameter(request, "sort");
1369: String order = GenericParamUtil.getParameter(request, "order");
1370: if (sort.length() == 0)
1371: sort = "ThreadLastPostDate";
1372: if (order.length() == 0)
1373: order = "DESC";
1374:
1375: int postsPerPage = onlineUser.getPostsPerPage();
1376: int offset = 0;
1377: try {
1378: offset = GenericParamUtil.getParameterUnsignedInt(request,
1379: "offset");
1380: } catch (BadInputException e) {
1381: // do nothing
1382: }
1383:
1384: int totalThreads = DAOFactory.getThreadDAO()
1385: .getNumberOfEnableThreadsWithPendingPosts();
1386: if (offset > totalThreads) {
1387: String localizedMessage = MVNForumResourceBundle
1388: .getString(locale,
1389: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1390: throw new BadInputException(localizedMessage);
1391: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1392: }
1393:
1394: Collection threadBeans = DAOFactory
1395: .getThreadDAO()
1396: .getEnableThreadsWithPendingPosts_withSortSupport_limit(
1397: offset, postsPerPage, sort, order);
1398:
1399: // now remove thread that current user does not have permission
1400: for (Iterator iterator = threadBeans.iterator(); iterator
1401: .hasNext();) {
1402: ThreadBean threadBean = (ThreadBean) iterator.next();
1403: int currentForumID = threadBean.getForumID();
1404: if (permission.canModerateThread(currentForumID) == false) {
1405: iterator.remove();
1406: } else if (ForumCache.getInstance().getBean(currentForumID)
1407: .getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1408: iterator.remove();
1409: }
1410: }
1411:
1412: request.setAttribute("ThreadBeans", threadBeans);
1413: request.setAttribute("TotalThreads", new Integer(totalThreads));
1414: }
1415:
1416: public void prepareListEnableThreadsWithPendingPosts_inForum_limit(
1417: GenericRequest request) throws DatabaseException,
1418: BadInputException, AuthenticationException,
1419: ObjectNotFoundException {
1420:
1421: OnlineUser onlineUser = onlineUserManager
1422: .getOnlineUser(request);
1423: MVNForumPermission permission = onlineUser.getPermission();
1424:
1425: // user must have been authenticated before he can view enable threads with pending posts
1426: permission.ensureIsAuthenticated();
1427:
1428: int forumID = GenericParamUtil
1429: .getParameterInt(request, "forum");
1430: permission.ensureCanModerateThread(forumID);
1431:
1432: ForumCache.getInstance().getBean(forumID)
1433: .ensureNotDisabledForum();
1434:
1435: Locale locale = I18nUtil.getLocaleInRequest(request);
1436:
1437: // for sort and order stuff
1438: String sort = GenericParamUtil.getParameter(request, "sort");
1439: String order = GenericParamUtil.getParameter(request, "order");
1440: if (sort.length() == 0)
1441: sort = "ThreadLastPostDate";
1442: if (order.length() == 0)
1443: order = "DESC";
1444:
1445: int postsPerPage = onlineUser.getPostsPerPage();
1446: int offset = 0;
1447: try {
1448: offset = GenericParamUtil.getParameterUnsignedInt(request,
1449: "offset");
1450: } catch (BadInputException e) {
1451: // do nothing
1452: }
1453:
1454: int totalThreads = DAOFactory.getThreadDAO()
1455: .getNumberOfEnableThreadsWithPendingPosts_inForum(
1456: forumID);
1457: if (offset > totalThreads) {
1458: String localizedMessage = MVNForumResourceBundle
1459: .getString(locale,
1460: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1461: throw new BadInputException(localizedMessage);
1462: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1463: }
1464:
1465: Collection threadBeans = DAOFactory
1466: .getThreadDAO()
1467: .getEnableThreadsWithPendingPosts_inForum_withSortSupport_limit(
1468: forumID, offset, postsPerPage, sort, order);
1469:
1470: request.setAttribute("ThreadBeans", threadBeans);
1471: request.setAttribute("TotalThreads", new Integer(totalThreads));
1472: }
1473:
1474: public void prepareModerationControlPanel(GenericRequest request,
1475: GenericResponse response) throws DatabaseException,
1476: DatabaseException, DatabaseException,
1477: AuthenticationException {
1478:
1479: OnlineUser onlineUser = onlineUserManager
1480: .getOnlineUser(request);
1481: MVNForumPermission permission = onlineUser.getPermission();
1482:
1483: // user must have been authenticated before he can view enable threads with pending posts
1484: permission.ensureIsAuthenticated();
1485: permission.ensureCanModerateThreadInAnyForum();
1486:
1487: Collection forumBeans = ForumCache.getInstance().getBeans();
1488: for (Iterator iter = forumBeans.iterator(); iter.hasNext();) {
1489: ForumBean forumBean = (ForumBean) iter.next();
1490: int forumID = forumBean.getForumID();
1491:
1492: int pendingThreadCount = 0;
1493: int threadsWithPendingPostsCount = 0;
1494: int pendingPostCount = 0;
1495:
1496: if (permission.canModerateThread(forumID)
1497: && (forumBean.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED)) {
1498: pendingThreadCount = DAOFactory.getThreadDAO()
1499: .getNumberOfDisableThreads_inForum(forumID);
1500: threadsWithPendingPostsCount = DAOFactory
1501: .getThreadDAO()
1502: .getNumberOfEnableThreadsWithPendingPosts_inForum(
1503: forumID);
1504: pendingPostCount = DAOFactory.getPostDAO()
1505: .getNumberOfDisablePosts_inForum(forumID);
1506: }
1507:
1508: // note that if user does not have permission on this forum, then the value is 0
1509: forumBean.setPendingThreadCount(pendingThreadCount);
1510: forumBean
1511: .setThreadsWithPendingPostsCount(threadsWithPendingPostsCount);
1512: forumBean.setPendingPostCount(pendingPostCount);
1513: }
1514:
1515: int pendingThreadCount = DAOFactory.getThreadDAO()
1516: .getNumberOfDisableThreads();
1517: int threadsWithPendingPostsCount = DAOFactory.getThreadDAO()
1518: .getNumberOfEnableThreadsWithPendingPosts();
1519:
1520: // Note that because this forumBeans is a new instance
1521: // we have to put it in session instead of get it again from the ForumCache
1522: request.setAttribute("ForumBeans", forumBeans);
1523: request.setAttribute("PendingThreadCount", new Integer(
1524: pendingThreadCount));
1525: request.setAttribute("ThreadsWithPendingPostsCount",
1526: new Integer(threadsWithPendingPostsCount));
1527:
1528: CategoryBuilder builder = new DefaultCategoryBuilder();
1529: CategoryTree tree = new CategoryTree(builder);
1530: CategoryTreeListener listener = categoryService
1531: .getManagementModcp(request, response);
1532: tree.addCategeoryTreeListener(listener);
1533: request.setAttribute("Result", tree.build());
1534: }
1535:
1536: public void prepareModeratePendingThreads_inForum_limit(
1537: GenericRequest request) throws DatabaseException,
1538: AuthenticationException, BadInputException,
1539: DatabaseException, ObjectNotFoundException {
1540:
1541: OnlineUser onlineUser = onlineUserManager
1542: .getOnlineUser(request);
1543: MVNForumPermission permission = onlineUser.getPermission();
1544:
1545: // user must have been authenticated before he can view pending/disabled threads
1546: permission.ensureIsAuthenticated();
1547:
1548: int forumID = GenericParamUtil
1549: .getParameterInt(request, "forum");
1550:
1551: // make sure there is the forum
1552: // will throw an BadInputException if there is not this forum
1553: ForumCache.getInstance().getBean(forumID)
1554: .ensureNotDisabledForum();
1555: permission.ensureCanModerateThread(forumID);
1556:
1557: Locale locale = I18nUtil.getLocaleInRequest(request);
1558:
1559: // for sort and order stuff
1560: String sort = GenericParamUtil.getParameter(request, "sort");
1561: String order = GenericParamUtil.getParameter(request, "order");
1562: if (sort.length() == 0)
1563: sort = "ThreadLastPostDate";
1564: if (order.length() == 0)
1565: order = "DESC";
1566:
1567: int postsPerPage = onlineUser.getPostsPerPage();
1568: int offset = 0;
1569: try {
1570: offset = GenericParamUtil.getParameterUnsignedInt(request,
1571: "offset");
1572: } catch (BadInputException e) {
1573: // do nothing
1574: }
1575:
1576: int totalThreads = DAOFactory.getThreadDAO()
1577: .getNumberOfDisableThreads_inForum(forumID);
1578: if (offset > totalThreads) {
1579: String localizedMessage = MVNForumResourceBundle
1580: .getString(locale,
1581: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1582: throw new BadInputException(localizedMessage);
1583: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1584: }
1585:
1586: Collection threadBeans = DAOFactory.getThreadDAO()
1587: .getDisableThreads_inForum_withSortSupport_limit(
1588: forumID, offset, postsPerPage, sort, order);
1589: Collection firstPostBeans = new ArrayList();
1590:
1591: for (Iterator iterator = threadBeans.iterator(); iterator
1592: .hasNext();) {
1593: ThreadBean threadBean = (ThreadBean) iterator.next();
1594: PostBean postBean = DAOFactory.getPostDAO()
1595: .getFirstPost_inThread(threadBean.getThreadID());
1596: firstPostBeans.add(postBean);
1597:
1598: MemberBean memberBean = null;
1599: if (postBean.getMemberID() != 0
1600: && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
1601: // Use cache for maximum performance
1602: memberBean = MemberCache.getInstance().getMember(
1603: postBean.getMemberID());
1604: }
1605: postBean.setMemberBean(memberBean);
1606:
1607: int postAttachCount = postBean.getPostAttachCount();
1608: if ((postAttachCount > 0)
1609: && MVNForumConfig.getEnableAttachment()) {
1610: int postID = postBean.getPostID();
1611: Collection attachBeans = DAOFactory.getAttachmentDAO()
1612: .getAttachments_inPost(postID);
1613: int actualAttachCount = attachBeans.size();
1614:
1615: // now check if the attachCount in table Post equals to the actual attachCount in table Attachment
1616: if (postAttachCount != actualAttachCount) {
1617: if (actualAttachCount != DAOFactory
1618: .getAttachmentDAO()
1619: .getNumberOfAttachments_inPost(postID)) {
1620: String localizedMessage = MVNForumResourceBundle
1621: .getString(locale,
1622: "java.lang.AssertionError.serious_error.cannot_process_attachment_count");
1623: throw new AssertionError(localizedMessage);
1624: //throw new AssertionError("Assertion: Serious error: cannot process Attachment Count in table Attachment");
1625: }
1626: log
1627: .warn("The attachment count in table Post and Attachment are not synchronized. In table Post = "
1628: + postAttachCount
1629: + " and in table Attachment = "
1630: + actualAttachCount
1631: + ". Synchronize to "
1632: + actualAttachCount);
1633: DAOFactory.getPostDAO().updateAttachCount(postID,
1634: actualAttachCount);
1635: }
1636: if (actualAttachCount > 0) {
1637: postBean.setAttachmentBeans(attachBeans);
1638: }
1639: }
1640: }
1641:
1642: request.setAttribute("FirstPostBeans", firstPostBeans);
1643: request.setAttribute("ThreadBeans", threadBeans);
1644: request.setAttribute("TotalThreads", new Integer(totalThreads));
1645: }
1646:
1647: public void processModeratePendingThreads(GenericRequest request)
1648: throws DatabaseException, AuthenticationException,
1649: BadInputException, DatabaseException,
1650: ObjectNotFoundException {
1651:
1652: SecurityUtil.checkHttpPostMethod(request);
1653:
1654: OnlineUser onlineUser = onlineUserManager
1655: .getOnlineUser(request);
1656: MVNForumPermission permission = onlineUser.getPermission();
1657:
1658: // user must have been authenticated before he can moderate pending/disabled threads
1659: permission.ensureIsAuthenticated();
1660:
1661: Locale locale = I18nUtil.getLocaleInRequest(request);
1662:
1663: // check normal permission, note that we dont check
1664: // permission on a forumID because we allow moderate posts
1665: // in multiple forums even if the web interface does not support it
1666: int forumID = -1;
1667: try {
1668: forumID = GenericParamUtil
1669: .getParameterInt(request, "forum");
1670: ForumCache.getInstance().getBean(forumID);// check valid forumID
1671: permission.ensureCanModerateThread(forumID);
1672:
1673: ForumCache.getInstance().getBean(forumID)
1674: .ensureNotDisabledForum();
1675: } catch (BadInputException ex) {
1676: // just ignore, in case of use customized client
1677: }
1678: permission.ensureCanModerateThreadInAnyForum();
1679:
1680: try {
1681: String prefix = "modthreadaction_";
1682: for (Enumeration enumeration = request.getParameterNames(); enumeration
1683: .hasMoreElements();) {
1684: String param = (String) enumeration.nextElement();
1685: if (param.startsWith(prefix)) {
1686: String modValue = GenericParamUtil.getParameter(
1687: request, param, true);
1688: String strThreadID = param.substring(prefix
1689: .length());
1690: int threadID = Integer.parseInt(strThreadID);
1691: if (modValue.equals("approve")) {
1692: ThreadBean threadBean = null;
1693: try {
1694: threadBean = DAOFactory.getThreadDAO()
1695: .getThread(threadID);
1696: } catch (ObjectNotFoundException e) {
1697: String localizedMessage = MVNForumResourceBundle
1698: .getString(
1699: locale,
1700: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
1701: new Object[] { new Integer(
1702: threadID) });
1703: throw new ObjectNotFoundException(
1704: localizedMessage);
1705: }
1706: int currentForumID = threadBean.getForumID();
1707: permission
1708: .ensureCanModerateThread(currentForumID);
1709: DAOFactory.getThreadDAO().updateThreadStatus(
1710: threadID,
1711: ThreadBean.THREAD_STATUS_DEFAULT);
1712:
1713: // now if change from Disable to Enable, update the lastpostdate so
1714: // that the Watch will see this thread as a new thread
1715: if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
1716: Timestamp now = DateUtil
1717: .getCurrentGMTTimestamp();
1718: DAOFactory.getThreadDAO()
1719: .updateLastPostDate(threadID, now);
1720: }
1721: } else if (modValue.equals("delete")) {
1722: ThreadBean threadBean = null;
1723: try {
1724: threadBean = DAOFactory.getThreadDAO()
1725: .getThread(threadID);
1726: } catch (ObjectNotFoundException e) {
1727: String localizedMessage = MVNForumResourceBundle
1728: .getString(
1729: locale,
1730: "mvncore.exception.ObjectNotFoundException.threadid_not_exists",
1731: new Object[] { new Integer(
1732: threadID) });
1733: throw new ObjectNotFoundException(
1734: localizedMessage);
1735: }
1736: deleteThread(request, threadBean);
1737: } else {
1738: // it means ignore, do nothing
1739: }
1740: }
1741: }
1742: } finally {
1743: // now update the forum statistics
1744: if (forumID != -1) {
1745: StatisticsUtil.updateForumStatistics(forumID);
1746: }
1747: }
1748:
1749: // Now clear the cache
1750: PostCache.getInstance().clear();
1751: ThreadCache.getInstance().clear();
1752:
1753: request.setAttribute("ForumID", String.valueOf(forumID));
1754: }
1755:
1756: public void prepareList_inFavorite(GenericRequest request)
1757: throws DatabaseException, AuthenticationException,
1758: ObjectNotFoundException {
1759:
1760: OnlineUser onlineUser = onlineUserManager
1761: .getOnlineUser(request);
1762: MVNForumPermission permission = onlineUser.getPermission();
1763: permission.ensureIsAuthenticated();
1764:
1765: int memberID = onlineUser.getMemberID();
1766:
1767: Collection threadBeans = DAOFactory.getThreadDAO()
1768: .getThreads_inFavorite_inMember(memberID);
1769:
1770: //remove threads that current user dont have permission
1771: for (Iterator iter = threadBeans.iterator(); iter.hasNext();) {
1772: ThreadBean threadBean = (ThreadBean) iter.next();
1773: int currentForumID = threadBean.getForumID();
1774: if (permission.canReadPost(currentForumID) == false) {
1775: iter.remove();
1776: } else if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
1777: if (permission.canModerateThread(currentForumID) == false) {
1778: iter.remove();
1779: }
1780: } else if (ForumCache.getInstance().getBean(currentForumID)
1781: .getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1782: iter.remove();
1783: }
1784: }
1785: int max = MVNForumConfig.getMaxFavoriteThreads();
1786: int favoriteThreadCount = threadBeans.size();
1787: double ratio = 0;
1788: if (max == 0) {
1789: ratio = 1.0;
1790: } else {
1791: ratio = (double) favoriteThreadCount / max;
1792: }
1793: request.setAttribute("QuotaRatio", new Double(ratio * 100));
1794: request.setAttribute("ThreadBeans", threadBeans);
1795: }
1796:
1797: public void prepareRSSSummary(GenericRequest request,
1798: GenericResponse response) throws DatabaseException,
1799: AuthenticationException {
1800:
1801: // for sort and order stuff
1802: String sort = GenericParamUtil.getParameter(request, "sort");
1803: String order = GenericParamUtil.getParameter(request, "order");
1804: if (sort.length() == 0)
1805: sort = "ThreadLastPostDate";
1806: if (order.length() == 0)
1807: order = "DESC";
1808:
1809: // call this to check the parameter sort and order
1810: DAOFactory.getThreadDAO()
1811: .getEnableThreads_withSortSupport_limit(0/*offset*/,
1812: 1/*rows*/, sort, order, false, -1, -1, -1);
1813:
1814: CategoryBuilder builder = new DefaultCategoryBuilder();
1815: CategoryTree tree = new CategoryTree(builder);
1816: CategoryTreeListener listener = categoryService
1817: .getManagementRSS(request, response, sort, order);
1818: tree.addCategeoryTreeListener(listener);
1819: request.setAttribute("Result", tree.build());
1820: }
1821:
1822: public void prepareListRSS(GenericRequest request)
1823: throws DatabaseException, AuthenticationException,
1824: ObjectNotFoundException {
1825:
1826: OnlineUser onlineUser = onlineUserManager
1827: .getOnlineUser(request);
1828: MVNForumPermission permission = onlineUser.getPermission();
1829:
1830: // for sort and order stuff
1831: String sort = GenericParamUtil.getParameter(request, "sort");
1832: String order = GenericParamUtil.getParameter(request, "order");
1833: if (sort.length() == 0)
1834: sort = "ThreadLastPostDate";
1835: if (order.length() == 0)
1836: order = "DESC";
1837:
1838: int offset = 0;// offset MUST always equals 0, please dont change !!!
1839: int rows = MVNForumConfig.getRowsPerRSS();
1840: try {
1841: rows = GenericParamUtil.getParameterInt(request, "rows");
1842: if (rows <= 0)
1843: rows = MVNForumConfig.getRowsPerRSS();
1844: } catch (Exception ex) {
1845: //just ignore
1846: }
1847:
1848: // now find that user want global/category/forum RSS
1849: int forumID = -1;
1850: int categoryID = -1;
1851:
1852: try {
1853: forumID = GenericParamUtil
1854: .getParameterInt(request, "forum");
1855:
1856: // check if forum id existed or not
1857: ForumCache.getInstance().getBean(forumID);
1858: } catch (BadInputException ex) {
1859: try {
1860: categoryID = GenericParamUtil.getParameterInt(request,
1861: "category");
1862:
1863: // check if category id existed or not
1864: CategoryCache.getInstance().getBean(categoryID);
1865: } catch (BadInputException ex1) {
1866: }
1867: }
1868:
1869: Collection threadBeans = null;
1870: if (forumID > 0) {
1871: if (permission.canReadPost(forumID)) {
1872: threadBeans = DAOFactory
1873: .getThreadDAO()
1874: .getAllEnableThreads_inForum_withSortSupport_limit(
1875: forumID, offset, rows, sort, order);
1876: } else {
1877: // dont have permission on this forum, just create empty Collection
1878: threadBeans = new ArrayList();
1879: }
1880: } else if (categoryID > 0) {
1881: //@todo implement later
1882: } else {// global RSS
1883: threadBeans = DAOFactory.getThreadDAO()
1884: .getEnableThreads_withSortSupport_limit(offset,
1885: rows, sort, order, false, -1, -1, -1);
1886:
1887: //remove threads that current user dont have permission
1888: for (Iterator iter = threadBeans.iterator(); iter.hasNext();) {
1889: ThreadBean threadBean = (ThreadBean) iter.next();
1890: int currentForumID = threadBean.getForumID();
1891: if (permission.canReadPost(currentForumID) == false) {
1892: iter.remove();
1893: } else if (ForumCache.getInstance().getBean(
1894: currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1895: iter.remove();
1896: }
1897: }
1898: }
1899:
1900: request.setAttribute("ThreadBeans", threadBeans);
1901: request.setAttribute("ForumID", new Integer(forumID));
1902: request.setAttribute("CategoryID", new Integer(categoryID));
1903: }
1904:
1905: public void prepareListUnansweredThreads(GenericRequest request,
1906: GenericResponse response) throws BadInputException,
1907: DatabaseException, ObjectNotFoundException,
1908: AuthenticationException {
1909:
1910: OnlineUser onlineUser = onlineUserManager
1911: .getOnlineUser(request);
1912: MVNForumPermission permission = onlineUser.getPermission();
1913:
1914: Locale locale = I18nUtil.getLocaleInRequest(request);
1915:
1916: // for sort and order stuff
1917: String sort = GenericParamUtil.getParameter(request, "sort");
1918: String order = GenericParamUtil.getParameter(request, "order");
1919: if (sort.length() == 0)
1920: sort = "ThreadCreationDate";
1921: if (order.length() == 0)
1922: order = "DESC";
1923:
1924: int postsPerPage = onlineUser.getPostsPerPage();
1925: int offset = 0;
1926: try {
1927: offset = GenericParamUtil.getParameterUnsignedInt(request,
1928: "offset");
1929: } catch (BadInputException e) {
1930: // do nothing
1931: }
1932:
1933: int category = -1;
1934: int forum = -1;
1935:
1936: String inputCategory = GenericParamUtil.getParameter(request,
1937: "category");
1938: if (inputCategory.length() > 0) {
1939: category = GenericParamUtil.getParameterUnsignedInt(
1940: request, "category");
1941: }
1942:
1943: String inputForum = GenericParamUtil.getParameter(request,
1944: "forum");
1945: if (inputForum.length() > 0) {
1946: forum = GenericParamUtil.getParameterUnsignedInt(request,
1947: "forum");
1948: }
1949: int threadStatus = -1;
1950: String status = GenericParamUtil
1951: .getParameter(request, "status");
1952: if (status.length() == 0) {
1953: status = "all";
1954: }
1955:
1956: if (status.equalsIgnoreCase("active")) {
1957: threadStatus = ThreadBean.THREAD_STATUS_DEFAULT;
1958: } else if (status.equalsIgnoreCase("closed")) {
1959: threadStatus = ThreadBean.THREAD_STATUS_CLOSED;
1960: } else if (status.equalsIgnoreCase("locked")) {
1961: threadStatus = ThreadBean.THREAD_STATUS_LOCKED;
1962: } else if (status.equalsIgnoreCase("all")) {
1963: threadStatus = -1;
1964: } else {
1965: throw new BadInputException(
1966: "The value of parameter 'status' is invalid");
1967: }
1968: // get all threads from database
1969: int totalOfUnanswerThread = DAOFactory.getThreadDAO()
1970: .getNumberOfEnableThreads(true, threadStatus, category,
1971: forum);
1972:
1973: if (offset > totalOfUnanswerThread) {
1974: String localizedMessage = MVNForumResourceBundle
1975: .getString(locale,
1976: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1977: throw new BadInputException(localizedMessage);
1978: }
1979: // only base on unanswered threads
1980: Collection threadBeans = DAOFactory.getThreadDAO()
1981: .getEnableThreads_withSortSupport_limit(offset,
1982: postsPerPage, sort, order, true, threadStatus,
1983: category, forum);
1984: for (Iterator iterator = threadBeans.iterator(); iterator
1985: .hasNext();) {
1986: ThreadBean threadBean = (ThreadBean) iterator.next();
1987: int currentForumID = threadBean.getForumID();
1988: // check again
1989: if (permission.canReadPost(currentForumID) == false) {
1990: iterator.remove();
1991: } else if (ForumCache.getInstance().getBean(currentForumID)
1992: .getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
1993: iterator.remove();
1994: }
1995: }
1996: request.setAttribute("ThreadBeans", threadBeans);
1997: request.setAttribute("TotalThreads", new Integer(
1998: totalOfUnanswerThread));
1999:
2000: CategoryBuilder builder = new DefaultCategoryBuilder();
2001: CategoryTree tree = new CategoryTree(builder);
2002: CategoryTreeListener listener = categoryService
2003: .getManagementCategorySelector(request, response,
2004: "listunansweredthreads", forum, category);
2005: tree.addCategeoryTreeListener(listener);
2006: request.setAttribute("Result", tree.build());
2007: }
2008:
2009: }
|