Search in sources :

Example 1 with JythonScript

use of org.apache.airavata.xbaya.jython.script.JythonScript in project airavata by apache.

the class JythonFiler method exportJythonScript.

/**
 * Exports a Jython script to the local file
 */
public void exportJythonScript() {
    Workflow workflow = this.engine.getGUI().getWorkflow();
    JythonScript script = new JythonScript(workflow, this.engine.getConfiguration());
    // Check if there is any errors in the workflow first.
    ArrayList<String> warnings = new ArrayList<String>();
    if (!script.validate(warnings)) {
        StringBuilder buf = new StringBuilder();
        for (String warning : warnings) {
            buf.append("- ");
            buf.append(warning);
            buf.append("\n");
        }
        this.engine.getGUI().getErrorWindow().warning(buf.toString());
        return;
    }
    int returnVal = this.jythonFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = this.jythonFileChooser.getSelectedFile();
        logger.debug(file.getPath());
        // Put ".py" at the end of the file name
        String path = file.getPath();
        if (!path.endsWith(XBayaConstants.JYTHON_SCRIPT_SUFFIX)) {
            file = new File(path + XBayaConstants.JYTHON_SCRIPT_SUFFIX);
        }
        try {
            // Create the script.
            script.create();
            // Write to a file
            IOUtil.writeToFile(script.getJythonString(), file);
        } catch (IOException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
        } catch (GraphException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
        } catch (RuntimeException e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        } catch (Error e) {
            this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
        }
    }
}
Also used : GraphException(org.apache.airavata.workflow.model.graph.GraphException) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.workflow.model.wf.Workflow) IOException(java.io.IOException) JythonScript(org.apache.airavata.xbaya.jython.script.JythonScript) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GraphException (org.apache.airavata.workflow.model.graph.GraphException)1 Workflow (org.apache.airavata.workflow.model.wf.Workflow)1 JythonScript (org.apache.airavata.xbaya.jython.script.JythonScript)1