grouper-users - [grouper-users] RE: How to delete direct memberships without touching subgroups and their members
Subject: Grouper Users - Open Discussion List
List archive
[grouper-users] RE: How to delete direct memberships without touching subgroups and their members
Chronological Thread
- From: Rory Larson <>
- To: "Redman, Chad" <>, "" <>
- Subject: [grouper-users] RE: How to delete direct memberships without touching subgroups and their members
- Date: Sun, 11 Feb 2018 23:48:12 +0000
- Accept-language: en-US
- Authentication-results: spf=none (sender IP is ) ;
- Ironport-phdr: 9a23:m9Gt0By7QZtyuw7XCy+O+j09IxM/srCxBDY+r6Qd2u0RIJqq85mqBkHD//Il1AaPAd2Craocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HObwlSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDtU7s6RSqt4LtqSB/wiScIKTg58H3MisdtiK5XuQ+tqwBjz4LRZoyeKfhwcb7Hfd4CRWRPQNtfVzBPDI2/YYsADesBMvpXoYbyvFYOsQK+CRWwCO/z1jNEmHn71rA63eQ7FgHG2RQtEc4JsHTOrNT+KaEcXvqvzKnTyjXDae5d1DDn6IjMaB8hu+qMXbV2ccbM0kQvCgXFjlGKpYP7IjyVy/0Avm6G5ORjTeKik3ArpBttrjSyw8ogl5TFip8Qx1DK+ih13Jo5KNi6RUFlbtOoDJ5duiSEO4dqXM8uW3xktDg+x7EcvZO2cjIGxZs9yxLBa/GLa4aI7QzgWeqNJDp1gX1od66/ihmv9EWv1O7xWtSx3VtOtCVIksTDu3UD2hPP6sWKSP1w9Vq71zmVzQDc8ORELFg0laXFL54hxaY9mIIPvErEAiP6hVz6grKOeEk54+So7P/obav8qp+bKo90lhrxMqMzmsy5HOs0KBAOX3Kc+eSgyrLs4VH5QLRNjv0wiKXZt43aJdgfpq6+BA9V0Zwv5Aq4DzejyNgYnH8HI0xZeB+fkYTmIU3CLO39APuinligjTJmx/7JM7H9HpnAK3rOn6nucLph7kNRzRQ/wcxB655MD7EOOvPzWkv/tNzCCR85NhS5w/zjCNpnzIMeQmWPAqmEPK7JrF+I4OYvL/OSa4AIpTbxM+Il6OL2jX8lhV8derGk3ZQNaHC/A/RmO1uWYWD1jtccCmcFoBA+TPfxhV2GUD5TfGqyX7ki6j0hCYKmC5vDSZ63gLyHwii7AoNaanpYBV+RDHe7P7mDDr02ZS6XK8kl2hcEXLTrA9sq1RiigxX3x79uKMLJ/CZeuJ7+gpw9reLJkgwq+CYxEt+QyXqlTmdok3kOSiNsmq1zvAY1nliZ1rVgjuYdCMde/ehhUwEmOITawvAgTd3+R1SSUM2OTQOcRc+3SRU4VMk2xZdaeUJ0Ac6liEnrwiyuRbIZiurYV9QP7qvA0i2pdI5GwHHc2fxk1gF+Tw==
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Hi Chad,
Thanks very much for this! That was just what I needed to get over the hump.
The way that eventually worked for me was essentially as follows:
gsh 0% sess = GrouperSession.startRootSession();
gsh 1% sw = GroupFinder.findByName(sess, "our:campus:group:studentworker",
true);
gsh 2% immediateMembers = sw.getImmediateMembers();
gsh 3% for (Member m: sw.getMembers()) {if ((immediateMembers.contains(m))
&& (m.getSubject().getName().length() >= 1) &&
(m.getSubject().getName().substring(0,1).compareTo("Z") <= 0))
{System.out.println("Deleting " + m.getSubject().getName());
sw.deleteMember(m, false);} }
Some takeaways:
1. Trying to do mass deletes like this through the UI is slow, and crashes
regularly every 10-25 records. Doing it through gsh is relatively quick,
perhaps about two records per second, and can apparently chew through
thousands in a row without ever choking.
2. The group.deleteMember(m, false) call deletes only direct memberships, not
indirect ones. This makes perfect sense, of course. I needn't have worried
on that score.
3. At first, the evidence seemed to indicate to me that group.getMembers()
and perhaps group.getImmediateMembers() returned only subjects (direct member
people), not member groups. If that were so, it should be possible to base
the mass delete solely on the [ if (immediateMembers.contains(m)) ] part of
the query. A final experiment before trying it showed this to be wrong. The
reason the member groups were not showing up under the full conditional that
filtered for the initial part of the name, is that the "name" returned for
the member groups is their ID path. A student worker like Sally Brown would
start with uppercase "S", which is less than "Z". But the ID path for our
member groups happened to begin with a lowercase "u", which is greater. So I
was apparently right to be worried about the possibility of deleting the
member groups this whole procedure was intended to save. This twist was
unexpected.
At any rate, the superfluous direct members have been deleted now, and our
Student Worker group seems to be happy. Again, thanks so much for chiming in
and sharing your expertise!
Best,
Rory
-----Original Message-----
From: Redman, Chad
[mailto:]
Sent: Saturday, February 10, 2018 12:44 AM
To: Rory Larson
<>;
Subject: RE: How to delete direct memberships without touching subgroups and
their members
Hi Rory,
The Group class has methods for getImmediateMembers() and
getEffectiveMembers(), so the combination of those two would make it a
straightforward task. Here are two sample scripts. Depending on your GSH
version (original bsh or the newer groovy), you may need to fold the
multi-line blocks into a single line.
# (1) Print tab-separated summary of all group members, and flags for direct,
indirect, or both # Depending on the results, you could use the data to
create a scrutinized list of Ids to delete, then import it and delete in a
loop
me = SubjectFinder.findByIdentifierAndSource("my-username", "pid", true);
session = GrouperSession.start(me); // OR: session =
GrouperSession.startRootSession(True)
group = GroupFinder.findByName(session, "tmp:my:group", true);
effectiveMembers = group.getEffectiveMembers(); immediateMembers =
group.getImmediateMembers();
System.out.println(String.join("\t", "id", "name", "Effective", "Immediate"));
for (Member m: group.getMembers()) {
System.out.print(m.getSubject().getId() + "\t" + m.getSubject().getName()
+ "\t");
System.out.print(effectiveMembers.contains(m).toString() + "\t");
System.out.println(immediateMembers.contains(m).toString() + "\t"); }
# (2) Get the immediate and effective members for a specific source ("pid" in
this example), intersect them to find the redundant ones # This has a dryRun
flag, so you can test first
sources = new HashSet<Source>()
sources.add(SourceManager.getInstance().getSource("pid"))
effectiveUsers = group.getEffectiveMembers(Group.getDefaultList(), sources,
null) immediateUsers = group.getImmediateMembers(Group.getDefaultList(),
sources, null)
# use retainAll() to find the intersection; i.e., users both as effective and
immediate member
immediateUsers.retainAll(effectiveUsers)
System.out.println("There are " + immediateUsers.size() + " users having both
direct + indirect memberships");
dryRun = true
for (Member m: immediateUsers) {
if (dryRun) {
System.out.println("Ok to delete " + m.getSubject().getId());
} else {
System.out.println("Deleting " + m.getSubject().getId());
group.deleteMember(m, false);
}
}
Hope this helps!
Chad
-----Original Message-----
From:
[mailto:]
On Behalf Of Rory Larson
Sent: Friday, February 09, 2018 8:52 PM
To:
Subject: [grouper-users] How to delete direct memberships without touching
subgroups and their members
Hello,
I have a group with largely redundant membership. It was originally created
with direct memberships from one data source, and then given a few groups
from another data source that had most of the same people, in a process
intended to be a smooth transition. Now I would like to remove all the old
direct memberships from the group, leaving only the new subgroups with their
members.
When I try this through the Grouper New UI, marking all direct members on the
page for deletion, it grinds for a while, deletes a few members, and then
crashes with a pink error message telling me to start over. It works as
advertised for the few it does delete, but since I'm dealing with a
membership of over 7500, this route does not look promising.
I would like to handle this through gsh, but I'm having trouble figuring out
how to filter. The query I've been developing might look something like this:
$ for (mem : getMembers("my:group:name")) {System.out.println("deleting: " +
mem.getName()); mem.delete();}
But I'm queasy about using this, because I'm not sure what all I'm deleting,
and where. I don't want to delete my subgroups, and I don't want to delete
anybody inside those subgroups. I tried testing with an if statement to
check names against who shows up with direct and indirect memberships in the
New UI, and was disappointed to discover that getMembers() returns both
direct and indirect members.
Is there a method that will return only the direct members of a group, but
not member groups? Or is there a filter I could use to select only the ones
I want through an if statement?
Thanks,
Rory
- [grouper-users] How to delete direct memberships without touching subgroups and their members, Rory Larson, 02/10/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Redman, Chad, 02/10/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Rory Larson, 02/11/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Redman, Chad, 02/12/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Hyzer, Chris, 02/12/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Rory Larson, 02/11/2018
- [grouper-users] RE: How to delete direct memberships without touching subgroups and their members, Redman, Chad, 02/10/2018
Archive powered by MHonArc 2.6.19.