String format = item.getFormat();
HttpHeaders headers = new HttpHeaders();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DendriteGraphTx tx = graph.buildTransaction().readOnly().start();
try {
if (format.equalsIgnoreCase("GraphSON")) {
headers.setContentType(new MediaType("application", "vnd.rexster+json"));
headers.set("Content-Disposition", "attachment; filename=\"graph.json\"");
GraphSONWriter.outputGraph(tx, byteArrayOutputStream);
} else if (format.equalsIgnoreCase("GraphML")) {
headers.setContentType(new MediaType("application", "vnd.rexster+xml"));
headers.set("Content-Disposition", "attachment; filename=\"graph.xml\"");
GraphMLWriter.outputGraph(tx, byteArrayOutputStream);
} else if (format.equalsIgnoreCase("GML")) {
headers.setContentType(new MediaType("application", "vnd.rexster+gml"));
headers.set("Content-Disposition", "attachment; filename=\"graph.gml\"");
GMLWriter.outputGraph(tx, byteArrayOutputStream);
} else {
tx.rollback();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
} catch (IOException e) {
tx.rollback();
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
tx.commit();
return new ResponseEntity<>(byteArrayOutputStream.toByteArray(), headers, HttpStatus.OK);
}