Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

VariableJava classDescription

gsh_builtin_grouperSession

GrouperSession

session the script runs as

gsh_builtin_ownerStemName

Stringowner stem name where template was called

gsh_builtin_ownerGroupName

Stringowner group name where template was called

gsh_builtin_gshReportRuntime

GshReportRuntimecontainer to hold important information about the run
gsh_builtin_gshReportRuntime.getOwnerGroup()Groupowner group where template was called
gsh_builtin_gshReportRuntime.getOwnerStem()Stemowner stem where template was called
gsh_builtin_gshReportRuntime.getOwnerGroupName()String
owner group name where template was called;
same as gsh_builtin_ownerGroupName
gsh_builtin_gshReportRuntime.getOwnerStemName()String
owner stem name where template was called;
same as gsh_builtin_ownerStemName
gsh_builtin_gshReportRuntime.getGrouperReportData()GrouperReportDatacontainer 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
languagegroovy
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
languagegroovy
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
languagegroovy
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 */

...