logger.debug("saving graph '" + graphId + "'");
// extract the storage location for the history
String format = item.getFormat();
DendriteGraphTx tx = graph.buildTransaction().readOnly().start();
try {
try {
String path;
if (format.equalsIgnoreCase("GraphSON")) {
path = new File(git.getRepository().getWorkTree(), graphId + ".json").getPath();
GraphSONWriter.outputGraph(tx, path);
} else if (format.equalsIgnoreCase("GraphML")) {
path = new File(git.getRepository().getWorkTree(), graphId + ".xml").getPath();
GraphMLWriter.outputGraph(tx, path);
} else if (format.equalsIgnoreCase("GML")) {
path = new File(git.getRepository().getWorkTree(), graphId + ".gml").getPath();
GMLWriter.outputGraph(tx, path);
} else {
tx.rollback();
response.put("status", "error");
response.put("msg", "unknown format '" + format + "'");
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
git.add()
.addFilepattern(".")
.call();
git.commit()
.setAuthor(authentication.getName(), "")
.setMessage("commit")
.call();
} finally {
git.close();
}
} catch (IOException e) {
tx.rollback();
response.put("status", "error");
response.put("msg", "exception: " + e.toString());
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}
tx.commit();
response.put("status", "ok");
return new ResponseEntity<>(response, HttpStatus.NO_CONTENT);
}