|
What this is
Other links
The source code
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberCompanyWebHandler.java,v 1.7 2005/01/18 11:52:12 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.7 $
* $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.MVNForumResourceBundle;
import com.mvnforum.auth.*;
import com.mvnforum.db.CompanyBean;
import com.mvnforum.db.DAOFactory;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
class MemberCompanyWebHandler {
private static Log log = LogFactory.getLog(MemberCompanyWebHandler.class);
private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
MemberCompanyWebHandler() {
}
void processAdd(HttpServletRequest request)
throws IOException, BadInputException, CreateException, DatabaseException,
DuplicateKeyException, ObjectNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Timestamp expireDate = new Timestamp(now.getTime() + DateUtil.DAY * 90);
int companyID = ParamUtil.getParameterInt(request, "companyid");
int isActive = 0;//ParamUtil.getParameterInt(request, "IsActive");
int relationType = 0;//ParamUtil.getParameterInt(request, "RelationType");
int relationOption = 0;//ParamUtil.getParameterInt(request, "RelationOption");
int relationStatus = 0;//ParamUtil.getParameterInt(request, "RelationStatus");
String memberNames = ParamUtil.getParameterSafe(request, "MemberNames", true);
Locale locale = I18nUtil.getLocaleInRequest(request);
//log.debug("member names = " + memberNames);
StringReader stringReader = new StringReader(memberNames);
BufferedReader reader = new BufferedReader(stringReader);
CompanyBean companyBean = null;
try {
companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
throw new ObjectNotFoundException(localizedMessage);
}
String memberName = null;
while ((memberName = reader.readLine()) != null) {
//log.debug("name = " + memberName + " length = " + memberName.length());
memberName = memberName.trim();
if (memberName.length() > 0) {
try {
// Assign member to company
int memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
DAOFactory.getMemberCompanyDAO().create(memberID, memberName, companyID,
now/*creationDate*/, expireDate, isActive,
relationType, relationOption, relationStatus);
// and also assign that member to group of the company
int groupID = companyBean.getGroupID();
int privilege = 0;
DAOFactory.getMemberGroupDAO().create(groupID, memberName, privilege, now/*creationDate*/, now/*modifiedDate*/);
} catch (DuplicateKeyException ex) {
// already existed, just ignore
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ImportException.member_belong_to_other_company", new Object[] {memberName});
throw new DuplicateKeyException(localizedMessage);
//throw new DuplicateKeyException("Member '" + memberName + "' already belong to other company.");
} catch (ObjectNotFoundException ex) {
// member not found, just ignore
} catch (ForeignKeyNotFoundException ex) {
// member not found, just ignore
}
}// if memberName is not empty
}//while
}
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 companyID = ParamUtil.getParameterInt(request, "companyid");
int memberID= ParamUtil.getParameterInt(request, "memberid");
CompanyBean companyBean = null;
try {
companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
} catch (ObjectNotFoundException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
throw new ObjectNotFoundException(localizedMessage);
}
// Delete member from the company
DAOFactory.getMemberCompanyDAO().delete(memberID, companyID);
// And also delete that member from the group of the company
int groupID = companyBean.getGroupID();
DAOFactory.getMemberGroupDAO().delete(groupID, memberID);
}
void prepareList_inCompany_limit(HttpServletRequest request)
throws DatabaseException, BadInputException, ObjectNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
int companyID = ParamUtil.getParameterInt(request, "companyid");
CompanyBean companyBean = null;
try {
companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
} catch (ObjectNotFoundException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.companyid_not_exists", new Object[] {new Integer(companyID)});
throw new ObjectNotFoundException(localizedMessage);
}
Collection memberCompanyBeans = DAOFactory.getMemberCompanyDAO().getBeans_inCompany_limit(companyID, 0, 10000);//@todo: FIX ME : hard code
request.setAttribute("CompanyBean", companyBean);
request.setAttribute("MemberCompanyBeans", memberCompanyBeans);
}
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.