All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.molgenis.python.PythonScriptRunner Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
package org.molgenis.python;

import static java.util.Objects.requireNonNull;

import java.util.Map;
import org.molgenis.script.core.Script;
import org.molgenis.script.core.ScriptRunner;
import org.molgenis.script.core.ScriptUtils;
import org.springframework.stereotype.Service;

@Service
public class PythonScriptRunner implements ScriptRunner {
  private static final String NAME = "python";

  private final PythonScriptExecutor pythonScriptExecutor;

  public PythonScriptRunner(PythonScriptExecutor pythonScriptExecutor) {
    this.pythonScriptExecutor = requireNonNull(pythonScriptExecutor);
  }

  @Override
  public String getName() {
    return NAME;
  }

  @Override
  public String runScript(Script script, Map parameters) {
    String generatedScript = ScriptUtils.generateScript(script, parameters);
    StringPythonOutputHandler handler = new StringPythonOutputHandler();
    pythonScriptExecutor.executeScript(generatedScript, handler);
    return handler.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy