Details
-
Improvement
-
Resolution: Fixed
-
Minor
-
None
-
None
-
None
Description
Scripts that run in Grouper (not in GSH) should use bind variables and reduce the number of compiled scripts. Example from custom UI
The bind variables passed in to the GrouperGroovyInput will be available in the grouperGroovyRuntime object
FROM:
script.append("grouperSession = GrouperSession.startRootSession();\n"); |
|
|
script.append("subject = SubjectFinder.findByIdAndSource(\"").append(StringUtils.replace((String)subject.getId(), "\"", "\\\"")) |
.append("\", \"").append(StringUtils.replace((String)subject.getSourceId(), "\"", "\\\"")).append("\", true);\n"); |
|
script.append("subjectLoggedIn = SubjectFinder.findByIdAndSource(\"").append(StringUtils.replace((String)subjectLoggedIn.getId(), "\"", "\\\"")) |
.append("\", \"").append(StringUtils.replace((String)subjectLoggedIn.getSourceId(), "\"", "\\\"")).append("\", true);\n"); |
|
script.append("group = GroupFinder.findByUuid(grouperSession, \"").append(StringUtils.replace(group.getId(), "\"", "\\\"")) |
.append("\", true);\n"); |
|
|
script.append(scriptPart);
|
return GrouperUtil.gshRunScript(script.toString(), true); |
|
To
GrouperGroovyInput grouperGroovyInput = new GrouperGroovyInput(); |
grouperGroovyInput.assignInputValueObject("subject", subject); |
script.append("Subject subject = (Subject)grouperGroovyRuntime.retrieveInputValueObject(\"subject\");\n"); |
grouperGroovyInput.assignInputValueObject("subjectLoggedIn", subjectLoggedIn); |
script.append("Subject subjectLoggedIn = (Subject)grouperGroovyRuntime.retrieveInputValueObject(\"subjectLoggedIn\");\n"); |
grouperGroovyInput.assignInputValueObject("group", group); |
script.append("Group group = (Group)grouperGroovyRuntime.retrieveInputValueObject(\"group\");\n"); |
|
script.append(scriptPart);
|
grouperGroovyInput.assignScript(script.toString());
|
GrouperGroovyResult grouperGroovyResult = new GrouperGroovyResult(); |
GrouperGroovysh.runScript(grouperGroovyInput, grouperGroovyResult);
|
return grouperGroovyResult.fullOutput(); |
|
|