home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberWebHandler.java,v 1.75 2005/01/26 18:46:51 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.75 $
 * $Date: 2005/01/26 18:46:51 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2005 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 * @author: Igor Manic   imanic@users.sourceforge.net
 */
package com.mvnforum.admin;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.common.*;
import com.mvnforum.db.*;
import com.mvnforum.search.member.MemberIndexer;
import com.mvnforum.search.member.MemberSearchQuery;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.interceptor.InterceptorService;
import net.myvietnam.mvncore.security.Encoder;
import net.myvietnam.mvncore.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class MemberWebHandler {

    private static Log log = LogFactory.getLog(MemberWebHandler.class);

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    MemberWebHandler() {
    }

    void processAdd(HttpServletRequest request)
        throws BadInputException, ObjectNotFoundException, CreateException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException, InterceptorException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        String memberName           = ParamUtil.getParameterSafe(request, "MemberName", true);// check good name
        /** @todo move to a name filter */
        if ( memberName.equalsIgnoreCase(MVNForumConfig.getDefaultGuestName()) ||
             memberName.equalsIgnoreCase("Guest") ||
             memberName.equalsIgnoreCase("Administrator") ||
             memberName.equalsIgnoreCase("Moderator") ) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_register_with_reserved_name", new Object[] {memberName});
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot register member with a reserved name : " + memberName);
        }
        StringUtil.checkGoodName(memberName);
        InterceptorService.getInstance().validateLoginID(memberName);
        if (memberName.length() > MVNForumGlobal.MAX_MEMBER_LOGIN_LENGTH) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.member_name_too_long");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("MemberName cannot be longer than 30 characters.");
        }

        String memberPassword1      = ParamUtil.getParameterPassword(request, "MemberMatkhau", 3, 0);
        String memberPassword2      = ParamUtil.getParameterPassword(request, "MemberMatkhauConfirm", 3, 0);
        if (!memberPassword1.equals(memberPassword2)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.confirmed_password_is_not_match");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Password and confirmed password are not the same, please try again.");
        }
        String memberPassword       = Encoder.getMD5_Base64(memberPassword1);

        String memberEmail          = ParamUtil.getParameterEmail(request, "MemberEmail");
        String memberEmailConfirm   = ParamUtil.getParameterEmail(request, "MemberEmailConfirm");
        if (!memberEmail.equals(memberEmailConfirm)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.confirmed_email_is_not_match");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Email and confirmed email are not the same, please try again.");
        }
        if (memberEmail.length() > MVNForumGlobal.MAX_MEMBER_EMAIL_LENGTH) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.member_email_too_long");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("MemberEmail cannot be longer than 60 characters.");
        }
        String memberFirstEmail     = memberEmail;
        InterceptorService.getInstance().validateMail(memberFirstEmail);

        int memberEmailVisible      = MemberBean.MEMBER_EMAIL_INVISIBLE;
        int memberNameVisible       = MemberBean.MEMBER_NAME_VISIBLE;
        String memberFirstIP        = request.getRemoteAddr();
        String memberLastIP         = memberFirstIP;
        int memberOption            = 0;//@todo review and support it later
        int memberStatus            = 0;// @todo review and support it later, ex: should it be active or not?
        String memberActivateCode   = "";// @todo review and support it later
        int memberMessageOption     = 0;// @todo review and support it later
        int memberPostsPerPage      = 10; //default for all preregistered users
        Date memberBirthday         = new java.sql.Date(now.getTime());
        Timestamp memberCreationDate= now;
        Timestamp memberModifiedDate= now;
        Timestamp memberExpireDate = memberCreationDate;// equal Creation Date mean no expiration
        if (MVNForumConfig.getEnableCompany()) {
            memberExpireDate = DateUtil.getCurrentGMTTimestampExpiredDay(MVNForumConfig.getExpireDateTutor());
        }

        DAOFactory.getMemberDAO().create(memberName, memberPassword, memberFirstEmail,
                                   memberEmail, memberEmailVisible, memberNameVisible,
                                   memberFirstIP, memberLastIP, 0/*memberViewCount*/,
                                   0/*memberPostCount*/, memberCreationDate, memberModifiedDate,memberExpireDate,
                                   now/*memberLastLogon*/, memberOption, memberStatus,
                                   memberActivateCode, ""/*memberTempPassword*/, 0/*memberMessageCount*/,
                                   memberMessageOption, memberPostsPerPage, 0/*memberWarnCount*/,
                                   0/*memberVoteCount*/, 0/*memberVoteTotalStars*/, 0/*memberRewardPoints*/,
                                   ""/*memberTitle*/, 0/*memberTimeZone*/, ""/*memberSignature*/,
                                   ""/*memberAvatar*/, ""/*memberSkin*/, ""/*memberLanguage*/,
                                   " "/*memberFirstname*/, " "/*memberLastname*/, 1/*memberGender*/,
                                   memberBirthday, ""/*memberAddress*/, ""/*memberCity*/,
                                   ""/*memberState*/, ""/*memberCountry*/, ""/*memberPhone*/,
                                   ""/*memberMobile*/, ""/*memberFax*/, ""/*memberCareer*/,
                                   ""/*memberHomepage*/, ""/*memberYahoo*/, ""/*memberAol*/,
                                   ""/*memberIcq*/, ""/*memberMsn*/, ""/*memberCoolLink1*/,
                                   ""/*memberCoolLink2*/);

        // Now, create 4 default folders for each member
        int memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
        int folderStatus = 0;
        int folderOption = 0;
        int folderType = 0;
        DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_INBOX, memberID, 0/*order*/, folderStatus, folderOption, folderType, now, now);
        DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_DRAFT, memberID, 1/*order*/, folderStatus, folderOption, folderType, now, now);
        DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_SENT, memberID, 2/*order*/, folderStatus, folderOption, folderType, now, now);
        DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_TRASH, memberID, 3/*order*/, folderStatus, folderOption, folderType, now, now);

        // Add member to the lucene index
        MemberBean memberBean = null;
        try {
            memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch(ObjectNotFoundException ex) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        MemberIndexer.scheduleAddMemberTask(memberBean);

        // now, if require activation, then we will send mail
        // Note that because after this page succeed,
        // we redirect to usermanagement so not use mvnforum.mail.failed now
        if (MVNForumConfig.getRequireActivation()) {
            String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
            try {
                SendMailUtil.sendActivationCodeEmail(memberID, serverName);
            } catch (Exception ex) {
                log.error("Cannot send mail after registration!", ex);
                request.setAttribute("mvnforum.mail.failed", "Cannot send activation email after registration!");
                //@todo: save the error message to displayed later
            }
        }
    }

    void processUpdateMemberStatus(HttpServletRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException {

        // primary key column(s)
        int memberID    = ParamUtil.getParameterInt(request, "memberid");

        // column(s) to update
        int memberStatus= ParamUtil.getParameterInt(request, "status");

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // now check if status is in the valid range
        if ( memberStatus != MemberBean.MEMBER_STATUS_ENABLE
          && memberStatus != MemberBean.MEMBER_STATUS_DISABLE) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_member_status.unknown_status", new Object[] { new Integer(memberStatus)});
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot update member's status to an unknown status = " + memberStatus);
        }

        // This code make sure Admin always has Enable status
        if (memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) {
            memberStatus = MemberBean.MEMBER_STATUS_ENABLE;
        }
        //IMPORTANT: Guest (id=MEMBER_ID_OF_GUEST) can be disabled by administrator.
        try {
            DAOFactory.getMemberDAO().updateStatus(memberID, // primary key
                                                   memberStatus);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
    }

    void prepareEdit(HttpServletRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AssertionException, AuthenticationException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int memberID = ParamUtil.getParameterInt(request, "memberid");

        MemberBean memberBean = null;
        try {
            // we must use getMember_forEditCurrentMember because we need more information on this member
            memberBean = DAOFactory.getMemberDAO().getMember_forEditCurrentMember(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberBean", memberBean);
    }

    void processEdit(HttpServletRequest request, HttpServletResponse response)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AssertionException, AuthenticationException {

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

        MyUtil.saveVNTyperMode(request, response);

        int memberID  = ParamUtil.getParameterInt(request, "memberid");

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // column(s) to update
        int memberEmailVisible      = ParamUtil.getParameterBoolean(request, "MemberEmailVisible")? MemberBean.MEMBER_EMAIL_VISIBLE : MemberBean.MEMBER_EMAIL_INVISIBLE;
        int memberNameVisible       = ParamUtil.getParameterBoolean(request, "MemberNameVisible") ? MemberBean.MEMBER_NAME_VISIBLE : MemberBean.MEMBER_NAME_INVISIBLE;
        int memberOption            = 0;//ParamUtil.getParameterInt(request, "MemberOption");
        int memberStatus            = ParamUtil.getParameterInt(request, "MemberStatus");
        int memberMessageOption     = 0;//ParamUtil.getParameterInt(request, "MemberMessageOption");
        int memberPostsPerPage      = ParamUtil.getParameterInt(request, "MemberPostsPerPage");
        if (memberPostsPerPage < 5) {
            memberPostsPerPage = 5;
        }
        int memberTimeZone          = ParamUtil.getParameterTimeZone(request, "MemberTimeZone");
        String memberSkin           = ParamUtil.getParameterSafe(request, "MemberSkin", false);
        String memberLanguage       = ParamUtil.getParameterSafe(request, "MemberLanguage", false);
        String memberFirstname      = ParamUtil.getParameterSafe(request, "MemberFirstname", true);
        String memberLastname       = ParamUtil.getParameterSafe(request, "MemberLastname", true);
        int memberGender            = ParamUtil.getParameterBoolean(request, "MemberGender")? 1 : 0;
        Date memberBirthday         = ParamUtil.getParameterDate(request, "MemberBirthday");
        String memberAddress        = ParamUtil.getParameterSafe(request, "MemberAddress", false);
        String memberCity           = ParamUtil.getParameterSafe(request, "MemberCity", false);
        String memberState          = ParamUtil.getParameterSafe(request, "MemberState", false);
        String memberCountry        = ParamUtil.getParameterSafe(request, "MemberCountry", false);
        String memberPhone          = ParamUtil.getParameterSafe(request, "MemberPhone", false);
        String memberMobile         = ParamUtil.getParameterSafe(request, "MemberMobile", false);
        String memberFax            = ParamUtil.getParameterSafe(request, "MemberFax", false);
        String memberCareer         = ParamUtil.getParameterSafe(request, "MemberCareer", false);
        String memberHomepage       = ParamUtil.getParameterUrl(request, "MemberHomepage");
        String memberYahoo          = ParamUtil.getParameterSafe(request, "MemberYahoo", false);
        String memberAol            = ParamUtil.getParameterSafe(request, "MemberAol", false);
        String memberIcq            = ParamUtil.getParameterSafe(request, "MemberIcq", false);
        String memberMsn            = ParamUtil.getParameterSafe(request, "MemberMsn", false);
        String memberCoolLink1      = ParamUtil.getParameterUrl(request, "MemberCoolLink1");
        String memberCoolLink2      = ParamUtil.getParameterUrl(request, "MemberCoolLink2");

        try {
            DAOFactory.getMemberDAO().update(memberID, // primary key
                               memberEmailVisible, memberNameVisible, now/*memberModifiedDate*/,
                               memberOption, memberStatus, memberMessageOption,
                               memberPostsPerPage, memberTimeZone, memberSkin,
                               memberLanguage, memberFirstname, memberLastname,
                               memberGender, memberBirthday, memberAddress,
                               memberCity, memberState, memberCountry,
                               memberPhone, memberMobile, memberFax,
                               memberCareer, memberHomepage, memberYahoo,
                               memberAol, memberIcq, memberMsn,
                               memberCoolLink1, memberCoolLink2);
        } catch(ObjectNotFoundException ex) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        MemberBean justEditedMemberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);

        MemberIndexer.scheduleUpdateMemberTask(justEditedMemberBean);
        //request.setAttribute("MemberBean", justEditedMemberBean);
    }

    void prepareView(HttpServletRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AssertionException, AuthenticationException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        String strMemberID = ParamUtil.getParameter(request, "memberid", false);
        String strMemberName = ParamUtil.getParameter(request, "member", false);
        String strMemberEmail = ParamUtil.getParameter(request, "memberemail", false);

        int memberID;

        if (strMemberID.length() > 0) {
            memberID = ParamUtil.getParameterInt(request, "memberid");
        } else if (strMemberName.length() > 0){
            /**@todo: improve this for better performance(dont use this method,
             * and write 2 new methods)*/
            StringUtil.checkGoodName(strMemberName);// check for better security
            try {
                memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(strMemberName);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object[] {strMemberName});
                throw new ObjectNotFoundException(localizedMessage);
            }
        } else if (strMemberEmail.length() > 0){
            String memberEmail = ParamUtil.getParameterEmail(request, "memberemail");// check for better security
            try {
                memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberEmail(memberEmail);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberemail_not_exists", new Object[] {memberEmail});
                throw new ObjectNotFoundException(localizedMessage);
            }
        } else {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_member_info");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot get the information to view member.");
        }

        // Update statistics to make sure Admin can delete this user
        // with the actual memberPostCount
        try {
            StatisticsUtil.updateMemberStatistics(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        int toMessageCount = 0;
        int fromMessageCount = 0;

        String toDay = ParamUtil.getParameter(request, "toDay", false);
        String toMonth = ParamUtil.getParameter(request, "toMonth", false);
        String toYear = ParamUtil.getParameter(request, "toYear", false);

        String fromDay = ParamUtil.getParameter(request, "fromDay", false);
        String fromMonth = ParamUtil.getParameter(request, "fromMonth", false);
        String fromYear = ParamUtil.getParameter(request, "fromYear", false);

        if ( !toDay.equals("") &&
             !toMonth.equals("") &&
             !toYear.equals("") &&
             !fromDay.equals("") &&
             !fromMonth.equals("") &&
             !fromYear.equals("")) {
            Timestamp from = new Timestamp(ParamUtil.getParameterDate(request, "fromDay", "fromMonth", "fromYear").getTime());
            Timestamp to = new Timestamp(ParamUtil.getParameterDate(request, "toDay", "toMonth", "toYear").getTime());

            toMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inToID_supportTimestamp(memberID, from, to);
            fromMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inFromID_supportTimestamp(memberID, from, to);
        } else {
            toMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inToID(memberID);
            fromMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inFromID(memberID);
        }

        MemberBean memberBean = null;
        try {
            // minhnn: dont use getMember_forViewCurrentMember because it does not support firstIP
            memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        int watchCount = DAOFactory.getWatchDAO().getNumberOfWatches_forMember(memberID);

        request.setAttribute("MemberBean", memberBean);
        request.setAttribute("WatchCount", new Integer(watchCount));

        request.setAttribute("ToMessageCount", new Integer(toMessageCount));
        request.setAttribute("FromMessageCount", new Integer(fromMessageCount));
        request.setAttribute("toDay", toDay);
        request.setAttribute("toMonth", toMonth);
        request.setAttribute("toYear", toYear);
        request.setAttribute("fromDay", fromDay);
        request.setAttribute("fromMonth", fromMonth);
        request.setAttribute("fromYear", toYear);
    }

    void processUpdateMemberTitle(HttpServletRequest request, HttpServletResponse response)
        throws BadInputException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

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

        MyUtil.saveVNTyperMode(request, response);

        // primary key column(s)
        int memberID        = ParamUtil.getParameterInt(request, "MemberID");

        // column(s) to update
        String memberTitle  = ParamUtil.getParameterSafe(request, "MemberTitle", false);
        Locale locale = I18nUtil.getLocaleInRequest(request);
        try {
            DAOFactory.getMemberDAO().updateTitle(memberID, memberTitle);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
    }

    void processResetMemberSignature(HttpServletRequest request)
        throws BadInputException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();
        Locale locale = I18nUtil.getLocaleInRequest(request);
        int memberID = ParamUtil.getParameterInt(request, "memberid");
        try {
            DAOFactory.getMemberDAO().updateSignature(memberID, "");
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberID", new Integer(memberID));
    }

    void processResetMemberAvatar(HttpServletRequest request)
        throws BadInputException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);
        int memberID = ParamUtil.getParameterInt(request, "memberid");
        try {
            DAOFactory.getMemberDAO().updateAvatar(memberID, "");
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberID", new Integer(memberID));
    }

    void processResetMemberActivation(HttpServletRequest request)
        throws BadInputException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);
        int memberID = ParamUtil.getParameterInt(request, "memberid");
        try {
            DAOFactory.getMemberDAO().updateActivateCode(memberID, "");
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberID", new Integer(memberID));
    }

    void processDeleteMember(ServletContext context, HttpServletRequest request)
        throws BadInputException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

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

        int memberID = ParamUtil.getParameterInt(request, "memberid");
        if ((memberID==MVNForumConstant.MEMBER_ID_OF_ADMIN) ||
            (memberID==0) ||
            (memberID==MVNForumConstant.MEMBER_ID_OF_GUEST)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete default Admin and Guest users.");
        }

        boolean deleteSentMessages = ParamUtil.getParameterBoolean(request, "deletesentmessages");

        MemberBean memberBean = null;
        try {
            memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        MemberWebHandler.deleteMember(memberBean, deleteSentMessages, context, locale);

        /*
        if (memberBean.getMemberPostCount() > 0) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_member_has_a_post");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete member that has posted at least one post.");
        }

        // first, we delete uploaded image if there is one
        String memberName = memberBean.getMemberName();
        StringBuffer bufferPicFile = new StringBuffer(256);
        bufferPicFile.append(context.getRealPath(MVNForumGlobal.UPLOADED_AVATAR_DIR));
        bufferPicFile.append(File.separatorChar).append(memberName).append(".jpg");
        String picFile =  bufferPicFile.toString();

        log.debug("Delete avatar = " + picFile);
        File file = new File(picFile);
        file.delete();// we dont need to check the returned value

        //@todo delete table Post/Thread/Attachment if we support delete posted user
        DAOFactory.getWatchDAO().delete_inMember(memberID);
        DAOFactory.getMemberForumDAO().delete_inMember(memberID);
        DAOFactory.getMemberGroupDAO().delete_inMember(memberID);
        DAOFactory.getMemberPermissionDAO().delete_inMember(memberID);
        DAOFactory.getFavoriteThreadDAO().delete_inMember(memberID);

        //Delete message, attachmessage, folder, message statistics stuff
        PrivateMessageUtil.deleteMessageFoldersInDatabase(memberID);
        DAOFactory.getMessageStatisticsDAO().delete_inMember(memberID);
        if (deleteSentMessages) {
            DAOFactory.getMessageDAO().deleteSenderMessages(memberID);
        }

        //Delete company stuff
        if (MVNForumConfig.getEnableCompany()) {
            DAOFactory.getMemberCompanyDAO().delete_inMember(memberID);
            DAOFactory.getMemberTutorDAO().deleteMembers_inTutor(memberID);
            try {
                DAOFactory.getMemberTutorDAO().delete(memberID);
            } catch (ObjectNotFoundException ex) {
                //ignore
            }
        }

        //Delete in primary table
        DAOFactory.getMemberDAO().deleteByPrimaryKey(memberID);
        MemberIndexer.scheduleDeleteMemberTask(memberID);
        */
    }

    /**
     * This method supports sorting base on many criteria
     */
    void prepareShowUserManagement(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // for sort and order stuff
        String sort  = net.myvietnam.mvncore.util.ParamUtil.getParameter(request, "sort");
        String order = net.myvietnam.mvncore.util.ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberCreationDate";
        if (order.length()== 0) order = "DESC";

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

        int totalMembers = DAOFactory.getMemberDAO().getNumberOfMembers();
        if (offset > totalMembers) {
            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 memberBeans = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(offset, postsPerPage, sort, order);
        int enabledMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inMemberStatus(MemberBean.MEMBER_STATUS_ENABLE);
        int disabledMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inMemberStatus(MemberBean.MEMBER_STATUS_DISABLE);
        int activatedMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inActivationStatus(true);
        int nonactivatedMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inActivationStatus(false);

        if ((disabledMembers + enabledMembers) != totalMembers) {
            // please do not localize this
            throw new AssertionException("Assertion: (disabledMembers + enabledMembers) == totalMembers");
        }
        if ((activatedMembers + nonactivatedMembers) != totalMembers) {
            // please do not localize this
            throw new AssertionException("Assertion: (activatedMembers + nonactivatedMembers) == totalMembers");
        }

        request.setAttribute("MemberBeans", memberBeans);
        request.setAttribute("TotalMembers", new Integer(totalMembers));
        request.setAttribute("EnabledMembers", new Integer(enabledMembers));
        request.setAttribute("DisabledMembers", new Integer(disabledMembers));
        request.setAttribute("ActivatedMembers", new Integer(activatedMembers));
        request.setAttribute("NonActivatedMembers", new Integer(nonactivatedMembers));
        request.setAttribute("offset", new Integer(offset));
    }

    public void prepareListUserExpire(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

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

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberExpireDate";
        if (order.length()== 0) order = "ASC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }
        Timestamp expiresoonDate = DateUtil.getCurrentGMTTimestampExpiredDay(MVNForumConfig.getUserTutorExpireSoonDate());

        int totalExpireMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inExpire(expiresoonDate);
        if (offset > totalExpireMembers) {
            //@todo : localize me
            throw new BadInputException("The offset is not allowed to be greater than total members.");
        }

        Collection expireMemberBeans = DAOFactory.getMemberDAO().getMembers_inExpire_limit(expiresoonDate, offset, postsPerPage, sort, order);

        request.setAttribute("TotalMembers", new Integer(totalExpireMembers));
        request.setAttribute("ExpireMemberBeans", expireMemberBeans);
        request.setAttribute("offset", new Integer(offset));
    }

    public void updateMemberExpireProcess(HttpServletRequest request)
        throws DatabaseException, BadInputException, ObjectNotFoundException,
        AssertionException, AuthenticationException {

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

        //int expiredDays = MVNForumConfig.getExpireDateTutor();
        String renew   = ParamUtil.getParameter(request, "renew");
        String disable = ParamUtil.getParameter(request, "disable");
        String enable  = ParamUtil.getParameter(request, "enable");
        int expiredDays = ParamUtil.getParameterUnsignedInt(request, "addtime");

        String[] checkList = request.getParameterValues("selectedmember");
        if (checkList == null) return;

        if (renew.equals("Renew")) {
            //renew creation date and expire date
            long offsetDate = expiredDays * DateUtil.DAY;
            Timestamp now = DateUtil.getCurrentGMTTimestamp();
            for (int i = 0; (checkList != null) && (i < checkList.length); i++) {
                int memberID = Integer.parseInt(checkList[i]);
                log.debug("Renew expiration date for MemberID = " + memberID);
                try {
                    MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
                    Timestamp expireDate = memberBean.getMemberExpireDate();
                    if (expireDate == null) {
                        expireDate = now;
                    }
                    Timestamp memberExpireDate  = new Timestamp(expireDate.getTime() + offsetDate);
                    DAOFactory.getMemberDAO().updateMember_expireDate(memberID, memberExpireDate);
                } catch (ObjectNotFoundException e) {
                    Locale locale = I18nUtil.getLocaleInRequest(request);
                    String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
                    throw new ObjectNotFoundException(localizedMessage);
                }
            }
        } else if (disable.equals("Disable")) {
            for (int i = 0; (checkList != null) && (i < checkList.length); i++) {
                int memberID = Integer.parseInt(checkList[i]);
                log.debug("Disable member with MemberID = " + memberID);
                try {
                    DAOFactory.getMemberDAO().updateStatus(memberID, MemberBean.MEMBER_STATUS_DISABLE);
                } catch (ObjectNotFoundException e) {
                    Locale locale = I18nUtil.getLocaleInRequest(request);
                    String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
                    throw new ObjectNotFoundException(localizedMessage);
                }
            }
        } else if (enable.equals("Enable")) {
            for (int i = 0; (checkList != null) && (i < checkList.length); i++) {
                int memberID = Integer.parseInt(checkList[i]);
                log.debug("Enable member with MemberID = " + memberID);
                try {
                    DAOFactory.getMemberDAO().updateStatus(memberID, MemberBean.MEMBER_STATUS_ENABLE);
                } catch (ObjectNotFoundException e) {
                    Locale locale = I18nUtil.getLocaleInRequest(request);
                    String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
                    throw new ObjectNotFoundException(localizedMessage);
                }
            }
        }
    }

    void processSearch(HttpServletRequest request)
        throws BadInputException, IOException, DatabaseException, ObjectNotFoundException,
        AuthenticationException, AssertionException {

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

        String memberNameKey      = ParamUtil.getParameter(request, "membername", false);
        String memberEmailKey     = ParamUtil.getParameter(request, "email", false);
        String memberLastNameKey  = ParamUtil.getParameter(request, "lastname", false);
        String memberFirstNameKey = ParamUtil.getParameter(request, "firstname", false);
        String memberCountryKey   = ParamUtil.getParameter(request, "country", false);

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int defaultRows = onlineUser.getPostsPerPage();

        int offset = ParamUtil.getParameterUnsignedInt(request, "offset", 0);
        int rows   = ParamUtil.getParameterUnsignedInt(request, "rows", defaultRows);
        if (rows == 0) {
            rows = defaultRows;// fix NullPointerException when rows = 0
        }

        // offset should be even when divide with rowsToReturn
        offset = (offset / rows) * rows;

        MemberSearchQuery query = new MemberSearchQuery();
        boolean isNullKey = true;
        if (memberNameKey.length() > 0) {
            query.setMemberNameKey(memberNameKey);
            isNullKey = false;
        }
        if (memberEmailKey.length() > 0) {
            query.setMemberEmailKey(memberEmailKey);
            isNullKey = false;
        }
        if (memberLastNameKey.length() > 0) {
            query.setMemberLastNameKey(memberLastNameKey);
            isNullKey = false;
        }
        if (memberFirstNameKey.length() > 0){
            query.setMemberFirstNameKey(memberFirstNameKey);
            isNullKey = false;
        }
        if (memberCountryKey.length() > 0) {
            query.setCountry(memberCountryKey);
            isNullKey = false;
        }
        if (isNullKey) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_search.key_is_null");
            throw new BadInputException(localizedMessage);
        }

        int searchDate        = ParamUtil.getParameterUnsignedInt(request, "date", MemberSearchQuery.SEARCH_ANY_DATE);
        int searchBeforeAfter = ParamUtil.getParameterInt(request, "beforeafter", MemberSearchQuery.SEARCH_NEWER);

        if ((searchDate != MemberSearchQuery.SEARCH_ANY_DATE) && (searchDate < 365 * 10)) { // 10 years
            long deltaTime = DateUtil.DAY * searchDate;

            Timestamp now = DateUtil.getCurrentGMTTimestamp();
            Timestamp from = null;
            Timestamp to = null;

            long currentTime = now.getTime();

            if (searchBeforeAfter == MemberSearchQuery.SEARCH_NEWER) {
                from = new Timestamp(currentTime - deltaTime);
            } else {// older
                to = new Timestamp(currentTime - deltaTime);
            }

            query.setFromDate(from);
            query.setToDate(to);
        }


        query.searchDocuments(offset, rows);
        int hitCount = query.getHitCount();
        Collection result = query.getMemberResult();

        if (offset > hitCount) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
        }

        request.setAttribute("offset", new Integer(offset));
        request.setAttribute("rows", new Integer(rows));
        request.setAttribute("TotalMembers", new Integer(hitCount));
        request.setAttribute("MemberBeans", result);
        request.setAttribute("MemberName", memberNameKey);
        request.setAttribute("MemberEmail", memberEmailKey); //strCompanyAddress);
        request.setAttribute("DateOption", new Integer(searchDate)); //strCompanyCreationDate);
        request.setAttribute("BeforeAfterOption", new Integer(searchBeforeAfter)); //strCompanyModifiedDate);
    }

    public void preparePermissionSummary(HttpServletRequest request )
        throws DatabaseException, ObjectNotFoundException, AuthenticationException, AssertionException {

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

        Collection authorizedMembers = DAOFactory.getMemberDAO().getAuthorizedMembers();
        Collection forumsAuthorizedMembers = DAOFactory.getMemberDAO().getForumsAuthorizedMembers();

        Collection distinctAuthorizedGroups = DAOFactory.getGroupPermissionDAO().getDistinctGroups();
        Collection authorizedGroups = new ArrayList(distinctAuthorizedGroups.size());
        for (Iterator iter = distinctAuthorizedGroups.iterator(); iter.hasNext(); ) {
            GroupPermissionBean item = (GroupPermissionBean) iter.next();
            GroupsBean groupBean = DAOFactory.getGroupsDAO().getGroup(item.getGroupID());
            authorizedGroups.add(groupBean);
        }

        Collection distinctForumAuthorizedGroups = DAOFactory.getGroupForumDAO().getDistinctGroups();
        Collection forumAuthorizedGroups = new ArrayList(distinctForumAuthorizedGroups.size());
        for (Iterator iter = distinctForumAuthorizedGroups.iterator(); iter.hasNext(); ) {
            GroupForumBean item = (GroupForumBean) iter.next();
            GroupsBean groupBean = DAOFactory.getGroupsDAO().getGroup(item.getGroupID());
            forumAuthorizedGroups.add(groupBean);
        }

        request.setAttribute("AuthorizedMembers", authorizedMembers);
        request.setAttribute("ForumsAuthorizedMembers", forumsAuthorizedMembers);
        request.setAttribute("AuthorizedGroups", authorizedGroups);
        request.setAttribute("ForumAuthorizedGroups", forumAuthorizedGroups);
    }

    public void prepareViewPermission(HttpServletRequest request )
        throws AuthenticationException, BadInputException, DatabaseException, AssertionException, ObjectNotFoundException {

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

        int memberID = ParamUtil.getParameterInt(request, "memberid");

        MemberBean member = null;
        try {
            member = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch (ObjectNotFoundException e) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        MVNForumPermission thisPermission = MVNForumPermissionFactory.getAuthenticatedPermission(memberID);
        Collection groups = DAOFactory.getGroupsDAO().getMyGroups(memberID);

        request.setAttribute("MemberBean", member);
        request.setAttribute("MemberGroups", groups);
        request.setAttribute("Permissions", thisPermission);
    }

    public void prepareChangePassword(HttpServletRequest request )
        throws DatabaseException, AuthenticationException, AssertionException,
        ObjectNotFoundException, BadInputException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);
        if ( ! MVNForumConfig.getEnableAdminCanChangePassword()) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.admin_can_change_password_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Admin Cannot change the user password. This feature is disabled by administrator");
        }
        int memberID = ParamUtil.getParameterInt(request, "memberid");

        if ( memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN ) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_change_root_password");
            throw new AssertionException(localizedMessage);
        }
        MemberBean memberBean = null;
        try {
            memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberBean", memberBean);
    }

    public void processChangePassword(HttpServletRequest request )
        throws DatabaseException, AuthenticationException, AssertionException,
        ObjectNotFoundException, BadInputException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        if ( ! MVNForumConfig.getEnableAdminCanChangePassword()) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.admin_can_change_password_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Admin Cannot change the user password. This feature is disabled by administrator");
        }

        int memberID = ParamUtil.getParameterInt(request, "memberid");

        if ( memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN ) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_change_root_password");
            throw new AssertionException(localizedMessage);
        }

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

        String password      = ParamUtil.getParameterPassword(request, "MemberMatkhau", 3, 0);
        String confirmword      = ParamUtil.getParameterPassword(request, "MemberMatkhauConfirm", 3, 0);
        if (!password.equals(confirmword)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.confirmed_password_is_not_match");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Password and confirmed password are not the same, please try again.");
        }
        password = Encoder.getMD5_Base64(password);

        try {
            DAOFactory.getMemberDAO().updatePassword(memberID, password);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("MemberID", new Integer(memberID));
    }

    void prepareDeleteNonActivatedNoPostMembers(HttpServletRequest request)
        throws DatabaseException, AuthenticationException,
        AssertionException, BadInputException {

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

        int days = ParamUtil.getParameterUnsignedInt(request, "days");

        long delta = days * DateUtil.DAY;
        Timestamp before = new Timestamp(DateUtil.getCurrentGMTTimestamp().getTime() - delta);

        Collection members = DAOFactory.getMemberDAO().getNonActivatedNoPostMembers(before);

        request.setAttribute("DeleteMembers", members);
    }

    void processDeleteNonActivatedNoPostMembers(ServletContext context, HttpServletRequest request)
        throws DatabaseException, ObjectNotFoundException, BadInputException,
        AuthenticationException, AssertionException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

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

        int days = ParamUtil.getParameterUnsignedInt(request, "days");

        boolean deleteMessages = ParamUtil.getParameterBoolean(request, "deletesentmessages");

        long delta = days * DateUtil.DAY;
        Timestamp before = new Timestamp(DateUtil.getCurrentGMTTimestamp().getTime() - delta);

        Collection members = DAOFactory.getMemberDAO().getNonActivatedNoPostMembers(before);

        int deletedMembersCount = 0;
        for (Iterator iterator = members.iterator(); iterator.hasNext(); ) {
            MemberBean member = (MemberBean) iterator.next();
            if ((member.getMemberID() != 0) && (member.getMemberID() != 1)) {
                MemberWebHandler.deleteMember(member, deleteMessages, context, locale);
                deletedMembersCount++;
            }
        }
        log.debug("Total: Deleted " + deletedMembersCount + " members");

        request.setAttribute("DeletedMembersCount", new Integer(deletedMembersCount));
    }

    public static void deleteMember(MemberBean memberBean, boolean deleteSentMessages, ServletContext context, Locale locale)
        throws DatabaseException, BadInputException, ObjectNotFoundException, AssertionException {

        int memberID = memberBean.getMemberID();
        if ((memberID==MVNForumConstant.MEMBER_ID_OF_ADMIN) ||
            (memberID==0) ||
            (memberID==MVNForumConstant.MEMBER_ID_OF_GUEST)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete default Admin and Guest users.");
        }

        // check in the MemberBean
        if (memberBean.getMemberPostCount() > 0) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_member_has_a_post");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete member that has posted at least one post.");
        }

        // Real checking in table post
        if (DAOFactory.getPostDAO().getNumberOfPosts_inMember(memberID) > 0) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_member_has_a_post");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete member that has posted at least one post.");
        }

        // first, we delete uploaded image if there is one
        String memberName = memberBean.getMemberName();

        log.info("About to delete member with login = " + memberName + " and id = " + memberID + " with option deleteSentMessages = " + deleteSentMessages);

        StringBuffer bufferPicFile = new StringBuffer(256);
        bufferPicFile.append(context.getRealPath(MVNForumGlobal.UPLOADED_AVATAR_DIR));
        bufferPicFile.append(File.separatorChar).append(memberName).append(".jpg");
        String picFile =  bufferPicFile.toString();

        log.debug("Delete avatar = " + picFile);
        File file = new File(picFile);
        file.delete();// we dont need to check the returned value

        //@todo delete table Post/Thread/Attachment if we support delete posted user
        DAOFactory.getWatchDAO().delete_inMember(memberID);
        DAOFactory.getMemberForumDAO().delete_inMember(memberID);
        DAOFactory.getMemberGroupDAO().delete_inMember(memberID);
        DAOFactory.getMemberPermissionDAO().delete_inMember(memberID);
        DAOFactory.getFavoriteThreadDAO().delete_inMember(memberID);

        //Delete message, attachmessage, folder, message statistics stuff
        PrivateMessageUtil.deleteMessageFoldersInDatabase(memberID);
        DAOFactory.getMessageStatisticsDAO().delete_inMember(memberID);
        if (deleteSentMessages) {
            DAOFactory.getMessageDAO().deleteSenderMessages(memberID);
        }

        //Delete company stuff
        if (MVNForumConfig.getEnableCompany()) {
            DAOFactory.getMemberCompanyDAO().delete_inMember(memberID);
            DAOFactory.getMemberTutorDAO().deleteMembers_inTutor(memberID);
            try {
                DAOFactory.getMemberTutorDAO().delete(memberID);
            } catch (ObjectNotFoundException ex) {
                //ignore
            }
        }

        //Delete in primary table
        DAOFactory.getMemberDAO().deleteByPrimaryKey(memberID);
        MemberIndexer.scheduleDeleteMemberTask(memberID);
    }
}


my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.