?? groupswebhandler.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/GroupsWebHandler.java,v 1.4 2004/05/19 19:11:57 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.4 $
* $Date: 2004/05/19 19:11:57 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 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.sql.Timestamp;
import java.util.Collection;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import com.mvnforum.MVNForumConstant;
import com.mvnforum.MyUtil;
import com.mvnforum.auth.*;
import com.mvnforum.db.DAOFactory;
import com.mvnforum.db.GroupsBean;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.ParamUtil;
class GroupsWebHandler {
private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
GroupsWebHandler() {
}
void processAdd(HttpServletRequest request)
throws ObjectNotFoundException, BadInputException, CreateException, DatabaseException, DuplicateKeyException,
ForeignKeyNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
String groupName = ParamUtil.getParameterSafe(request, "GroupName", true);
String groupDesc = ParamUtil.getParameterSafe(request, "GroupDesc", false);
int groupOption = 0;//ParamUtil.getParameterInt(request, "GroupOption");
DAOFactory.getGroupsDAO().create(""/*groupOwnerName*/, groupName, groupDesc,
groupOption, now/*groupCreationDate*/, now/*groupModifiedDate*/);
//now add owner to group if there is owner for this group
String groupOwnerName = ParamUtil.getParameterSafe(request, "GroupOwnerName", false);
if (groupOwnerName.length() > 0) {
int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName);
int privilege = 0;//@todo review and support it later, should be GroupAdmin
try {
DAOFactory.getGroupsDAO().updateOwner(groupID, // primary key
groupOwnerName, now/*groupModifiedDate*/);
DAOFactory.getMemberGroupDAO().create(groupID, groupOwnerName, privilege, now, now);
} catch (ForeignKeyNotFoundException ex) {
// what should do when member not found ???
// now, I just do nothing
} catch (DuplicateKeyException ex) {
// do nothing, it is not an error (member already in this group)
}
}
}
void prepareDelete(HttpServletRequest request)
throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
// primary key column(s)
int groupID = ParamUtil.getParameterInt(request, "group");
//make sure reserved groups are never deleted (like "Registered Members" group)
if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
throw new BadInputException("Cannot delete group with id <= "+
Integer.toString(MVNForumConstant.LAST_RESERVED_GROUP_ID));
}
GroupsBean bean = DAOFactory.getGroupsDAO().getBean(groupID);
request.setAttribute("GroupsBean", bean);
}
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");
//make sure reserved groups are never deleted (like "Registered Members" group)
if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
throw new BadInputException("Cannot delete group with id <= "+
Integer.toString(MVNForumConstant.LAST_RESERVED_GROUP_ID));
}
// now check the password
MyUtil.ensureCorrectCurrentPassword(request);
DAOFactory.getGroupForumDAO().delete_inGroup(groupID);
DAOFactory.getGroupPermissionDAO().delete_inGroup(groupID);
DAOFactory.getMemberGroupDAO().delete_inGroup(groupID);
DAOFactory.getGroupsDAO().delete(groupID);
}
void processUpdate(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException, DuplicateKeyException,
AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
// primary key column(s)
int groupID = ParamUtil.getParameterInt(request, "group");
// column(s) to update
String groupName = ParamUtil.getParameterSafe(request, "GroupName", true);
String groupDesc = ParamUtil.getParameterSafe(request, "GroupDesc", true);
DAOFactory.getGroupsDAO().update(groupID, // primary key
groupName, groupDesc, now/*groupModifiedDate*/);
}
void processUpdateGroupOwner(HttpServletRequest request)
throws ObjectNotFoundException, BadInputException, DatabaseException, ForeignKeyNotFoundException,
CreateException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
Timestamp now = DateUtil.getCurrentGMTTimestamp();
// primary key column(s)
int groupID = ParamUtil.getParameterInt(request, "group");
//make sure group owners for reserved groups can't be changed
if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
throw new AssertionException("Cannot update group owner for reserved (virtual) groups.");
}
//@todo: Igor: Why don't we allow changing of GroupOwner for reserved groups? I think we have no reason to disallow that.
// column(s) to update
String groupOwnerName = ParamUtil.getParameterSafe(request, "GroupOwnerName", false);
DAOFactory.getGroupsDAO().updateOwner(groupID, // primary key
groupOwnerName, now/*groupModifiedDate*/);
/*
* now add owner to group if there is owner for this group
* if member already in the group, we dont throw Exception (DuplicateKeyException)
*/
if (groupOwnerName.length() > 0) {
int privilege = 0;//@todo review and support it later
try {
DAOFactory.getMemberGroupDAO().create(groupID, groupOwnerName, privilege, now, now);
} catch (DuplicateKeyException ex) {
// do nothing, it is not an error (member already in this group)
}
}
}
void prepareView(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");
GroupsBean bean = DAOFactory.getGroupsDAO().getBean(groupID);
request.setAttribute("GroupsBean", bean);
}
void prepareList(HttpServletRequest request)
throws DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAdminSystem();
Collection beans = DAOFactory.getGroupsDAO().getBeans();
// now count the number of members in each group
Iterator iterator = beans.iterator();
while(iterator.hasNext()) {
GroupsBean row = (GroupsBean)iterator.next();
int groupID = row.getGroupID();
if (groupID == MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
//"Registered Members" group. Exclude virtual guest from count.
row.setGroupMemberCount(DAOFactory.getMemberDAO().getNumberOfMembers()-1);
} else if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
//other reserved groups
row.setGroupMemberCount(0);
} else {
row.setGroupMemberCount(DAOFactory.getMemberGroupDAO().getNumberOfBeans_inGroup(groupID));
}
}
request.setAttribute("GroupsBeans", beans);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -