Skip to Content.
Sympa Menu

grouper-users - [grouper-users] RE: Using Grouper API in a maven project

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] RE: Using Grouper API in a maven project


Chronological Thread 
  • From: "Hyzer, Chris" <>
  • To: "Nakandala, Supun Chathuranga" <>
  • Cc: "" <>
  • Subject: [grouper-users] RE: Using Grouper API in a maven project
  • Date: Fri, 17 Jun 2016 13:26:07 +0000
  • Accept-language: en-US
  • Authentication-results: spf=none (sender IP is ) ;
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

I think you need a grouper session before you find a subject...

Also, I would take out all the exception handling... if you want to catch an
exception, catch Exception, unless there is something specific you are
looking for

try this:



GrouperSession s = GrouperSession.startRootSession();

//generally this goes in a finally block
GrouperSession.stopQuietly(s);

s = GrouperSession.startRootSession();

Subject subj = SubjectFinder.findById("GrouperSystem", false);

//Find the root stem
//you should always close your sessions, also, the are in a threadlocal
if already started
//Stem root =
StemFinder.findRootStem(GrouperSession.start(SubjectFinder.findRootSubject()));

Stem root =
StemFinder.findRootStem(GrouperSession.staticGrouperSession());

//Create top level stem, I would use the Save API
// Stem etc = root.addChildStem("etc", "Grouper Administration");

Stem etc = new
StemSave(s).assignName("etc").assignCreateParentStemsIfNotExist(true).save();

//Create child group, again, I would use the Sae api
// Stem etc = root.addChildStem("etc", "Grouper Administration");
// Group wheel = etc.addChildGroup("wheel", "Wheel Group");

Group wheel = new
GroupSave(s).assignName("etc:wheel").assignCreateParentStemsIfNotExist(true).save();

// the "All" subject is for privileges, it wont have an effect if you add
it to a group, though
// you just might have been doing an example...
// Subject all = SubjectFinder.findAllSubject();
// if ( !wheel.hasMember(all) ) {

wheel.addMember(subj, false);



-----Original Message-----
From: Nakandala, Supun Chathuranga
[mailto:]

Sent: Thursday, June 16, 2016 4:49 PM
To: Hyzer, Chris
<>
Subject: Re: Using Grouper API in a maven project

The code is as follows

---------------------------------------------------------------------------------------------------------------------------------
public static void main(String[] args) {

//Find a subject
try {
Subject subj = SubjectFinder.findById("GrouperSystem");
}
catch (SubjectNotFoundException eSNF) {
// could not find subject
}
catch (SubjectNotUniqueException eSNU) {
// could not uniquely resolve "subject id"
}

//Start-And-Stop a subject
try {
GrouperSession s =
GrouperSession.start(SubjectFinder.findRootSubject());
try {
s.stop();
}
catch (SessionException eS) {
// unable to stop this session
}
}
catch (SessionException eS) {
// unable to start session
}

//Find the root stem
Stem root =
StemFinder.findRootStem(GrouperSession.start(SubjectFinder.findRootSubject()));

//Create top level stem
try {
Stem etc = root.addChildStem("etc", "Grouper Administration");
}
catch (InsufficientPrivilegeException eIP) {
// not privileged to add this stem
}
catch (StemAddException eNSA) {
// error adding this stem
}

//Create child group
try {
Stem etc = root.addChildStem("etc", "Grouper Administration");
Group wheel = etc.addChildGroup("wheel", "Wheel Group");
}
catch (GroupAddException eGA) {
// error adding this group
}
catch (InsufficientPrivilegeException eIP) {
// not privileged to add this group
}


//Add Member To Group If Not Already A Member
Stem etc = root.addChildStem("etc", "Grouper Administration");
Group wheel = etc.addChildGroup("wheel", "Wheel Group");
Subject all = SubjectFinder.findAllSubject();
if ( !wheel.hasMember(all) ) {
try {
wheel.addMember(all);
}
catch (InsufficientPrivilegeException eIP) {
// not privileged to add this member
}
catch (MemberAddException eMA) {
// error adding this member
}
}
}



