GrouperGroup memberOfBase = g;  if (m.typeID().equals("group")) { memberOfBase = GrouperBackend._groupLoadByID( m.subjectID() );
GrouperMember mg = GrouperMember.load(g.id(), "group"); List groups = new ArrayList(); Iterator mgA = GrouperBackend.listVals(s, mg, list).iterator(); while (mgA.hasNext()) { GrouperList glA = (GrouperList) mgA.next(); GrouperBackend._listAddVal( session, glA.group(), m, list, g ); groups.add(glA.group());
  protected static boolean listAddVal(GrouperSession s, GrouperGroup g, GrouperMember m, String list) {    Session session = GrouperBackend._init();    boolean rv      = false;    // FIXME Better validation efforts, please.    // TODO  Refactor to a method    // TODO  Refactor commonality with listDelVal    if (        g.getClass().getName().equals("edu.internet2.middleware.grouper.GrouperGroup")   &&        s.getClass().getName().equals("edu.internet2.middleware.grouper.GrouperSession") &&        m.getClass().getName().equals("edu.internet2.middleware.grouper.GrouperMember")  &&        Grouper.groupField(g.type(), list)       )     {      // Verify that the value doesn't already exist      List vals = GrouperBackend._queryGrouperList(                    session, g.key(), m.key(), Grouper.DEF_LIST_TYPE, Grouper.MEM_IMM                  );      // Doesn't exist      if (vals.size() == 0) {        try {          Transaction t = session.beginTransaction();          // Update immediate list data          GrouperBackend._listAddVal(session, g, m, list, null);          GrouperGroup memberOfBase = g;          // Is this member a group?          if (m.typeID().equals("group")) {            memberOfBase = GrouperBackend._groupLoadByID( m.subjectID() );          }          // Grab immediate list data to update          List imms = GrouperBackend._listVals(                                               session, memberOfBase, null,                                               list, Grouper.MEM_IMM                                              );          // Update effective list data          Iterator effIter = GrouperBackend._memberOf(                              session, memberOfBase, list                             ).iterator();          while (effIter.hasNext()) {            GrouperVia via = (GrouperVia) effIter.next();            GrouperBackend._listAddVal(                                       session, via.group(),                                       via.member(), list, via.via()                                      );            Iterator immsIter = imms.iterator();            while(immsIter.hasNext()) {              GrouperList   gl  = (GrouperList) immsIter.next();              GrouperMember mem = (GrouperMember) gl.member();              if (mem != null) {                GrouperBackend._listAddVal(                                           session, via.group(),                                           mem, list, memberOfBase                                          );              } // TODO else...            }          }          // Update modify information          session.update(g);          // Commit it          t.commit();          rv = true;        } catch (Exception e) {          // TODO We probably need a rollback in here in case of failure          //      above.          System.err.println(e);          System.exit(1);        }      }    }     GrouperBackend._hibernateSessionClose(session);    return rv;  }