support bind variables for GSH template scripts

XMLWordPrintable

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Minor
    • 2.5.48
    • Affects Version/s: None
    • Component/s: None
    • None

      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();
       
       

            Assignee:
            Chris Hyzer (upenn.edu)
            Reporter:
            Chris Hyzer (upenn.edu)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: