⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
    }

    public void processMoveThread(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        ForeignKeyNotFoundException, 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 threadID = GenericParamUtil.getParameterInt(request, "thread");

        // now, check the permission
        ThreadBean threadBean = null;
        try {
            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        int forumID = threadBean.getForumID();
        permission.ensureCanDeletePost(forumID);

        ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        int destForumID = GenericParamUtil.getParameterInt(request, "destforum");

        // make sure that we dont move to the same forum (meaningless)
        if (destForumID == forumID) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_move_thread_to_the_same_forum");
            throw new BadInputException(localizedMessage);
            //throw new AssertionException("Cannot move thread to the same forum.");
        }

        // now make sure that the dest forum is existed
        ForumCache.getInstance().getBean(destForumID);

        DAOFactory.getThreadDAO().updateForumID(threadID, destForumID);
        DAOFactory.getPostDAO().update_ForumID_inThread(threadID, destForumID);
        DAOFactory.getFavoriteThreadDAO().update_ForumID_inThread(threadID, destForumID);

        //now, update the statistics in the source forum and dest forum
        StatisticsUtil.updateForumStatistics(forumID);
        StatisticsUtil.updateForumStatistics(destForumID);

        // now update the search index
        // @todo : what if the above methods throw exception, then no thread is deleted from index ???
        PostIndexer.scheduleUpdateThreadTask(threadID);

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

        request.setAttribute("ForumID", String.valueOf(forumID));
    }

    public void prepareEditThreadStatus(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int threadID = GenericParamUtil.getParameterInt(request, "thread");

        ThreadBean threadBean = null;
        try {
            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();

        // now, check the permission
        permission.ensureCanModerateThread(threadBean.getForumID());

        int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);

        int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);

        request.setAttribute("ThreadBean", threadBean);
        request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
        request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
    }

    public void processEditThreadStatus(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // user must have been authenticated before he can edit thread status
        permission.ensureIsAuthenticated();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int threadID = GenericParamUtil.getParameterInt(request, "thread");

        // now, check the permission
        ThreadBean threadBean = null;
        try {
            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        int forumID = threadBean.getForumID();

        ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();

        permission.ensureCanModerateThread(forumID);

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        int threadStatus = GenericParamUtil.getParameterInt(request, "ThreadStatus");

        ThreadBean.validateThreadStatus(threadStatus);

        // now if change from Disable to Enable, update the lastpostdate so
        // that the Watch will see this thread as a new thread
        if ((threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) &&
            (threadStatus != ThreadBean.THREAD_STATUS_DISABLED)) {
            Timestamp now = DateUtil.getCurrentGMTTimestamp();
            DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
        }

        DAOFactory.getThreadDAO().updateThreadStatus(threadID, threadStatus);
        StatisticsUtil.updateForumStatistics(forumID);
        //@todo: should update other info ???

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

        request.setAttribute("ThreadID", String.valueOf(threadID));
        request.setAttribute("ForumID", String.valueOf(forumID));
    }

    public void prepareEditThreadType(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int threadID = GenericParamUtil.getParameterInt(request, "thread");

        ThreadBean threadBean = null;
        try {
            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();

        // now, check the permission
        permission.ensureCanModerateThread(threadBean.getForumID());

        int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);

        int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);

        request.setAttribute("ThreadBean", threadBean);
        request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
        request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
    }

    public void processEditThreadType(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // user must have been authenticated before he can edit thread status
        permission.ensureIsAuthenticated();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int threadID = GenericParamUtil.getParameterInt(request, "thread");
        int threadType = GenericParamUtil.getParameterUnsignedInt(request, "ThreadType", ThreadBean.THREAD_TYPE_DEFAULT);

        ThreadBean threadBean = null;
        try {
            threadBean = DAOFactory.getThreadDAO().getThread(threadID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        int forumID = threadBean.getForumID();

        ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();

        if (threadType > ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT /* 3 */) {
            throw new BadInputException("Not support this thread type");
        }

        if ((threadType == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT) ||
            (threadBean.getThreadType() == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT)) {
            permission.ensureCanAdminSystem();
        } else {
            permission.ensureCanModerateThread(forumID);
        }

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        DAOFactory.getThreadDAO().updateThreadType(threadID, threadType);
        //@todo: should update other info ???

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

        request.setAttribute("ThreadID", String.valueOf(threadID));
        request.setAttribute("ForumID", String.valueOf(forumID));
    }

    public void prepareList_limit(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AssertionException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int forumID = GenericParamUtil.getParameterInt(request, "forum");

        // make sure there is the forum
        // will throw an BadInputException if there is not this forum
        ForumBean forumBean = ForumCache.getInstance().getBean(forumID);

        forumBean.ensureNotDisabledForum();

        // make sure user can read post in this forum
        permission.ensureCanReadPost(forumID);

        // for sort and order stuff
        String sort  = GenericParamUtil.getParameter(request, "sort");
        String order = GenericParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "ThreadLastPostDate";
        if (order.length()== 0) order = "DESC";

        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = GenericParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalThreads = ThreadCache.getInstance().getNumberOfEnableThreads_inForum(forumID);
        int totalNormalThreads = ThreadCache.getInstance().getNumberOfNormalEnableThreads_inForum(forumID);
        if (offset > totalNormalThreads) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection threadBeans = ThreadCache.getInstance().getNormalEnableThreads_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);

        // the correct value is the enable posts - disable threads, so we could get directly from the ForumBean
        //int totalPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -