grouper/contrib/cdg/src/cdg/com/devclue/grouper/group

1 view
Skip to first unread message

blair christensen

unread,
Dec 16, 2005, 4:48:02 PM12/16/05
to grouper...@listhost.uchicago.edu, grouper...@googlegroups.com
Update
of /home/cvs/i2mi/grouper/contrib/cdg/src/cdg/com/devclue/grouper/group
In directory ellis.internet2.edu:/home/blair/tmp/tmpdir/cvs-serv11088/contrib/cdg/src/cdg/com/devclue/grouper/group

Added Files:
GroupAdd.java GroupQ.java
Log Message:
* mark old contrib items as deprecated
* import a modified version of cdg into contrib


--- /dev/null
+++ contrib/cdg/src/cdg/com/devclue/grouper/group/GroupAdd.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2005 blair christensen.
+ * All Rights Reserved.
+ *
+ * You may use and distribute under the same terms as Grouper itself.
+ */
+
+package com.devclue.grouper.group;
+
+import com.devclue.grouper.session.*;
+import edu.internet2.middleware.grouper.*;
+import edu.internet2.middleware.subject.*;
+import java.util.*;
+
+/**
+ * Add groups to the Groups Registry.
+ * <p />
+ * @author blair christensen.
+ * @version $Id: GroupAdd.java,v 1.1 2005/12/16 21:48:00 blair Exp $
+ */
+public class GroupAdd {
+
+ /*
+ * CONSTRUCTORS
+ */
+
+ /**
+ * Create a new GroupAdd object.
+ * <pre class="eg">
+ * GroupAdd ga = new GroupAdd();
+ * </pre>
+ */
+ public GroupAdd() {
+ // Nothing
+ } // public GroupAdd()
+
+
+ /*
+ * PUBLIC CLASS METHODS
+ */
+
+ /**
+ * Create group within the stem given as command line arguments.
+ * <p>Group is printed to STDOUT if created.</p>
+ * <p>Exits with 0 if group created, 1 otherwise.</p>
+ * <pre class="eg">
+ * // Create a group with extension <i>example</i> within stem
+ * // <i>com</i>.
+ * % java com.devclue.grouper.group.GroupAdd com example
+ * </pre>
+ */
+ public static void main(String[] args) {
+ int ev = 1;
+ GroupAdd ga = new GroupAdd();
+ Group g = null;
+ try {
+ if (args.length == 2) {
+ g = ga.addGroup(args[0], args[1]);
+ }
+ else {
+ System.err.println("Invalid number of arguments: " + args.length);
+ }
+ }
+ catch (RuntimeException e) {
+ System.err.println("Error creating group: " + e.getMessage());
+ }
+ if (g !=null) {
+ ev = 0;
+ System.out.println(
+ g.getUuid() + "," + g.getName() + "," + g.getDisplayName()
+ );
+ }
+ System.exit(ev);
+ } // public static void main(args)
+
+
+ /*
+ * PUBLIC INSTANCE METHODS
+ */
+
+ /**
+ * Add a group.
+ * <pre class="eg">
+ * // Create a group with extension <i>example</i> within stem
+ * // <i>com</i>.
+ * GroupAdd ga = new GroupAdd();
+ * try {
+ * Group g = ga.addGroup("com", "example");
+ * }
+ * catch (RuntimeException e) {
+ * // Group not created
+ * }
+ * </pre>
+ * @param stem Create group within this stem.
+ * @param extension Create group with this extension.
+ * @return Created group.
+ */
+ public Group addGroup(String stem, String extension) {
+ try {
+ GrouperSession s = SessionFactory.getSession();
+ Stem parent = StemFinder.findByName(s, stem);
+ return parent.addChildGroup(extension, extension);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ } // public Group addGroup(stem, extension)
+
+}
+
--- /dev/null
+++ contrib/cdg/src/cdg/com/devclue/grouper/group/GroupQ.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2005 blair christensen.
+ * All Rights Reserved.
+ *
+ * You may use and distribute under the same terms as Grouper itself.
+ */
+
+package com.devclue.grouper.group;
+
+import com.devclue.grouper.session.*;
+import edu.internet2.middleware.grouper.*;
+import java.util.*;
+
+/**
+ * Query for groups within the Groups Registry.
+ * <p />
+ * @author blair christensen.
+ * @version $Id: GroupQ.java,v 1.1 2005/12/16 21:48:00 blair Exp $
+ */
+public class GroupQ {
+
+ /*
+ * CONSTRUCTORS
+ */
+
+ /**
+ * Create a new GroupQ object.
+ * <pre class="eg">
+ * GroupQ gq = new GroupQ();
+ * </pre>
+ */
+ public GroupQ() {
+ // Nothing
+ } // public GroupQ()
+
+
+ /*
+ * PUBLIC CLASS METHODS
+ */
+
+ /**
+ * Query each group named <b>like</b> the command line arguments.
+ * <p />
+ * <p>Groups printed to STDOUT if found, STDERR otherwise.</p>
+ * <p>Exits with 0 if all groups are found, 1 otherwise.</p>
+ * <pre class="eg">
+ * // Query for groups named like <i>com:example</i>
+ * % java com.devclue.grouper.group.GroupQ com:example
+ *
+ * // Query for groups named like <i>com:example</i> and
+ * // <i>org:example</i>
+ * % java com.devclue.grouper.group.GroupQ com:example org:example
+ * </pre>
+ */
+ public static void main(String[] args) {
+ int ev = 0;
+ GroupQ gq = new GroupQ();
+ Iterator iter = Arrays.asList(args).iterator();
+ while (iter.hasNext()) {
+ String name = (String) iter.next();
+ Set groups = gq.getGroups(name);
+ if (groups.size() > 0) {
+ Iterator groupIter = groups.iterator();
+ while (groupIter.hasNext()) {
+ Group g = (Group) groupIter.next();
+ System.out.println(
+ g.getUuid() + "," + g.getName() + "," + g.getDisplayName()
+ );
+ }
+ }
+ else {
+ System.err.println("Group not found: " + name);
+ ev = 1;
+ }
+ }
+ System.exit(ev);
+ } // public static void main(args)
+
+
+ /*
+ * PUBLIC INSTANCE METHODS
+ */
+
+ /**
+ * Perform fuzzy query for groups by <i>name</i> and <i>displayName</i>.
+ * <pre class="eg">
+ * // Query for a groups named like <i>com:example</i>
+ * GroupQ gq = new GroupQ();
+ * Set groups = gq.getGroups("com:example");
+ * </pre>
+ * @param name Name to query on.
+ * @return Set of found groups.
+ */
+ // DESIGN Should I make this exact? Or maybe just add a getGroup()
+ // method?
+ public Set getGroups(String name) {
+ try {
+ GrouperSession s = SessionFactory.getSession();
+ Stem root = StemFinder.findRootStem(s);
+ GrouperQuery gq = GrouperQuery.createQuery(
+ s,
+ new GroupNameFilter(name, root)
+ );
+ return gq.getGroups();
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ } // public Set getGroups(name)
+
+}
+

Reply all
Reply to author
Forward
0 new messages