Search in sources :

Example 1 with ParameterNotKnownException

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);
}
Also used : CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) IOException(java.io.IOException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotReadStatusException(de.ipbhalle.exception.CouldNotReadStatusException) CouldNotFetchResultsException(de.ipbhalle.exception.CouldNotFetchResultsException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CouldNotRemoveProcessException(de.ipbhalle.exception.CouldNotRemoveProcessException) ExecutionException(java.util.concurrent.ExecutionException) CouldNotReadHostException(de.ipbhalle.exception.CouldNotReadHostException) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) ResponseEntity(org.springframework.http.ResponseEntity) SettingsChecker(de.ipbhalle.metfraglib.parameter.SettingsChecker) File(java.io.File) ProcessAssembler(de.ipbhalle.model.ProcessAssembler) CombinedMetFragProcess(de.ipbhalle.metfraglib.process.CombinedMetFragProcess) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ParameterNotKnownException

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;
}
Also used : ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException)

Aggregations

ParameterNotKnownException (de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException)2 CouldNotCreateProcessException (de.ipbhalle.exception.CouldNotCreateProcessException)1 CouldNotFetchResultsException (de.ipbhalle.exception.CouldNotFetchResultsException)1 CouldNotReadHostException (de.ipbhalle.exception.CouldNotReadHostException)1 CouldNotReadStatusException (de.ipbhalle.exception.CouldNotReadStatusException)1 CouldNotRemoveProcessException (de.ipbhalle.exception.CouldNotRemoveProcessException)1 CouldNotWriteStatusException (de.ipbhalle.exception.CouldNotWriteStatusException)1 SettingsChecker (de.ipbhalle.metfraglib.parameter.SettingsChecker)1 CombinedMetFragProcess (de.ipbhalle.metfraglib.process.CombinedMetFragProcess)1 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)1 ProcessAssembler (de.ipbhalle.model.ProcessAssembler)1 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1