Skip to content

Commit

Permalink
Change mkdir to mkdirs and check the return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu authored and mathbagu committed Nov 26, 2016
1 parent fda602b commit bc94926
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,28 @@ public void run(CommandLine line) throws Exception {
String workflowId = line.getOptionValue("workflow");
List<Integer> states = line.hasOption("state") ? Arrays.asList(Integer.valueOf(line.getOptionValue("state"))) : onlinedb.listStoredStates(workflowId);
Path folder = Paths.get(line.getOptionValue("folder"));
System.out.println("Exporting in AMPL format network data of workflow " + workflowId +", " + states.size() + " state(s), to folder " + folder);
states.stream().forEach(state -> exportState(onlinedb, workflowId, state, folder));
System.out.println("Exporting in AMPL format network data of workflow " + workflowId + ", " + states.size() + " state(s), to folder " + folder);
states.forEach(state -> exportState(onlinedb, workflowId, state, folder));
onlinedb.close();
}

private void exportState(OnlineDb onlinedb, String workflowId, Integer stateId, Path folder) {
System.out.println("Exporting network data of workflow " + workflowId +", state " + stateId);
Network network = onlinedb.getState(workflowId, stateId);
if ( network == null ) {
if (network == null) {
System.out.println("Cannot export network data: no stored state " + stateId + " for workflow " + workflowId);
return;
}
Path stateFolder = Paths.get(folder.toString(), "wf_" + workflowId + "_state_" + stateId);
System.out.println("Exporting network data of workflow " + workflowId +", state " + stateId + " to folder "+ stateFolder);
if ( stateFolder.toFile().exists() ) {
System.out.println("Cannot export network data of workflow " + workflowId +", state " + stateId + ": folder "+ stateFolder + " already exists");
System.out.println("Exporting network data of workflow " + workflowId + ", state " + stateId + " to folder " + stateFolder);
if (stateFolder.toFile().exists()) {
System.out.println("Cannot export network data of workflow " + workflowId + ", state " + stateId + ": folder " + stateFolder + " already exists");
return;
} else
stateFolder.toFile().mkdir();
}
if (! stateFolder.toFile().mkdirs()) {
System.out.println("Cannot export network data of workflow " + workflowId + ", state " + stateId + ": unable to create " + stateFolder + " folder");
return;
}
DataSource dataSource = new FileDataSource(stateFolder, "wf_" + workflowId + "_state_" + stateId);
Exporters.export("AMPL", network, new Properties(), dataSource);
}
Expand Down

0 comments on commit bc94926

Please sign in to comment.