public GroovyResult execute(final String script, final Map<String, Object> variables) { if (script == null) { return new GroovyResult(); } final Script groovyObject = compileGroovy(script, true); if (groovyObject == null) { return new GroovyResult(); } return execute(groovyObject, variables); }
public GroovyResult execute(GroovyResult result, final Script groovyScript, final Map<String, Object> variables) { if (variables != null) { final Binding binding = groovyScript.getBinding(); for (final Map.Entry<String, Object> entry : variables.entrySet()) { binding.setVariable(entry.getKey(), entry.getValue()); } } if (result == null) { result = new GroovyResult(); } Object res = null; try { res = groovyScript.run(); } catch (final Exception ex) { log.info("Groovy-Execution-Exception: " + ex.getMessage(), ex); return new GroovyResult(ex); } result.setResult(res); return result; }
public GroovyResult execute(final ScriptDO script, final List<ScriptParameter> parameters) { hasLoggedInUserSelectAccess(script, true); final ReportGeneratorList reportGeneratorList = new ReportGeneratorList(); final Map<String, Object> scriptVariables = new HashMap<String, Object>(); addScriptVariables(scriptVariables); scriptVariables.put("reportList", reportGeneratorList); if (parameters != null) { for (final ScriptParameter param : parameters) { scriptVariables.put(param.getParameterName(), param.getValue()); } } if (script.getFile() != null) { final Map<String, Object> scriptVars = new HashMap<String, Object>(); scriptVariables.put("script", scriptVars); scriptVars.put("file", script.getFile()); scriptVars.put("filename", script.getFilename()); } scriptVariables.put("i18n", new I18n()); String scriptContent = script.getScriptAsString(); if (scriptContent.contains("import org.projectforge.export")) { // Package was renamed in version 5.2 and 6.13: scriptContent = scriptContent.replace("import org.projectforge.export", "import org.projectforge.export.*\nimport org.projectforge.business.excel"); } groovyResult = groovyExecutor.execute(new GroovyResult(), scriptContent, scriptVariables); return groovyResult; }
final GroovyResult scriptResult = new GroovyResult(); binding.setVariable("scriptResult", scriptResult);
scriptVariables.put("reportList", reportGeneratorList); if (StringUtils.isNotBlank(getReportScriptingStorage().getGroovyScript()) == true) { groovyResult = groovyExecutor.execute(new GroovyResult(), getReportScriptingStorage().getGroovyScript(), scriptVariables); if (groovyResult.hasException() == true) {