if (LOG.isInfoEnabled()) { LOG.debug("Loading memberships for " + groupName); }
LOG.debug("Loading memberships for " + groupName);
  private void _processMembershipLists()     throws  GrouperException,            GroupModifyException,            GroupNotFoundException,            InsufficientPrivilegeException,            MemberAddException,            MemberDeleteException,            SchemaException,            SubjectNotFoundException  {    if (membershipLists == null || membershipLists.size() == 0) {      return;    }    Collection  subjects;    Iterator    subjectsIterator;    Element     subjectE;    Element     list;    String      listName;    Field       field               = null;    Subject     subject;    String      groupName;    String      lastGroupName       = "";    Group       group               = null;    Map         map;    String      subjectId;    String      subjectIdentifier;    String      subjectType;    Group       privGroup;    boolean     isImmediate;    String      importOption;    for (int i = 0; i < membershipLists.size(); i++) {      map = (Map) membershipLists.get(i);      list = (Element) map.get("list");      importOption = list.getAttribute("importOption");      if (XmlUtils.isEmpty(importOption)) {        importOption = options.getProperty("import.data.lists");      }      if (XmlUtils.isEmpty(importOption) || "ignore".equals(importOption)) {        continue; //No instruction so ignore      }      groupName = (String) map.get("group");      //Save a call if we are dealing with same group      if (!groupName.equals(lastGroupName)) {        if (!XmlUtils.isEmpty(lastGroupName)) {          if (LOG.isInfoEnabled()) {            LOG.debug("Finished loading memberships for " + lastGroupName);          }        }        group = GroupFinder.findByName(s, groupName);        if (LOG.isInfoEnabled()) {          LOG.debug("Loading memberships for " + groupName);        }      }      lastGroupName = groupName;      listName = list.getAttribute("field");      try {        field = FieldFinder.find(listName);        if (!field.getType().equals(FieldType.LIST)) {          LOG.error(listName + " is not a list");          continue;        }      }       catch (Exception e) {        LOG.error("Cannot find list " + listName);        continue;      }      //TODO add admin check?      if (!group.hasType(field.getGroupType())) {        if (_optionTrue("import.data.apply-new-group-types")) {          if (LOG.isInfoEnabled())            LOG.debug("Adding group type " + field.getGroupType());          group.addType(field.getGroupType());        }         else {          if (LOG.isInfoEnabled()) {            LOG.debug("Ignoring field " + field.getName());          }          continue;        }      }      if (!group.canReadField(field)) {        LOG.debug("No write privilege - ignoring field " + field.getName());        continue;      }      boolean hasComposite  = group.hasComposite();      boolean hasMembers    = false;      if (!hasComposite && group.getImmediateMembers().size() > 0) {        hasMembers = true;      }      Element compE = _getImmediateElement(list, "composite");      if ("replace".equals(importOption)) {        if (hasComposite) {          group.deleteCompositeMember();        }         else {          Set       members         = group.getImmediateMembers(field);          Iterator  membersIterator = members.iterator();          Member    memb;          if (LOG.isInfoEnabled()) {            LOG.debug("Removing all memberships for " + groupName);          }          while (membersIterator.hasNext()) {            memb = (Member) membersIterator.next();            group.deleteMember(memb.getSubject());          }        }      }      if (compE != null && (!"add".equals(importOption) || hasMembers)) {        _processComposite(compE, group);        continue;      }      if (compE != null && hasMembers) {        LOG.warn("Skipping composite - cannot ad to existing members for " + groupName);        continue;      }      subjects          = _getImmediateElements(list, "subject");      subjectsIterator  = subjects.iterator();      while (subjectsIterator.hasNext()) {        subjectE    = (Element) subjectsIterator.next();        isImmediate = "true".equals(subjectE.getAttribute("immediate"));        if (XmlUtils.isEmpty(subjectE.getAttribute("immediate"))) {          isImmediate = true;        }        if (!isImmediate) {          continue;        }        subjectId         = subjectE.getAttribute("id");        subjectIdentifier = subjectE.getAttribute("identifier");        subjectType       = subjectE.getAttribute("type");        if ("group".equals(subjectType)) {          if (            subjectIdentifier.startsWith("*")            &&             !subjectIdentifier.endsWith("*")          )           {            //relative import            if (!XmlUtils.isEmpty(importRoot)) {              subjectIdentifier = importRoot + Stem.ROOT_INT + subjectIdentifier.substring(1);            }            else {              subjectIdentifier = subjectIdentifier.substring(1);            }          }           else {            if ("*SELF*".equals(subjectIdentifier)) {              subjectIdentifier = groupName;            }            else {              subjectIdentifier = _getAbsoluteName(                subjectIdentifier, group.getParentStem() .getName()              );            }          }          try {            privGroup = GroupFinder.findByName(s, subjectIdentifier);          }           catch (Exception e) {            LOG.warn("Could not find Group identified by " + subjectIdentifier);            continue;          }          subject = privGroup.toMember().getSubject();        }         else {          try {            if (XmlUtils.isEmpty(subjectId)) {              subject = _getSubjectByIdentifier(subjectIdentifier, subjectType);            }             else {              subject = _getSubjectById(subjectId, subjectType);            }          }           catch (Exception e) {            String msg = "Could not find subject with ";            if (XmlUtils.isEmpty(subjectId)) {              msg = msg + "identifier=" + subjectIdentifier;            }            else {              msg = msg + "id=" + subjectId;            }            LOG.error(msg);            continue;          }        }        if (!group.hasImmediateMember(subject, field)) {          if (LOG.isDebugEnabled()) {            LOG.debug(              "Making " + subject.getName()              + " a member of " + group.getName() + "(list="              + listName + ")"            );          }          group.addMember(subject, field);          if (LOG.isDebugEnabled()) {            LOG.debug("...assigned");          }        }         else {          if (LOG.isDebugEnabled()) {            LOG.debug(              subject.getName()              + " is already a member of " + group.getName()              + "- skipping"            );          }        }      }    }    membershipLists = null;  } // private void _processMembershipLists()