Run a script with parameters.

@param scriptName name of the script to run
@param parameters parameters for the script
@return ScriptResult
@throws UnknownScriptException if scriptName is unknown
@throws GenerateScriptException , if parameter is missing
503615
public ScriptResult runScript(String scriptName, Map<String, Object> parameters) {
    Script script =
        dataService.query(SCRIPT, Script.class).eq(ScriptMetadata.NAME, scriptName).findOne();
    if (script == null) {
      throw new UnknownEntityException(SCRIPT, scriptName);
    }

    if (script.getParameters() != null) {
      for (ScriptParameter param : script.getParameters()) {
        if (!parameters.containsKey(param.getName())) {
          throw new GenerateScriptException("Missing parameter [" + param + "]");
        }
      }
    }

    Map<String, Object> scriptParameters = new HashMap<>(parameters);
    if (script.isGenerateToken()) {
      String token =
          tokenService.generateAndStoreToken(
              SecurityUtils.getCurrentUsername(), "For script " + script.getName());
      scriptParameters.put("molgenisToken", token);
    }

    ScriptRunner scriptRunner =
        scriptRunnerFactory.getScriptRunner(script.getScriptType().getName());

    FileMeta fileMeta = null;
    if (scriptRunner.hasFileOutput(script)) {
      String name = generateRandomString();
      String resultFileExtension = script.getResultFileExtension();
      if (resultFileExtension != null) {
        name += "." + script.getResultFileExtension();
      }
      File file = fileStore.getFileUnchecked(name);
      scriptParameters.put("outputFile", file.getAbsolutePath());
      fileMeta = createFileMeta(name, file);
      dataService.add(FILE_META, fileMeta);
    }
    String output = scriptRunner.runScript(script, scriptParameters);

    return new ScriptResult(fileMeta, output);
  }
953056
public Map runScript(String key, Map<String, Object> paras) throws ScriptEvalError
	{
		return this.runScript(key, paras, null);

	}
421692
public static <T> T executeGroovyShellScript(final String script,
                                                 final Map<String, Object> variables,
                                                 final Class<T> clazz) {
        try {
            val binding = new Binding();
            val shell = new GroovyShell(binding);
            if (variables != null && !variables.isEmpty()) {
                variables.forEach(binding::setVariable);
            }
            if (!binding.hasVariable("logger")) {
                binding.setVariable("logger", LOGGER);
            }
            LOGGER.debug("Executing groovy script [{}] with variables [{}]", script, binding.getVariables());

            val result = shell.evaluate(script);
            return getGroovyScriptExecutionResultOrThrow(clazz, result);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }
1002211
public static <T> ParameterBuilder<T> create(String name) {
    return new ParameterBuilder<T>()
        .name(name);
  }
326449
@Override
	public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
		return ((Invocable) scriptEngine).invokeFunction(name, args);
	}
518008
public Script getScriptSig() throws ScriptException {
        // Transactions that generate new coins don't actually have a script. Instead this
        // parameter is overloaded to be something totally different.
        Script script = scriptSig == null ? null : scriptSig.get();
        if (script == null) {
            script = new Script(scriptBytes);
            scriptSig = new WeakReference<>(script);
        }
        return script;
    }
