*/
public static void inputGraph(final Graph inputGraph, final InputStream inputStream, int bufferSize) throws IOException {
// titan requires creation of vertices before edges
// unless enabling the option to set vertex id upon creation,
// use a map to store the idFaunus->idBlueprints transformation
FaunusEdge fe;
Vertex vertexIn, vertexOut;
long faunusIdIn, faunusIdOut, blueprintsIdIn, blueprintsIdOut;
HashMap<Long, Long> faunusToBlueprintsId = new HashMap<Long, Long>();
// if this is a transactional graph then we're buffering
final BatchGraph graph = BatchGraph.wrap(inputGraph, bufferSize);
// load list of vertices
List<FaunusVertex> faunusVertexList = FaunusGraphSONUtility.fromJSON(inputStream);
// add vertices w/ properties to graph, also saving id->id mapping for edge creation
Vertex blueprintsVertex;
for (FaunusVertex faunusVertex : faunusVertexList) {
blueprintsVertex = graph.addVertex(faunusVertex.getIdAsLong());
for (String property : faunusVertex.getPropertyKeys()) {
blueprintsVertex.setProperty(property, faunusVertex.getProperty(property));
}
faunusToBlueprintsId.put(faunusVertex.getIdAsLong(), (Long) blueprintsVertex.getId());
}
// add edges between vertices
for (FaunusVertex faunusVertex : faunusVertexList) {
for (Edge edge : faunusVertex.getEdges(Direction.BOTH)) {
fe = (FaunusEdge) edge;
// retrieve the vertices stored in the graph
faunusIdIn = fe.getVertexId(Direction.IN);
blueprintsIdIn = faunusToBlueprintsId.get(faunusIdIn);
faunusIdOut = fe.getVertexId(Direction.OUT);
blueprintsIdOut = faunusToBlueprintsId.get(faunusIdOut);
vertexIn = graph.getVertex(blueprintsIdIn);
vertexOut = graph.getVertex(blueprintsIdOut);
// save the edge to the graph
graph.addEdge(null, vertexIn, vertexOut, fe.getLabel());
}
}
// commit changes to the graph
graph.commit();