alvinalexander.com | 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/MemberGroupWebHandler.java,v 1.12 2005/01/18 11:52:12 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.12 $
 * $Date: 2005/01/18 11:52:12 $
 *
 * ====================================================================
 *
 * 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
 */
package com.mvnforum.admin;

import java.io.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.db.DAOFactory;
import com.mvnforum.db.GroupsBean;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class MemberGroupWebHandler {

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

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    MemberGroupWebHandler() {
    }

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

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();
        Timestamp expireDate = new Timestamp(now.getTime() + DateUtil.DAY * 90);// for company

        int groupID   = ParamUtil.getParameterInt(request, "group");

        // check if the group is one of the reserved groups
        if (groupID == MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
            // actually it could be ok to list member in this group
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_member_to_virtual_group_registered_members");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot add member to virtual group Registered Members.");
        } else if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_member_to_virtual_reserved_group");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot add member to a reserved (virtual) group.");
        }

        String memberNames = ParamUtil.getParameterSafe(request, "MemberNames", true);
        int privilege      = 0;//ParamUtil.getParameterInt(request, "Privilege");

        // Begin for Company
        int isActive       = 0;
        int relationType   = 0;
        int relationOption = 0;
        int relationStatus = 0;
        int companyID      = 0;
        GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(groupID);
        String groupName = groupsBean.getGroupName();
        if (groupName.toLowerCase().startsWith(MVNForumGlobal.COMPANY_GROUP_FREFIX.toLowerCase())) {
            try {
                companyID = DAOFactory.getCompanyDAO().getCompanyIDFromGroupID(groupID);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_groupid", new Object[] {new Integer(groupID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
        }
        // End for Company

        //log.debug("member names = " + memberNames);
        StringReader stringReader = new StringReader(memberNames);
        BufferedReader reader = new BufferedReader(stringReader);

        String memberName = null;
        while ((memberName = reader.readLine()) != null) {
            //log.debug("name = " + memberName + " length = " + memberName.length());
            memberName = memberName.trim();
            if (memberName.length() > 0) {
                try {
                    DAOFactory.getMemberGroupDAO().create(groupID, memberName, privilege,
                                                now/*creationDate*/, now/*modifiedDate*/);

                    // Begin for Company
                    if (companyID > 0) {
                        // if memberName does not exist, then the ForeignKeyNotFoundException already thrown above
                        int memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
                        DAOFactory.getMemberCompanyDAO().create(memberID, memberName, companyID,
                                              now/*creationDate*/, expireDate, isActive,
                                              relationType, relationOption, relationStatus);
                    }
                    // End for Company
                } catch (DuplicateKeyException ex) {
                    // already existed, just ignore
                } catch (ForeignKeyNotFoundException ex) {
                    // member not found, just ignore
                }
            }// if memberName is not empty
        }//while
    }

    /*
     * @todo: check if we should reset the GroupOwnerID from Groups table ???
     */
    void processDelete(HttpServletRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

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

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

        // Begin for Company
        int companyID      = 0;
        GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(groupID);
        String groupName = groupsBean.getGroupName();
        if (groupName.toLowerCase().startsWith(MVNForumGlobal.COMPANY_GROUP_FREFIX.toLowerCase())) {
            try {
                companyID = DAOFactory.getCompanyDAO().getCompanyIDFromGroupID(groupID);
            } catch (ObjectNotFoundException e) {
                Locale locale = I18nUtil.getLocaleInRequest(request);
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.company_not_exists.with_groupid", new Object[] {new Integer(groupID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
        }
        // End for Company

        DAOFactory.getMemberGroupDAO().delete(groupID, memberID);

        // Delete member from the company
        if (companyID > 0) {
            DAOFactory.getMemberCompanyDAO().delete(memberID, companyID);
        }

        //Netmama's function: We must delete all Member belongs to this memberID also in MemberTutor
        if (MVNForumConfig.getEnableCompany()) {
            //@todo: what is it here ???
            DAOFactory.getMemberTutorDAO().deleteMembers_inTutor(memberID);
        }
    }

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

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        int groupID = ParamUtil.getParameterInt(request, "group");

        // check if the group is one of the reserved groups
        if (groupID == MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
            // actually it could be ok to list member in this group
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_list_member_in_virtual_group_registered_members");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot list member in virtual group Registered Members.");
        } else if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_list_member_in_reserved_group");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot list member in a reserved (virtual) group.");
        }

        GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(groupID);
        Collection memberGroupBeans = DAOFactory.getMemberGroupDAO().getBeans_inGroup(groupID);

        request.setAttribute("MemberGroupBeans", memberGroupBeans);
        request.setAttribute("GroupsBean", groupsBean);
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.