// yes yes, this probably ought to be a bunch of methods
Properties p = new Properties();
try {
p.loadFromXML(new FileInputStream(new File("commands.xml")));
} catch (InvalidPropertiesFormatException e) {
return new MigrateResult(null, ServiceUtils
.createExceptionErrorReport("Could not load commands.xml",
e));
} catch (FileNotFoundException e) {
return new MigrateResult(null, ServiceUtils
.createExceptionErrorReport("Could not load commands.xml",
e));
} catch (IOException e) {
return new MigrateResult(null, ServiceUtils
.createExceptionErrorReport("Could not load commands.xml",
e));
}
MultiProperties mp = MultiProperties.load(p);
Map<String, String> params = new HashMap<String, String>();
for (Parameter param : parameters) {
params.put(param.getName(), param.getValue());
}
Map<String, String> toolParams = mp.get(params.get("tool-name"));
try {
File inputFile = DigitalObjectUtils.toFile(dob);
File outputFile = File.createTempFile("generic-output", "tmp");
FileUtils.deleteQuietly(outputFile);
String commandString = toolParams.get("path") + File.separator
+ toolParams.get("command");
String argsString = toolParams.get("arguments");
argsString = argsString.replace("$IN", inputFile.getAbsolutePath());
argsString = argsString.replace("$OUT", outputFile
.getAbsolutePath());
List<String> strings = new ArrayList<String>();
strings.add(commandString);
for (String s : argsString.split(" ")) {
strings.add(s);
}
ProcessRunner pr = new ProcessRunner(strings);
pr.run();
FileUtils.deleteQuietly(inputFile);
FileUtils.deleteQuietly(outputFile);
boolean toolError = pr.getReturnCode() == -1;
ServiceReport log;
if (toolError) {
log = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, pr
.getProcessErrorAsString());
} else {
log = new ServiceReport(Type.INFO, Status.SUCCESS, pr
.getProcessOutputAsString());
}
/*
* log.properties = new ArrayList<Property>(); log.properties.add(
* new Property( URI.create("planets:uri"), "name", "value") );
*/
return new MigrateResult(readDestination(outputFile), log);
} catch (IOException e) {
return new MigrateResult(null, ServiceUtils
.createExceptionErrorReport(
"Could not execute command using tool "
+ params.get("tool-name"), e));
}
}