📄 savegroupaction.java
字号:
/* * CyberTester - J2EE Web application for creating, delivering and managing tests/exams/surveys. * Copyright (C) 2004 CyberDemia Research and Services Pty Ltd * * 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 * (at your option) any later version. * * 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 (see the file COPYING); if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * See the COPYING file located in the top-level-directory of * the archive of this program for complete text of license. */package com.cyberdemia.cybertester.admin.user;import java.util.ArrayList;import java.util.Enumeration;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionError;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.cyberdemia.cybertester.Constants;import com.cyberdemia.cybertester.admin.AdminConstants;import com.cyberdemia.cybertester.CyberTesterUtils;import com.cyberdemia.cybertester.admin.AbstractAdminAction;import com.cyberdemia.user.GroupData;import com.cyberdemia.user.GroupManager;import com.cyberdemia.user.GroupManagerHome;/** * SaveGroupAction is a Struts action to save the values received from * the group editor to either a new or existing group. * * @author Alexander Yap * @version $Revision: 1.2 $ at $Date: 2004/05/29 17:30:32 $ by $Author: alexycyap $ */public class SaveGroupAction extends AbstractAdminAction{ protected ActionForward doPerform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception { // Was this transaction cancelled? if (isCancelled(request)) { return mapping.findForward(Constants.SUCCESS); } Logger logger = CyberTesterUtils.getLogger(); ActionErrors errors = new ActionErrors(); // If submitted out of order, go to error page immediately. if (!isTokenValid(request)) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.transaction.token")); } resetToken(request); if (errors.isEmpty()) { GroupForm groupForm = (GroupForm)form; try { GroupManagerHome gMgrHome = CyberTesterUtils.getGroupManagerHome(); GroupManager groupMgr = (GroupManager)gMgrHome.create(); if (groupForm.isNew()) { String hierId = (String)session.getAttribute(AdminConstants.SELECTED_HIERARCHY_ID_KEY); if (hierId==null) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.hierarchyNode.unselected")); } else { GroupData data = getGroupDataFromForm(groupForm, hierId); logger.log(Level.FINE, "Creating new group, name=\""+groupForm.getName()+"\"."); groupMgr.addGroup(data, null); } } else { logger.log(Level.FINE, "Updating group "+groupForm.getName()); groupMgr.setGroup(groupForm.getId(), groupForm.getName()); List userToRemoveIdList = new ArrayList(); Enumeration pEnum = request.getParameterNames(); while (pEnum.hasMoreElements()) { String pName = (String)pEnum.nextElement(); if (pName.startsWith(REMOVE_PARAM_PREFIX) ) { if ( "true".equals(request.getParameter(pName)) ) { Integer userId = CyberTesterUtils.convertToInteger(pName.substring(REMOVE_PARAM_PREFIX.length())); if (userId!=null) { userToRemoveIdList.add(userId); } } } } if (!userToRemoveIdList.isEmpty()) { groupMgr.removeUsersFromGroup(groupForm.getId(), userToRemoveIdList); } } } catch (Exception ex) { logger.log( Level.SEVERE, "Error saving Group", ex); throw ex; } } if (!errors.isEmpty()) { saveErrors(request, errors); return mapping.findForward(Constants.ERROR); } return mapping.findForward(Constants.SUCCESS); } private static GroupData getGroupDataFromForm(GroupForm groupForm, String hierId) { GroupData data = new GroupData(groupForm.getId(), hierId, groupForm.getName(), System.currentTimeMillis()); return data; } private static final String REMOVE_PARAM_PREFIX = "remove_"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -