use of de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException 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);
}
use of de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException in project MetFragRelaunched by ipb-halle.
the class ParameterDataTypes method getParameter.
/*
* function to retrieve parameters
*/
public static Object getParameter(String parameter, String parameterName) throws ParameterNotKnownException {
String type = parameterDatatypes.get(parameterName);
if (type == null)
throw new ParameterNotKnownException("Parameter '" + parameterName + "' not known.");
if (type.equals("Double"))
return Double.parseDouble(parameter);
if (type.equals("Integer"))
return Integer.parseInt(parameter);
if (type.equals("Byte"))
return Byte.parseByte(parameter);
if (type.equals("Boolean"))
return parameter.toLowerCase().equals("true");
if (type.equals("Level"))
return (Level.toLevel(parameter));
if (type.equals("Double[]")) {
String[] tmp = parameter.split(",");
Double[] values = new Double[tmp.length];
for (int i = 0; i < values.length; i++) values[i] = Double.parseDouble(tmp[i]);
return values;
}
if (type.equals("String[]")) {
String[] tmp = parameter.split(",");
for (int i = 0; i < tmp.length; i++) tmp[i] = tmp[i].trim();
return tmp;
}
return parameter;
}
Aggregations