> On Jun 16, 2016, at 4:43 PM, Hyzer, Chris
> <>
> wrote:
>
> Send the test code please
>
> From: Nakandala, Supun Chathuranga
> [mailto:]
>
> Sent: Thursday, June 16, 2016 4:36 PM
> To: Hyzer, Chris
> <>
> Subject: Re: Using Grouper API in a maven project
>
> The complete log can be found here http://pastebin.com/raw/4rBg3TUr
>
> No after the exception was thrown the test code stopped.
> On Jun 16, 2016, at 4:27 PM, Hyzer, Chris
> <>
> wrote:
>
> Can you forward the complete stack/logs please? Jar file mismatches (or
> missing) and grouper version mismatches might say error but they should be
> only non-fatal… is there something else going on or is it started
> successfully? J
>
> Thanks
> Chris
>
> From:
>
>
> [mailto:]
> On Behalf Of Nakandala, Supun Chathuranga
> Sent: Thursday, June 16, 2016 3:54 PM
> To:
>
> Subject: [grouper-users] Using Grouper API in a maven project
>
> Hi Devs,
>
> I trying to create a project which directly interacts with the Grouper Java
> API. The project is a maven project and I have added the following
> dependency.
>
> <dependency>
> <groupId>edu.internet2.middleware.grouper</groupId>
> <artifactId>grouper</artifactId>
> <version>2.3.0</version>
> </dependency>
>
> I also copied the files inside the conf directory in the binary
> distribution into resources directory in the project and configured the
> correct database connections in the hibernate properties file. Also using
> the gsh I initialized the database.
>
> But when I tried to run simple example code provided in the API.txt
> document I get the following error
> .
> .
> Grouper warning: cannot find class
> com.thoughtworks.xstream.alias.CannotResolveClassException, perhaps you are
> missing jar: xstream.jar
> Grouper error: grouper versions do not match, GrouperVersion.class: 2.3.0,
> grouper.version.properties: null, manifest: null
> Exception in thread "main" java.lang.NullPointerException
> at
> edu.internet2.middleware.grouper.GrouperSourceAdapter$2.callback(GrouperSourceAdapter.java:317)
> Disconnected from the target VM, address: '127.0.0.1:56978', transport:
> 'socket'
> at
> edu.internet2.middleware.grouper.GrouperSession.callbackGrouperSession(GrouperSession.java:974)
> at
> edu.internet2.middleware.grouper.GrouperSourceAdapter.getSubjectsByIds(GrouperSourceAdapter.java:311)
> at
> edu.internet2.middleware.grouper.GrouperSourceAdapter.getSubject(GrouperSourceAdapter.java:215)
> at
> edu.internet2.middleware.grouper.subj.SourcesXmlResolver$1.callLogic(SourcesXmlResolver.java:119)
> at
> edu.internet2.middleware.grouper.subj.SourcesXmlResolver$1.callLogic(SourcesXmlResolver.java:116)
> at
> edu.internet2.middleware.grouper.subj.SourcesXmlResolver$LogLabelCallable.call(SourcesXmlResolver.java:169)
> at
> edu.internet2.middleware.grouper.subj.SourcesXmlResolver.executeCallables(SourcesXmlResolver.java:230)
> at
> edu.internet2.middleware.grouper.subj.SourcesXmlResolver.find(SourcesXmlResolver.java:125)
> at
> edu.internet2.middleware.grouper.subj.CachingResolver.find(CachingResolver.java:125)
> at
> edu.internet2.middleware.grouper.subj.ValidatingResolver.find(ValidatingResolver.java:91)
> at
> edu.internet2.middleware.grouper.SubjectFinder.findById(SubjectFinder.java:431)
> at
> edu.internet2.middleware.grouper.SubjectFinder.findById(SubjectFinder.java:405)
> at org.apache.airavata.groupmanager.Main.main(Main.java:38)
>
> After Googling for the exception message I found this grouper email thread
> [https://lists.internet2.edu/sympa/arc/grouper-dev/2011-10/msg00069.html]
> which is discussing the same issue. There is an open issue for this
> https://bugs.internet2.edu/jira/browse/GRP-673 and I tried to manually copy
> this file into my project to overcome the issue. But I cannot find the
> misc/version.properties file in the API binary distribution.
>
> Where can I get this file? Or else your help on how to fix this issue is
> highly appreciated.
>
> Thanks
> -Supun




Archive powered by MHonArc 2.6.16.

Top of Page