Skip to Content.
Sympa Menu

grouper-users - RE: [grouper-users] Recursive stem delete?

Subject: Grouper Users - Open Discussion List

List archive

RE: [grouper-users] Recursive stem delete?


Chronological Thread 
  • From: Chris Hyzer <>
  • To: Colin Hudler <>, Grouper Users Mailing List <>
  • Subject: RE: [grouper-users] Recursive stem delete?
  • Date: Wed, 19 Nov 2008 13:02:59 -0500
  • Accept-language: en-US
  • Acceptlanguage: en-US

This seems like a useful function, I added a jira request (not sure what
release it will be in).

https://bugs.internet2.edu/jira/browse/GRP-187

I had thought if a group were a composite member of another group that you
cant delete the group that is a member (due to foreign key... what should
happen to the composite group? Should the composite membership disappear?

Anyways, having said that, I couldn’t immediately reproduce, and I was able
to run Tom Zeller's script in GSH (in grouper 1.4):

addRootStem("a", "a");
addGroup("a", "groupA", "groupA");
addStem("a", "b", "b");
addGroup("a:b", "groupB", "groupB");
addStem("a", "c", "c");
addGroup("a:b", "groupB1", "groupB1");
addGroup("a:c", "groupC1", "groupC1");
addGroup("a:c", "groupC2", "groupC2");

grouperSession = GrouperSession.startRootSession();

stem = StemFinder.findByName(grouperSession, "a");
for(child : stem.getChildGroups(Stem.Scope.SUB)) { child.delete(); }
for(childStem : stem.getChildStems(Stem.Scope.SUB)) { childStem.delete(); }
stem.delete();

StemFinder.findByName(grouperSession, "a");
//cant find!



> -----Original Message-----
> From: Colin Hudler
> [mailto:]
> Sent: Wednesday, November 19, 2008 12:40 PM
> To: Grouper Users Mailing List
> Subject: Re: [grouper-users] Recursive stem delete?
>
> Tom Zeller wrote:
> > Since the Grouper 1.2.1 API, perhaps :
> >
> > for(Group child : stem.getChildGroups(Scope.SUB)) {
> > child.delete();
> > }
> > for(Stem child : stem.getChildStems(Scope.SUB)) {
> > child.delete();
> > }
>
> That's very close to how I do it, except it probably needs to recurse.
>
> Here is an example written in JRuby
>
> include Java
> Dir["/srv/grouper/api/dist/lib/grouper.jar"].each { |jar| require jar }
> Grouper = Java::edu.internet2.middleware.grouper
> Stem = Grouper.StemFinder
> Session =
> Grouper.GrouperSession.start(Grouper.SubjectFinder.find_by_id('GrouperS
> ystem'))
>
> def delete_groups(stem)
> stem.get_child_groups.each { |group| group.delete }
> end
>
> def delete_stems(stem)
> stem.get_child_stems.each { |stem|
> delete_groups(stem);delete_stems(stem) }
> stem.delete
> end
>
> stem = Stem.find_by_name(Session, ARGV[0])
> delete_groups(stem)
> delete_stems(stem)



Archive powered by MHonArc 2.6.16.

Top of Page