859364
public static <T> T executeGroovyScriptEngine(final String script,
                                                  final Map<String, Object> variables,
                                                  final Class<T> clazz) {
        try {
            val engine = new ScriptEngineManager().getEngineByName("groovy");
            if (engine == null) {
                LOGGER.warn("Script engine is not available for Groovy");
                return null;
            }
            val binding = new SimpleBindings();
            if (variables != null && !variables.isEmpty()) {
                binding.putAll(variables);
            }
            if (!binding.containsKey("logger")) {
                binding.put("logger", LOGGER);
            }
            val result = engine.eval(script, binding);
            return getGroovyScriptExecutionResultOrThrow(clazz, result);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }
807614
public void runScript(String configFileName) 
	{
		int lineNum = 0;
		try {
	    BufferedReader in = new BufferedReader(new FileReader(configFileName));
	    String line;
	    while ((line = in.readLine())!=null) {
				lineNum++;
				if (!line.startsWith("#")) {
					String command = null;
					List args = new ArrayList();
					StringTokenizer tok = new StringTokenizer(line);
					if (tok.hasMoreTokens()) {
						command = tok.nextToken();
					}
					while (tok.hasMoreTokens()) {
						args.add( tok.nextToken() );
					}
					if (command!=null) {
						if (echoCommands) System.out.println("exec: "+line);
						execCommand(command,args);
					}
				}
			}
		} catch (Exception e) {
			System.out.println("Error: "+configFileName+" line "+lineNum+": "+e.toString());
			e.printStackTrace();
			return;
		}
	}
1188915
@RequestMapping(value = "/api/scripts", method = RequestMethod.GET)
    public
    @ResponseBody
    HashMap<String, Object> getScripts(Model model,
                                       @RequestParam(required = false) Integer type) throws Exception {
        Script[] scripts = ScriptService.getInstance().getScripts(type);
        return Utils.getJQGridJSON(scripts, "scripts");
    }
1324786
function executeCommand(parameters) {
    if (parameters.colors === undefined) {
      parameters.colors = plugin.myrmex.getConfig('colors');
    }
    return plugin.findApi(parameters.apiIdentifier)
    .then(api => {
      return api.generateSpec(parameters.specVersion);
    })
    .then(jsonSpec => {
      let spec = JSON.stringify(jsonSpec, null, 2);
      if (parameters.colors) {
        spec = icli.highlight(spec, { json: true });
      }
      icli.print(spec);
      return Promise.resolve(jsonSpec);
    });
  }
1259553
Object executeScript(String jsScript, Map<String, Object> parameters) {
    EntityType entityType = entityTypeFactory.create("entity");
    Set<String> attributeNames = parameters.keySet();
    attributeNames.forEach(key -> entityType.addAttribute(attributeFactory.create().setName(key)));
    if (attributeNames.iterator().hasNext()) {
      entityType.getAttribute(attributeNames.iterator().next()).setIdAttribute(true);
    }
    Entity entity = new DynamicEntity(entityType);
    parameters.forEach(entity::set);
    return jsMagmaScriptEvaluator.eval(jsScript, entity);
  }
731874
public void addJavaScriptValues(Map<String, String> parameterMap) {
        for (Map.Entry<String, String> entry : parameterMap.entrySet()) {
            String parameterName = entry.getKey();
            String parameterValue = entry.getValue();
            this.javascriptExpressions.put(parameterName, parameterValue);
        }
    }
552277
@RequestMapping(value = "/api/scripts/{scriptIdentifier}", method = RequestMethod.POST)
    public
    @ResponseBody
    Script updateScript(Model model, @PathVariable String scriptIdentifier,
                        @RequestParam(required = false) String name,
                        @RequestParam(required = false) String script) throws Exception {
        int scriptId = Integer.parseInt(scriptIdentifier);

        if (name != null) {
            ScriptService.getInstance().updateName(scriptId, name);
        }

        if (script != null) {
            ScriptService.getInstance().updateScript(scriptId, script);
        }

        return ScriptService.getInstance().getScript(scriptId);
    }
340544
@Override
	public Parameter getParam(final String paramName) {
		Parameter param = getBindParameter(paramName);
		if (param == null) {
			Map<String, Parameter> constParams = getConstParameterMap();
			if (constParams != null) {
				param = constParams.get(paramName.toUpperCase());
			}
		}
		return param;
	}
496621
@Override
    public List<FixtureResult> runFixtureScript(
            final FixtureScript fixtureScript,
            @Parameter(optionality = Optionality.OPTIONAL)
            @ParameterLayout(
                named = "Parameters",
                describedAs = "Script-specific parameters (if any).  The format depends on the script implementation (eg key=value, CSV, JSON, XML etc)",
                multiLine = 10
            )
            final String parameters) {
        return super.runFixtureScript(fixtureScript, parameters);
    }
347371
@BeforeSuite(alwaysRun=true)
	@Parameters(value={"parameters"})
	public static void startSelenium(String parameters)
	{
		parametersMap = parameterScanner(parameters);
		
		parametersInfo();
		
		String 	browserName = parametersMap.get("browser"),
				profile = parametersMap.get("profile"),
				chromeDriverBin = parametersMap.get("chromeDriverBin"),
				ieDriverBin = parametersMap.get("ieDriverBin"),
				chromeBin = parametersMap.get("chromeBin"),
				languages = parametersMap.get("languages");
				
		if(browserName == null){
			throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"browser"));
		}
		
		if(driver == null) {
			if(BrowsersList.FIREFOX.equalsString(browserName)){
				FirefoxProfile fp = new FirefoxProfile();
				fp.setPreference("dom.max_script_run_time", 0);
				fp.setPreference("dom.max_chrome_script_run_time", 0);
				if(profile != null && !profile.isEmpty()){
					fp.setPreference("webdriver.firefox.profile", profile);
				}
				if(languages != null && !languages.isEmpty()){
					fp.setPreference("intl.accept_languages", languages);
				}
				driver = new WebDriverAdapter(new FirefoxDriver(fp));
			}
			else if(BrowsersList.CHROME.equalsString(browserName)) {
				
				if(chromeBin == null){
					throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"chromeBin"));
				}
				
				
				// Optional, if not specified, WebDriver will search your path for chromedriver 
				// in the system environment. (OBS: To evade problems, webdriver.chrome.driver MUST have a value.
				if(System.getProperty("webdriver.chrome.driver") == null || System.getProperty("webdriver.chrome.driver").isEmpty()){
					if(chromeDriverBin == null){
						throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"chromeDriverBin"));
					}
					System.setProperty("webdriver.chrome.driver", chromeDriverBin);	
				}
				
				ChromeOptions co = new ChromeOptions();
				// Get the chrome binary directory path from System Envionment.
				co.setBinary(new File(chromeBin));
				driver = new WebDriverAdapter(new ChromeDriver(co));
			}
			else if(BrowsersList.IE.equalsString(browserName))
			{
				if(ieDriverBin == null){
						throw new IllegalArgumentException(String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL,"ieDriverBin"));
				}
				System.setProperty("webdriver.ie.driver", ieDriverBin);	
				driver = new WebDriverAdapter(new InternetExplorerDriver());
			}
			else if(BrowsersList.HTML_UNIT.equalsString(browserName)){
				driver = new HtmlUnitDriver(true);
			}
			else {
				throw new IllegalArgumentException(ErrorMessages.ERROR_BROWSER_INVALID);
			}
		}
		/* Sets to all driver methods the global timeout of 1 second. 
		 * To tests, Timeouts must be specified on the components.
		 */
		SeleniumController.driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
		SeleniumController.builder = new SeleniumBuilder(driver);
		SeleniumController.browser = new SeleniumBrowser();
		ListenerGateway.setWebDriver(driver);
		ListenerGateway.setParameters(parametersMap);
	}
1340988
private void executeScript(String script) {
        try {
            final StatementSplitter statementSplitter =
                new StatementSplitterResolver(scriptConfigurationInstance.get()).resolve();
            final ScriptExecutor scriptExecutor =
                new ScriptExecutor(databaseConnection.get().getConnection(), scriptConfigurationInstance.get(),
                    statementSplitter);
            scriptExecutor.execute(script);
        } catch (SQLException e) {
            throw new DBUnitConnectionException("Unable to execute script.", e);
        }
    }