Skip to Content.
Sympa Menu

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: "Hyzer, Chris" <>
  • To: "Redman, Chad" <>, Rory Larson <>, "" <>
  • Subject: [grouper-users] RE: How to delete direct memberships without touching subgroups and their members
  • Date: Mon, 12 Feb 2018 16:31:32 +0000
  • Accept-language: en-US
  • Authentication-results: spf=none (sender IP is ) ;
  • Ironport-phdr: 9a23:x2uauRTgRZ57J2+mPaG9SCYAhtpsv+yvbD5Q0YIujvd0So/mwa67ZBGEt8tkgFKBZ4jH8fUM07OQ7/i5HzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba9vIBmssQndqtQdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KpwVhTmlDkIOCI48GHPi8x/kqRboA66pxdix4LYeZyZOOZicq/Ye94RWGhPUdtLVyFZAo2ycZYBD/YPM+hboYnypVoOogexCwajH+7v1iZIimPq0aEmz+gtDwfL1xEgEdIUt3TUqc34OKkQX+G1zajH0y/DY+tL0jrj6IjIaBEhoeqCUbltdsfRzFUgFwPFj1SRt4PlJSiY1uUWs2eH9eZgSPqvhHAhqwF3uDSg2NojipTQi48T11vK+yJ5wIMvKt25Tk52ed+kEJ1Mty6ELYt2RN0tQ312tCog1LIJpIO7cS4Xw5ok3x7Sc+KLf5WJ7x75WuudPy10iG9mdb6inRq+71SsxvXhWsS6zFpGtC5InsTWunwTyhDe7tKLRuZ/80qgwTqP2R7c5+JYLU0xkKfXNoMuz70/m5cWr0vMBDP6lUD1gaCIaEkp/u2l5P/nb7XoupCRMZJ/hBvkPaQ0gMO/BPw1MggQUGif/uSxzKXt8FH+TrlWgPA6i7fUvonHKcgCoa62GBFa3pwk6xaiEzepy9MYnWQBLF1YYh6Hl5LpO1bSIP/mEfi/n1WskDBtx/zcOb3hH4nNLnzEkLfmfrZx8VJTyA02zdxH5pJUDK8OIO7rV0PvqdDVDwU1PgKqz+r9Fdlw1Z4SVXiRDqOFKK/StEWH5uMrI+mCfo8VvzP9JuAg5/HyjX84mV4ccrez3ZYMaXC4BehpL1+EYXr0nNgBF2EKshAgQ+P3lV2OSSRTaGqqX6Ig+jE7D5qrDYjZRoCqnbyBxDm0HodPamBbEVCDD23od56fVvcIaSKSOdNhkicaWbS7So8h0w2uuxHgy7phMOXU5jMUuYj929do+u2A3S01oHZOAsiY2mfJB0p0l29CD2s93KlzllZwxlKK14BlhfceGNBOsbcBaAAgJNb4xvZhDNa6DhjFd82ST1D/asigBXc8Qs9nh5dEbFx6Bs2vlFXexCewGJcUkaCGHpo57via0nTsbY4pxGzBybEslRw7WcZVLkWngLJy7Q7eG9SPnkmEwfWEb6MZiWTt5XWO1y7Gl0FCURU6GfHAVnAOdEbMhdXi7QXfV7KoD/IqPhYXmp3KEbdDdtC81QYOf/zkItmLJjvpw2o=
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

That is great Chad! I added that to the GSH wiki.

https://spaces.internet2.edu/pages/viewpage.action?pageId=14517859

Rory, do you have a copy of the stacktrace that gave the original error?
Please send it along if so.

Thanks
Chris

-----Original Message-----
From:


[mailto:]
On Behalf Of Redman, Chad
Sent: Saturday, February 10, 2018 1:44 AM
To: Rory Larson
<>;


Subject: [grouper-users] 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




Archive powered by MHonArc 2.6.19.

Top of Page