use of de.ipbhalle.exception.CouldNotWriteStatusException in project MetFragRelaunched by ipb-halle.
the class MetFragRestController method process.
/**
* runs a metfrag query
*
* @param args
* @return
* @throws CouldNotWriteStatusException
* @throws CouldNotCreateProcessException
*/
@RequestMapping(method = RequestMethod.POST, value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public ResponseEntity<Resource<ProcessAssembler>> process(@RequestBody ProcessArguments args) throws CouldNotWriteStatusException, CouldNotCreateProcessException {
File resFolder;
String processid;
try {
resFolder = Files.createTempDirectory("java.io.tmpdir").toFile();
processid = resFolder.getName();
try {
MetFragGlobalSettings settings = args.getSettingsObject(resFolder);
// check settings
SettingsChecker settingsChecker = new SettingsChecker();
if (!settingsChecker.check(settings))
throw new CouldNotCreateProcessException("Error: Corrupt parameters");
logger.info("Storing in " + settings.get(VariableNames.STORE_RESULTS_PATH_NAME));
CombinedMetFragProcess mp = new CombinedMetFragProcess(settings);
this.writeStatus("RUNNING", processid);
this.writeHost(processid);
new Thread(() -> {
System.out.println("staring run");
try {
MetFragRestService.startMetFrag(mp, settings, resFolder.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
return;
}
}, "MyThread-" + processid).start();
} catch (ParameterNotKnownException e) {
e.printStackTrace();
this.writeStatus("ERROR", processid);
throw new CouldNotCreateProcessException("Error: Parameter not known");
} catch (IOException e) {
e.printStackTrace();
throw new CouldNotCreateProcessException("Error: Could not write status");
} catch (Exception e) {
e.printStackTrace();
this.writeStatus("ERROR", processid);
throw new CouldNotCreateProcessException("Error: Unknown error");
}
} catch (IOException e) {
throw new CouldNotWriteStatusException(e.getMessage());
}
Resource<ProcessAssembler> resource = new ProcessAssembler("process", processid).toResource();
resource.add(linkTo(MetFragRestController.class).slash("process").withSelfRel());
resource.add(linkTo(MetFragRestController.class).slash("status").slash(processid).withRel("status"));
resource.add(linkTo(MetFragRestController.class).slash("host").slash(processid).withRel("host"));
resource.add(linkTo(MetFragRestController.class).slash("result").slash(processid).withRel("result"));
resource.add(linkTo(MetFragRestController.class).slash("resultzip").slash(processid).withRel("resultzip"));
return new ResponseEntity<Resource<ProcessAssembler>>(resource, HttpStatus.CREATED);
}
Aggregations