⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adminugset.java

📁 java论坛
💻 JAVA
字号:
package com.laoer.bbscs.web.action;

import java.util.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;
import org.apache.struts.util.*;
import org.apache.commons.lang.*;
import com.laoer.bbscs.comm.*;
import com.laoer.bbscs.service.*;
import com.laoer.bbscs.web.form.*;
import com.laoer.bbscs.bean.UserGroup;
import com.laoer.bbscs.bean.Role;
import com.laoer.bbscs.exception.*;

public class AdminUgSet
    extends AdminBaseAction {

  private UserGroupService userGroupService;

  private RoleService roleService;

  private AjaxMessagesXML ajaxMessagesXML;

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                               HttpServletResponse response) {
    AdminUgSetForm adminUgSetForm = (AdminUgSetForm) form;

    MessageResources mr = this.getResources(request);
    Locale locale = this.getLocale(request);

    if (adminUgSetForm.getAction().equalsIgnoreCase("new")) {
      adminUgSetForm.setAction("add");
      this.setRoleList(request);
      request.setAttribute("roleValues", new ArrayList().toArray());
      return mapping.findForward("ugSet");
    }

    if (adminUgSetForm.getAction().equalsIgnoreCase("add")) {
      if (StringUtils.isBlank(adminUgSetForm.getGroupName())) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_NULL,
                                             mr.getMessage(locale, "error.nullerror"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward("ajaxjsp");
      }

      List roleIDs = new ArrayList();
      if (adminUgSetForm.getRoleIDs() == null) {
        roleIDs.add(new Integer(0));
      }
      else {
        for (int i = 0; i < adminUgSetForm.getRoleIDs().length; i++) {
          roleIDs.add(new Integer(adminUgSetForm.getRoleIDs()[i]));
        }
      }
      List roles = this.getRoleService().findRolesInIDs(roleIDs);
      UserGroup ug = new UserGroup();
      ug.setGroupDesc(adminUgSetForm.getGroupDesc());
      ug.setGroupName(adminUgSetForm.getGroupName());
      for (int i = 0; i < roles.size(); i++) {
        Role role = (Role) roles.get(i);
        ug.getRoles().add(role);
      }
      try {
        this.getUserGroupService().saveUserGroup(ug);
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                             mr.getMessage(locale, "admin.ug.add.ok"));
      }
      catch (BbscsException ex) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_UG_ADDFAILED,
                                             mr.getMessage(locale, "error.admin.ug.add"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");
    }

    if (adminUgSetForm.getAction().equalsIgnoreCase("edit")) {
      adminUgSetForm.setAction("editdo");
      UserGroup ug = this.userGroupService.findUserGroupByID(adminUgSetForm.getId());
      adminUgSetForm.setGroupDesc(ug.getGroupDesc());
      adminUgSetForm.setGroupName(ug.getGroupName());
      List roleValues = new ArrayList();

      Iterator it = ug.getRoles().iterator();
      while (it.hasNext()) {
        Role role = (Role) it.next();
        roleValues.add(role.getId());
      }
      this.setRoleList(request);
      request.setAttribute("roleValues", roleValues.toArray());
      return mapping.findForward("ugSet");
    }

    if (adminUgSetForm.getAction().equalsIgnoreCase("editdo")) {
      if (StringUtils.isBlank(adminUgSetForm.getGroupName())) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_NULL,
                                             mr.getMessage(locale, "error.nullerror"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward("ajaxjsp");
      }

      UserGroup ug = this.userGroupService.findUserGroupByID(adminUgSetForm.getId());
      ug.setGroupDesc(adminUgSetForm.getGroupDesc());
      ug.setGroupName(adminUgSetForm.getGroupName());

      ug.getRoles().clear();
      List roleIDs = new ArrayList();
      if (adminUgSetForm.getRoleIDs() == null) {
        roleIDs.add(new Integer(0));
      }
      else {
        for (int i = 0; i < adminUgSetForm.getRoleIDs().length; i++) {
          roleIDs.add(new Integer(adminUgSetForm.getRoleIDs()[i]));
        }
      }
      List roles = this.getRoleService().findRolesInIDs(roleIDs);
      for (int i = 0; i < roles.size(); i++) {
        Role role = (Role) roles.get(i);
        ug.getRoles().add(role);
      }
      try {
        //this.getUserGroupService().saveUserGroup(ug);
        this.getUserGroupService().updateUserGroup(ug);//更新UserGroup
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                             mr.getMessage(locale, "admin.ug.edit.ok"));
      }
      catch (BbscsException ex) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_UG_EDITFAILED,
                                             mr.getMessage(locale, "error.admin.ug.edit"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");

    }

    if (adminUgSetForm.getAction().equalsIgnoreCase("del")) {
      UserGroup ug = this.userGroupService.findUserGroupByID(adminUgSetForm.getId());
      if (ug.getTypeID() == 0) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_UG_CANNOTDEL,
                                             mr.getMessage(locale, "error.admin.role.cannotdel"));
      }
      try {
        this.getUserGroupService().removeUserGroup(ug);
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                             mr.getMessage(locale, "admin.ug.del.ok"));
      }
      catch (BbscsException ex1) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_ROLE_EDITFAILED,
                                             mr.getMessage(locale, "error.admin.ug.del"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");
    }

    return mapping.getInputForward();
  }

  protected void setRoleList(HttpServletRequest request) {
    List roleList = this.getRoleService().findRolesAll();
    request.setAttribute("roleList", roleList);
  }

  public AjaxMessagesXML getAjaxMessagesXML() {
    return ajaxMessagesXML;
  }

  public RoleService getRoleService() {
    return roleService;
  }

  public UserGroupService getUserGroupService() {
    return userGroupService;
  }

  public void setAjaxMessagesXML(AjaxMessagesXML ajaxMessagesXML) {
    this.ajaxMessagesXML = ajaxMessagesXML;
  }

  public void setRoleService(RoleService roleService) {
    this.roleService = roleService;
  }

  public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -