📄 postwebhandler.java
字号:
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("PostID", String.valueOf(postID));
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));
// Clear the cache
PostCache.getInstance().clear();
ThreadCache.getInstance().clear();
}
public void prepareDelete(GenericRequest 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();
Locale locale = I18nUtil.getLocaleInRequest(request);
// primary key column(s)
int postID = GenericParamUtil.getParameterInt(request, "post");
PostBean postBean = null;
try {
postBean = DAOFactory.getPostDAO().getPost(postID);
} catch(ObjectNotFoundException ex) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object[] {new Integer(postID)});
throw new ObjectNotFoundException(localizedMessage);
}
int forumID = postBean.getForumID();
try {
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
throw new ObjectNotFoundException(localizedMessage);
}
if (postBean.getParentPostID() == 0) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_root_post");
throw new BadInputException(localizedMessage);
//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 */
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old");
throw new BadInputException(localizedMessage);
//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) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_post.post_has_reply");
throw new BadInputException(localizedMessage);
//throw new BadInputException("Cannot delete a post that has reply!");
}
if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_post.post_is_in_pending_status");
throw new BadInputException(localizedMessage);
//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);
}
public void processDelete(GenericRequest request)
throws BadInputException, DatabaseException, AuthenticationException, AssertionException, ObjectNotFoundException {
Locale locale = I18nUtil.getLocaleInRequest(request);
// primary key column(s)
int postID = GenericParamUtil.getParameterInt(request, "post");
PostBean postBean = null;
try {
postBean = DAOFactory.getPostDAO().getPost(postID);
} catch(ObjectNotFoundException ex) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object[] {new Integer(postID)});
throw new ObjectNotFoundException(localizedMessage);
}
// 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);
// Clear the cache
PostCache.getInstance().clear();
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(GenericRequest 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();
Locale locale = I18nUtil.getLocaleInRequest(request);
if (parentPostID == 0) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_root_post");
throw new BadInputException(localizedMessage);
//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 */
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object[] {new Integer(maxDays)});
throw new BadInputException(localizedMessage);
//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) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_post.post_has_reply");
throw new BadInputException(localizedMessage);
//throw new BadInputException("Cannot delete a post that has reply!");
}
if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_post.post_is_in_pending_status");
throw new BadInputException(localizedMessage);
//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);
}
public void prepareModeratePendingPosts_limit(GenericRequest request)
throws AssertionException, DatabaseException, AuthenticationException, BadInputException,
DatabaseException, ObjectNotFoundException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
Locale locale = I18nUtil.getLocaleInRequest(request);
int threadID = GenericParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = null;
try {
threadBean = DAOFactory.getThreadDAO().getThread(threadID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -