Uploaded image for project: 'Grouper'
  1. Grouper
  2. GRP-3360

support bind variables for GSH template scripts

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.5.48
    • 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();
       
       

      Attachments

        Activity

          People

            chris.hyzer@at.internet2.edu Chris Hyzer (upenn.edu)
            chris.hyzer@at.internet2.edu Chris Hyzer (upenn.edu)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Smart Checklist