Package si.unimb.cot.mgbl.gamemgmt.formbeans

Examples of si.unimb.cot.mgbl.gamemgmt.formbeans.EditGameSecurityForm2


  public ActionForward defaultMethod(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res) {
   
    //we use transactions here
    //super.defaultMethod(am, af, req, res);
   
    EditGameSecurityForm2 form=(EditGameSecurityForm2)af;

    MessageBean.addSpeedOMeterCheckPoint(req, "point1");
   
    form.setMyUserId(webUser.getId());
   
    long id=Long.parseLong(req.getParameter("id"));
    GameHiber g=GameDao.findGameHiber(id,session);
    Game g2=GameDao.findGame(id,session);

    MessageBean.addSpeedOMeterCheckPoint(req, "point2");
   
    form.setGame(g2);
   
    if (!SecurityCenter.canIDefineSecurityForGame(webUser.getId(), form.getGame())) {
      MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
      form.reset();
      return am.findForward("error");
    }
   
    //if needeed invalidate cache
    if (req.getParameter("invalidateCache")!=null) {
      SecurityCenter.invalidateCache();
      searchGroupsCache=null;
      searchUserSetsCache=null;
      searchUsersCache=null;
      MessageBean.setMyMessage(req, ("Security cache invalidated."));
    }
   
    //do the update, if needed - allow
    MessageBean.addSpeedOMeterCheckPoint(req, "point3");
    boolean changed=false;
   
    if (req.getParameter("AllowBrowseUser")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,Long.parseLong(req.getParameter("AllowBrowseUser")),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlayUser")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,Long.parseLong(req.getParameter("AllowPlayUser")),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditUser")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,Long.parseLong(req.getParameter("AllowEditUser")),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresUser")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,Long.parseLong(req.getParameter("AllowViewScoresUser")),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllUser")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,Long.parseLong(req.getParameter("AllowAllUser")),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}

    if (req.getParameter("AllowBrowseGroup")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,Long.parseLong(req.getParameter("AllowBrowseGroup")),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlayGroup")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,Long.parseLong(req.getParameter("AllowPlayGroup")),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditGroup")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,Long.parseLong(req.getParameter("AllowEditGroup")),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresGroup")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,Long.parseLong(req.getParameter("AllowViewScoresGroup")),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllGroup")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,Long.parseLong(req.getParameter("AllowAllGroup")),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}

    if (req.getParameter("AllowBrowseUserSet")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,Long.parseLong(req.getParameter("AllowBrowseUserSet")),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlayUserSet")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,Long.parseLong(req.getParameter("AllowPlayUserSet")),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditUserSet")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,Long.parseLong(req.getParameter("AllowEditUserSet")),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresUserSet")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,Long.parseLong(req.getParameter("AllowViewScoresUserSet")),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllUserSet")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,Long.parseLong(req.getParameter("AllowAllUserSet")),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    //do the update, if needed - revoke
    if (req.getParameter("RevokeSubmitPlayUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowPlayForUsersSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("RevokeSubmitPlayGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowPlayForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("RevokeSubmitPlaySet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowPlayForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point7");

    if (req.getParameter("RevokeSubmitEditUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowEditForUsersSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("RevokeSubmitEditGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowEditForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("RevokeSubmitEditSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowEditForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point8");

    if (req.getParameter("RevokeSubmitBrowseUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowBrowseForUsersSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("RevokeSubmitBrowseGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowBrowseForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("RevokeSubmitBrowseSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowBrowseForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point9");

    if (req.getParameter("RevokeSubmitAllUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowAllForUsersSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
    if (req.getParameter("RevokeSubmitAllGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowAllForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
    if (req.getParameter("RevokeSubmitAllSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowAllForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point10");

    if (req.getParameter("RevokeSubmitViewScoresUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowViewScoresForUsersSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("RevokeSubmitViewScoresGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowViewScoresForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("RevokeSubmitViewScoresSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowViewScoresForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
   
    if (changed) {
      //update the security summary for the game
      //for faster working!
     
      List<GameSecurityHiber> gss=null;
      StringBuffer summary=new StringBuffer();
     
      gss=GameSecurityDao.getGameSecurityForGameAllowAll(g.getId(),session);
      if (gss.size()>0) {
        summary.append("A(");
        boolean first=true;
       
        MessageBean.addSpeedOMeterCheckPoint(req, "point11");

        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
       
        MessageBean.addSpeedOMeterCheckPoint(req, "point12");

       
        summary.append(") ");
      }
     
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point13");


      gss=GameSecurityDao.getGameSecurityForGameAllowEdit(g.getId(),session);
      if (gss.size()>0) {
        summary.append("E(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        if (first) { first=false;} else {summary.append(", "); }
        summary.append(") ");
      }

     
      MessageBean.addSpeedOMeterCheckPoint(req, "point14");


      gss=GameSecurityDao.getGameSecurityForGameAllowPlay(g.getId(),session);
      if (gss.size()>0) {
        summary.append("P(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;
          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point15");

      gss=GameSecurityDao.getGameSecurityForGameAllowBrowse(g.getId(),session);
      if (gss.size()>0) {
        summary.append("B(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point16");

      gss=GameSecurityDao.getGameSecurityForGameAllowViewScores(g.getId(),session);
      if (gss.size()>0) {
        summary.append("VS(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }

      g.setSecuritySummary(summary.toString());
      GameDao.updateGame(g,session);
    }
   
    //end updating summary
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point17");

    //reset the view
    form.reset();
    MessageBean.addSpeedOMeterCheckPoint(req, "point18a");
    if (req.getParameter("id")!=null) {
      //display security for game

      Game toSet=Game.asGameObject(g);
      toSet.setGameType(g2.getGameType());
      form.setGame(toSet);

      List<GameSecurityHiber> all;
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point18");

      //allow browse
      all=GameSecurityDao.getGameSecurityForGameAllowBrowse(g.getId(),session);
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point19a");
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowBrowseForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowBrowseForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowBrowseForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point19");

      //allow play
      all=GameSecurityDao.getGameSecurityForGameAllowPlay(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowPlayForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowPlayForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowPlayForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point20");

      //allow edit
      all=GameSecurityDao.getGameSecurityForGameAllowEdit(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowEditForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowEditForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowEditForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point21");

      //allow view scores
      all=GameSecurityDao.getGameSecurityForGameAllowViewScores(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowViewScoresForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowViewScoresForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowViewScoresForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point22");

      //allow all
      all=GameSecurityDao.getGameSecurityForGameAllowAll(g.getId(),session);
      MessageBean.addSpeedOMeterCheckPoint(req, "point23a");
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowAllForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowAllForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowAllForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }

    }
   
    //do the search for adding security constraint if needed
    if (
        (req.getParameter("AddSubmitBrowseUserSearch")!=null)||
        (req.getParameter("AddSubmitPlayUserSearch")!=null)||
        (req.getParameter("AddSubmitEditUserSearch")!=null)||
        (req.getParameter("AddSubmitViewScoresUserSearch")!=null)||
        (req.getParameter("AddSubmitAllUserSearch")!=null)
      ) {
      String search=req.getParameter("search");
      form.setSearchUsers(searchUserFromAll(search.toUpperCase(),session));
    }
    if (
        (req.getParameter("AddSubmitEditGroupSearch")!=null)||
        (req.getParameter("AddSubmitPlayGroupSearch")!=null)||
        (req.getParameter("AddSubmitBrowseGroupSearch")!=null)||
        (req.getParameter("AddSubmitAllGroupSearch")!=null)||
        (req.getParameter("AddSubmitViewScoresGroupSearch")!=null)
      ) {
      String search=req.getParameter("search");
      form.setSearchGroups(searchUserRoleFromAll(search.toUpperCase(),session));
    }
    if (
        (req.getParameter("AddSubmitViewScoresUserSetSearch")!=null)||
        (req.getParameter("AddSubmitBrowseUserSetSearch")!=null)||
        (req.getParameter("AddSubmitEditUserSetSearch")!=null)||
        (req.getParameter("AddSubmitPlayUserSetSearch")!=null)||
        (req.getParameter("AddSubmitAllUserSetSearch")!=null)
      ) {
      String search=req.getParameter("search");
      form.setSearchUserSets(searchUserSetFromAll(search.toUpperCase(),session));
    }
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point23");

    return am.findForward("ok");
View Full Code Here

TOP

Related Classes of si.unimb.cot.mgbl.gamemgmt.formbeans.EditGameSecurityForm2

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.