JsonExport { public void convert(String[] filepaths) throws ReaderException, IOException, WriterException { if (filepaths.length == 0 || filepaths[0].equals("-h")) { System.out.println("Export workflow structore as JSON."); System.out.println("Usage: jsonexport [filename] ..."); System.out.println("If the filename is - the workflow will be read from STDIN and"); System.out.println("JSON written to STDOUT. "); System.out.println("Otherwise, the file is read as a workflow (t2flow, workflow bundle)"); System.out.println("and written as JSON to a file with the .json extension."); System.out.println("Multiple filenames can be given. JSON filenames are written to STDOUT"); return; } if (filepaths[0].equals("-")) { WorkflowBundle wfBundle = io.readBundle(System.in, null); io.writeBundle(wfBundle, System.err, "application/ld+json"); return; } for (String filepath : filepaths) { File workflow = new File(filepath); String filename = workflow.getName(); filename = filename.replaceFirst("\\..*", ".json"); File workflowFile = new File(workflow.getParentFile(), filename); WorkflowBundle wfBundle = io.readBundle(workflow, null); io.writeBundle(wfBundle, workflowFile, "application/ld+json"); System.out.println(workflowFile); } } JsonExport(); static void main(String[] args); void convert(String[] filepaths); ObjectNode toJson(WorkflowBundle wfBundle);  }
@Test public void jsonExportHelloAnyone() throws Exception { File tmp = File.createTempFile("helloanyone", ".t2flow"); tmp.deleteOnExit(); InputStream ebi = getClass().getResourceAsStream("/workflows/t2flow/helloanyone.t2flow"); FileOutputStream output = new FileOutputStream(tmp); IOUtils.copy(ebi, output); output.close(); JsonExport jsonExport = new JsonExport(); jsonExport.convert(new String[]{tmp.getAbsolutePath()}); File jsonFile = new File(tmp.getAbsolutePath().replace(".t2flow", ".json")); assertTrue(jsonFile.isFile()); jsonFile.deleteOnExit(); }
@Ignore("Takes 24 seconds!") @Test public void jsonExportNested() throws Exception { File tmp = File.createTempFile("enm", ".t2flow"); tmp.deleteOnExit(); InputStream ebi = getClass().getResourceAsStream("/workflows/t2flow/generic_enm_workflow_with_interaction_615643.t2flow"); FileOutputStream output = new FileOutputStream(tmp); IOUtils.copy(ebi, output); output.close(); JsonExport jsonExport = new JsonExport(); jsonExport.convert(new String[]{tmp.getAbsolutePath()}); File jsonFile = new File(tmp.getAbsolutePath().replace(".t2flow", ".json")); assertTrue(jsonFile.isFile()); }