protected void importFromLDAPByGroup(
      long ldapServerId,
      long companyId,
      LdapContext ldapContext,
      Properties userMappings,
      Properties userExpandoMappings,
      Properties contactMappings,
      Properties contactExpandoMappings,
      Properties groupMappings)
      throws Exception {

    byte[] cookie = new byte[0];

    while (cookie != null) {
      List<SearchResult> searchResults = new ArrayList<SearchResult>();

      String groupMappingsGroupName =
          GetterUtil.getString(groupMappings.getProperty("groupName")).toLowerCase();

      cookie =
          PortalLDAPUtil.getGroups(
              ldapServerId,
              companyId,
              ldapContext,
              cookie,
              0,
              new String[] {groupMappingsGroupName},
              searchResults);

      for (SearchResult searchResult : searchResults) {
        try {
          Attributes attributes =
              PortalLDAPUtil.getGroupAttributes(
                  ldapServerId,
                  companyId,
                  ldapContext,
                  PortalLDAPUtil.getNameInNamespace(ldapServerId, companyId, searchResult),
                  true);

          UserGroup userGroup = importUserGroup(companyId, attributes, groupMappings);

          Attribute usersAttribute =
              getUsers(ldapServerId, companyId, ldapContext, attributes, userGroup, groupMappings);

          if (usersAttribute == null) {
            if (_log.isInfoEnabled()) {
              _log.info("No users found in " + userGroup.getName());
            }

            continue;
          }

          importUsers(
              ldapServerId,
              companyId,
              ldapContext,
              userMappings,
              userExpandoMappings,
              contactMappings,
              contactExpandoMappings,
              userGroup.getUserGroupId(),
              usersAttribute);
        } catch (Exception e) {
          _log.error("Unable to import group " + searchResult, e);
        }
      }
    }
  }