...
The GSH report type can have an output type of either CSV or FILE. For both types, the script will use fields from the available gsh_builtin_gshReportRuntime variable variable to add data to the output. For CSV output, the script will set a header array and a list of data arrays. For FILE output, the script will open a Writer and and write arbitrary data to the character stream.
Variables available to the GSH script
Variable | Java class | Description |
---|---|---|
gsh_builtin_grouperSession | GrouperSession | session the script runs as |
gsh_builtin_ownerStemName | String | owner stem name where template was called |
gsh_builtin_ownerGroupName | String | owner group name where template was called |
gsh_builtin_gshReportRuntime | GshReportRuntime | container to hold important information about the run |
gsh_builtin_gshReportRuntime.getOwnerGroup() | Group | owner group where template was called |
gsh_builtin_gshReportRuntime.getOwnerStem() | Stem | owner stem where template was called |
gsh_builtin_gshReportRuntime.getOwnerGroupName() | String |
same as gsh_builtin_ownerGroupName | |
gsh_builtin_gshReportRuntime.getOwnerStemName() | String |
same as gsh_builtin_ownerStemName | ||
gsh_builtin_gshReportRuntime.getGrouperReportData() | GrouperReportData | container for the output file (FILE) or csv rows (CSV) |
gsh_builtin_gshReportRuntime.getGrouperReportData().getFile() | File | (FILE) file object to be written to |
gsh_builtin_gshReportRuntime.getGrouperReportData().getHeaders() | List<String> | (CSV) column names to appear in csv header row |
gsh_builtin_gshReportRuntime.getGrouperReportData().getData() | List<String[]> | (CSV) rows of data to appear in the csv; not set by default, so must be initialized with at least an empty list |
Example script writing to FILE format
Code Block | ||
---|---|---|
| ||
Group g = GroupFinder.findByName(gsh_builtin_grouperSession, gsh_builtin_ownerGroupName, true)gshReportRuntime.ownerGroup File file = gsh_builtin_gshReportRuntime.grouperReportData.file file.withWriter('utf-8') { writer -> writer << ['Row', 'ID', 'UID', 'Name', 'Email'].join(",") << "\n" g.members.eachWithIndex { it, i -> writer << i+1 << "," writer << it.subject.getAttributeValue('employeenumber') << "," writer << it.subject.getAttributeValue('uid') << "," writer << it.subject.getAttributeValue('cn') << "," writer << it.subject.getAttributeValue('mail') << "\n" } } |
...
Code Block | ||
---|---|---|
| ||
Group g = GroupFinder.findByName(gsh_builtin_grouperSession, gsh_builtin_ownerGroupName, true)gshReportRuntime.ownerGroup GrouperReportData grouperReportData = gsh_builtin_gshReportRuntime.grouperReportData grouperReportData.headers = ['Row', 'ID', 'UID', 'Name', 'Email'] grouperReportData.data = new ArrayList<String[]>() g.members.eachWithIndex { it, i -> String[] row = [ i+1, it.subject.getAttributeValue('employeenumber'), it.subject.getAttributeValue('uid'), it.subject.getAttributeValue('cn'), it.subject.getAttributeValue('mail'), ] grouperReportData.data << row } |
Mock setup of objects for development of a GSH reporting script
...
Code Block | ||
---|---|---|
| ||
import edu.internet2.middleware.grouper.app.reports.GshReportRuntime import edu.internet2.middleware.grouper.app.reports.GrouperReportData def gs = GrouperSession.startRootSessionIfNotStarted().grouperSession def g = GroupFinder.findByName(gs, "test:vpn:vpn_legacy_exceptions", true) GshReportRuntime gshReportRuntime = new GshReportRuntime() gshReportRuntime.ownerGroup = g gshReportRuntime.ownerGroupName = g.name GrouperReportData grouperReportData = new GrouperReportData() gshReportRuntime.grouperReportData = grouperReportData def // (next line is for FILE output only, set to an arbitrary file instead of the autogenerated one) grouperReportData.file = new File('/tmp/legacy_exceptions.csv') grouperReportData.file = file // simulate the built-in variables GrouperSession gsh_builtin_grouperSession = gs GshReportRuntime gsh_builtin_gshReportRuntime = gshReportRuntime String gsh_builtin_ownerStemName = gsh_builtin_gshReportRuntime.ownerStemName String gsh_builtin_ownerGroupName = gsh_builtin_gshReportRuntime.ownerGroupName /** continue from here with reporting script */ |
...