Package com.foxconn.gds.security.model

Examples of com.foxconn.gds.security.model.Group


          acc = new UserAccount(i + "-acc-" + j, "Foxconn88");
          acc.setProfile(pfl);
          //accMgr.createUserAccount(acc);
         
          //同時創建一個組與account相同,並將此account加到此組中
          Group group = new Group(acc.getAccount());
          accMgr.createGroup(group);
         
          //
          UserGroup userGroup = new UserGroup(acc, group);
          Collection<UserGroup> inGroups = new ArrayList<UserGroup>();
View Full Code Here


   * 與Group相關的操作
   * ======================================================================
   */
  @Test
  public void testCreateGroup() throws Exception {
    Group group = new Group("ADMIN");
    boolean created = UserAccountServices.getInstance().createGroup(group);
    Assert.assertTrue(created);
   
    group = new Group("NORMAL");
    created = UserAccountServices.getInstance().createGroup(group);
    Assert.assertTrue(created);
  }
View Full Code Here

    }
  }
 
  @Test
  public void testSaveOrUpdateGroup01() {
    Group newGrp = new Group("newGroup01");
    boolean updated = true;
    try {
      boolean bool = UserAccountServices.getInstance().saveOrUpdateGroup(newGrp, null);
      Assert.assertTrue(bool);
    } catch (Exception e) {
View Full Code Here

    }
  }
 
  @Test
  public void testSaveOrUpdateGroup02() {
    Group newGrp = UserAccountServices.getInstance().findGroupByName("newGroup01");
    boolean updated = true;
    try {
      boolean bool = UserAccountServices.getInstance().saveOrUpdateGroup(newGrp, null);
      Assert.assertTrue(bool);
    } catch (Exception e) {
View Full Code Here

    }
  }
 
  @Test
  public void testSaveOrUpdateGroup03() {
    Group newGrp = UserAccountServices.getInstance().findGroupByName("newGroup01");
    String[] accAy = new String[]{"100-acc-0", "101-acc-0"};
    boolean updated = true;
    try {
      boolean bool = UserAccountServices.getInstance().saveOrUpdateGroup(newGrp, accAy);
      Assert.assertTrue(bool);
View Full Code Here

    return (findGroupByName(groupName)!=null);
  }
 
  public Group findGroupByName(String groupName) {
    log.info("enter findGroupByName ...");
    Group result;
    String hql = "from Group where groupName = ? AND 1=1";
    try {
      EntityManager em = entityManagerFactory.createEntityManager();
      result = (Group) em.createQuery(hql).setParameter(1,
          groupName).getSingleResult();
View Full Code Here

    Collection<UserGroup> inGroups = userAccount.getInGroups();
    if( inGroups.toString().contains(groupName) ) {
      log.warning("User has readly been in the Group!");
      return false;
    } else {
      Group group = this.findGroupByName(groupName);
      if(group==null) {
        group = new Group(groupName);
        if(!this.createGroup(group)) {
          log.warning("Create Group " + groupName + " failure!");
          return false;
        }
      }
View Full Code Here

      tx =em.getTransaction();
      tx.begin();
     
      profile = em.merge(profile);
//     
      Group tmpGrp = null;
      String tmpGrpName = null;
      for(UserGroup ugrp :user.getInGroups()) {
        tmpGrpName = ugrp.getGroup().getGroupName();
        tmpGrp = this.findGroupByName( tmpGrpName );
        if(tmpGrp==null){
          tmpGrp = new Group( tmpGrpName );
          em.persist(tmpGrp);
        }
        ugrp.setGroup( tmpGrp );
      }
View Full Code Here

   
    return true;
  }
 
  public boolean saveOrUpdateGroup(Group group, String[] accountAy) throws Exception {
    Group pGrp = this.findGroupByName(group.getGroupName());
    if(pGrp==null) {
      if( this.createGroup(group) ) {
        pGrp = group;
      }
    }
    //-------------------------------------------------------
    Collection<UserGroup> ownUsers = null;
    if(accountAy!=null) {
      for(String account : accountAy){
        UserAccount userAccount = this.findUserAccountByID(account);
        UserGroup userGroup = new UserGroup(userAccount, pGrp);
        if(ownUsers==null) {
          ownUsers = new ArrayList<UserGroup>();
        }
        ownUsers.add(userGroup);
      }
    }
    pGrp.setOwnUsers(ownUsers);
   
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
      em = entityManagerFactory.createEntityManager();
      tx = em.getTransaction();
      tx.begin();
     
      String hql = "DELETE FROM UserGroup WHERE group.id=?";
      em.createQuery(hql).setParameter(1, pGrp.getId())
        .executeUpdate();
     
      em.merge(pGrp);
      tx.commit();
    } catch (Exception err) {
View Full Code Here

        jnObj.put("page", sspInfo.getPage());
        jnObj.put("total", sspInfo.getTotal());
        jnObj.put("records", sspInfo.getRecords());
       
        JSONArray jnAry = new JSONArray();
        Group grp = null;
        JSONObject perJN=null;
        StringBuilder sb = new StringBuilder();
        for(int i=0, size=allGroups.size(); i<size; i++) {
          grp = allGroups.get(i);
          perJN = new JSONObject();
          perJN.put("id", grp.getId());
         
          perJN.put("groupName", grp.getGroupName());
          sb = new StringBuilder();
          for(UserGroup ug : grp.getOwnUsers()) {
            if(ug.getUserAccount()!=null) {
              sb.append( ug.getUserAccount().getAccount() ).append(",");
            }
          }
          perJN.put("ownUsers", sb.toString());
         
          jnAry.add(perJN);
        }
       
        jnObj.put("rows", jnAry);
       
        System.out.println( "JSON.toString = \n"+ jnObj.toString() );
        res.setContentType("text/json;charset=utf-8");
        res.getWriter().write( jnObj.toString() );
// FETCH ALL USERS       
    } else if(req.getRequestURI().endsWith("allUsers.do")) {
      List<UserAccount> allUsers = UserAccountServices.getInstance().listAllUserAccount();
      JSONArray jnAry = new JSONArray();
      UserAccount account = null;
      JSONObject perJN=null;
      for(int i=0, size=allUsers.size(); i<size; i++) {
        account = allUsers.get(i);
        perJN = new JSONObject();
        perJN.put("id", account.getId());
        perJN.put("account", account.getAccount());
        jnAry.add(perJN);
      }
     
      System.out.println( "JSON.toString = \n"+ jnAry.toString() );
      res.setContentType("text/json;charset=utf-8");
      res.getWriter().write( jnAry.toString() );
// SAVE OR UPDATE GROUP     
    } else if (req.getRequestURI().endsWith("saveOrUpdateGroup.do")) {
      //System.out.println("req.URI="+req.getRequestURI());
      String id = req.getParameter("id");
      String groupName = req.getParameter("groupName");
      String ownUsers = req.getParameter("ownUsers");
      JSONObject jnObj = new JSONObject();
      try {
        Group group = new Group(groupName);
        if(id!=null&&id.trim().length()!=0) {
          group.setId( Long.parseLong(id) );
        }
        String[] accountAy = null;
        if(ownUsers!=null) {
          accountAy = ownUsers.split(",");
        }
View Full Code Here

TOP

Related Classes of com.foxconn.gds.security.model.Group

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.