📄 postwebhandler.java
字号:
int favoriteOption = 0; //@todo implement it later
int favoriteStatus = 0; //@todo implement it later
// now check permission the this user have the readPost permission
permission.ensureCanReadPost(forumID);
// has the permission now, then insert to database
try {
DAOFactory.getFavoriteThreadDAO().create(logonMemberID, threadID, forumID,
favoriteCreationDate, favoriteType, favoriteOption, favoriteStatus);
} catch (DuplicateKeyException ex) {
// already add favorite thread, just ignore
}
}
}
//add watch if user checked it
if (addWatchThread) {
permission.ensureIsAuthenticated();
permission.ensureIsActivated();
if (MVNForumConfig.getEnableWatch() == false) {
// should never happen, because if it happen, then the whole process is broken
throw new AssertionException("Cannot add Watch because Watch feature is disabled by administrator.");
}
int watchType = 0;//ParamUtil.getParameterInt(request, "WatchType");
int watchOption = 0;//ParamUtil.getParameterInt(request, "WatchOption");
int watchStatus = 0;//ParamUtil.getParameterInt(request, "WatchStatus");
Timestamp watchCreationDate = now;
Timestamp watchLastSentDate = now;
Timestamp watchEndDate = now;// @todo: check it !!!
try {
DAOFactory.getWatchDAO().create(logonMemberID, 0/*watchCategoryID*/, 0/*watchForumID*/,
threadID, watchType, watchOption,
watchStatus, watchCreationDate, watchLastSentDate,
watchEndDate);
} catch (DuplicateKeyException ex) {
// User try to create a duplicate watch, just ignore
}
}
request.setAttribute("ForumID", String.valueOf(forumID));
request.setAttribute("ThreadID", String.valueOf(threadID));
request.setAttribute("AttachMore", new Boolean(attachMore));
request.setAttribute("PostBean", postBean);
// now update the search index
//@todo : modify for better performance here
PostIndexer.scheduleUpdatePostTask(DAOFactory.getPostDAO().getPost(postID));
}
void prepareDelete(HttpServletRequest request)
throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can delete
permission.ensureIsAuthenticated();
// primary key column(s)
int postID = ParamUtil.getParameterInt(request, "post");
PostBean postBean = DAOFactory.getPostDAO().getPost(postID);
int forumID = postBean.getForumID();
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
if (postBean.getParentPostID() == 0) {
throw new BadInputException("Cannot delete a root post. Use delete thread instead.");
}
// check constraint
int logonMemberID = onlineUser.getMemberID();
int authorID = postBean.getMemberID();
if (permission.canDeletePost(forumID)) {
// have permission, just do nothing, that is dont check the max day contraint
} else if (logonMemberID == authorID) {// same author
// check date here, usually must not older than 7 days
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Timestamp postDate = postBean.getPostCreationDate();
int maxDays = MVNForumConfig.getMaxDeleteDays();
if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
/** @todo choose a better Exception here */
throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
}
//Check to make sure that "no reply" for this post
int threadID = postBean.getThreadID();
Collection postBeans = DAOFactory.getPostDAO().getEnablePosts_inThread_limit(threadID, 0, 10000);
boolean foundReply = false;
for (Iterator ite = postBeans.iterator(); ite.hasNext(); ) {
PostBean tPostBean = (PostBean) ite.next();
if (tPostBean.getParentPostID() == postBean.getPostID()) {
foundReply = true;
break;
}
}
if (foundReply) {
throw new BadInputException("Cannot delete a post that has reply!");
}
if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) {
throw new BadInputException("Cannot delete your own post in pending status.");
}
} else {//not an author, so this user must have Edit Permission
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
}
request.setAttribute("PostBean", postBean);
}
void processDelete(HttpServletRequest request)
throws BadInputException, DatabaseException, AuthenticationException, AssertionException, ObjectNotFoundException {
// primary key column(s)
int postID = ParamUtil.getParameterInt(request, "post");
PostBean postBean = DAOFactory.getPostDAO().getPost(postID);
// now check the password
MyUtil.ensureCorrectCurrentPassword(request);
ForumCache.getInstance().getBean(postBean.getForumID()).ensureNotDisabledForum();
// delete the post and children attachments
deletePost(request, postBean);
int threadID = postBean.getThreadID();
int forumID = postBean.getForumID();
// now update the forum and thread statistics
StatisticsUtil.updateForumStatistics(forumID);
StatisticsUtil.updateThreadStatistics(threadID);
request.setAttribute("ForumID", String.valueOf(forumID));
request.setAttribute("ThreadID", String.valueOf(threadID));
}
// Note that this method does not update the forum statistics and thread statistics
private void deletePost(HttpServletRequest request, PostBean postBean)
throws AssertionException, DatabaseException, AuthenticationException,
BadInputException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can delete
permission.ensureIsAuthenticated();
int parentPostID = postBean.getParentPostID();
if (parentPostID == 0) {
throw new BadInputException("Cannot delete a root post. Use delete thread instead.");
}
int forumID = postBean.getForumID();
// check constraint
int logonMemberID = onlineUser.getMemberID();
int authorID = postBean.getMemberID();
if (permission.canDeletePost(forumID)) {
// have permission, just do nothing, that is dont check the max day contraint
} else if (logonMemberID == authorID) {// same author
// check date here, usually must not older than 7 days
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Timestamp postDate = postBean.getPostCreationDate();
int maxDays = MVNForumConfig.getMaxDeleteDays();
if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
/** @todo choose a better Exception here */
throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
}
//Check to make sure that "no reply" for this post
int threadID = postBean.getThreadID();
Collection postBeans = DAOFactory.getPostDAO().getEnablePosts_inThread_limit(threadID, 0, 10000);
boolean foundReply = false;
for (Iterator ite = postBeans.iterator(); ite.hasNext(); ) {
PostBean tPostBean = (PostBean) ite.next();
if (tPostBean.getParentPostID() == postBean.getPostID()) {
foundReply = true;
break;
}
}
if (foundReply) {
throw new BadInputException("Cannot delete a post that has reply!");
}
if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) {
throw new BadInputException("Cannot delete your own disabled post.");
}
} else {//not an author, so this user must have Edit Permission
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
}
int postID = postBean.getPostID();
// Delete all attachments in this post,
// we must call this before any attempt to delete the post
AttachmentWebHandler.deleteAttachments_inPost(postID);
// now delete the post, note that we delete it after delete all child objects (attachment)
DAOFactory.getPostDAO().delete(postID);
try {
DAOFactory.getPostDAO().updateParentPostID(postID, parentPostID);
} catch (ObjectNotFoundException ex) {
// we just ignore if no post is affect by this method
}
int memberID = postBean.getMemberID();
StatisticsUtil.updateMemberStatistics(memberID);
// now update the search index
PostIndexer.scheduleDeletePostTask(postID, DeletePostIndexTask.OBJECT_TYPE_POST);
}
void prepareModeratePendingPosts_limit(HttpServletRequest request)
throws AssertionException, DatabaseException, AuthenticationException, BadInputException,
DatabaseException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
int threadID = ParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
int forumID = threadBean.getForumID();
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
// user must have been authenticated before he can view pending/disabled threads
permission.ensureIsAuthenticated();
// check normal permission
permission.ensureCanModerateThread(forumID);
int postsPerPage = 10000;
int offset = 0;
Collection postBeans = DAOFactory.getPostDAO().getDisablePosts_inThread_limit(threadID, offset, postsPerPage);
Iterator iterator = postBeans.iterator();
while (iterator.hasNext()) {
PostBean postBean = (PostBean) iterator.next();
// very slow here
/** @todo find a better solution */
MemberBean memberBean = null;
if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
memberBean = DAOFactory.getMemberDAO().getMember_forPublic(postBean.getMemberID());
}
postBean.setMemberBean(memberBean);
int postAttachCount = postBean.getPostAttachCount();
if ((postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) {
int postID = postBean.getPostID();
Collection attachBeans = DAOFactory.getAttachmentDAO().getBeans_inPost(postID);
int actualAttachCount = attachBeans.size();
// now check if the attachCount in talbe Post equals to the actual attachCount in table Attachment
if (postAttachCount != actualAttachCount) {
if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfBeans_inPost(postID)) {
throw new AssertionException("AssertionException: Serious error: cannot process Attachment Count in table Attachment");
}
log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " +
postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount);
DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount);
}
if (actualAttachCount > 0) {
postBean.setAttachmentBeans(attachBeans);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -