public static SubGraph from( Result result, GraphDatabaseService gds, boolean addBetween ) final CypherResultSubGraph graph = new CypherResultSubGraph(); final List<String> columns = result.columns(); for ( Map<String, Object> row : loop( result ) ) graph.addToGraph( value ); if ( graph.getLabels().contains( label ) ) graph.addIndex( def ); break; if ( graph.getLabels().contains( def.getLabel() ) ) graph.addConstraint( def ); graph.addRelationshipsBetweenNodes();
public void add( Node node ) { final long id = node.getId(); if ( !nodes.containsKey( id ) ) { addNode( id, node ); } }
private void addToGraph( Object value ) { if ( value instanceof Node ) { add( (Node) value ); } if ( value instanceof Relationship ) { add( (Relationship) value ); } if ( value instanceof Iterable ) { for ( Object inner : (Iterable) value ) { addToGraph( inner ); } } }
@Test public void testSingleNode() { Node n = gdb.createNode(); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
private void addRelationshipsBetweenNodes() { Set<Node> newNodes = new HashSet<>(); for ( Node node : nodes.values() ) { for ( Relationship relationship : node.getRelationships() ) { if ( !relationships.containsKey( relationship.getId() ) ) { continue; } final Node other = relationship.getOtherNode( node ); if ( nodes.containsKey( other.getId() ) || newNodes.contains( other ) ) { continue; } newNodes.add( other ); } } for ( Node node : newNodes ) { add( node ); } }
@Test public void testFromSimpleCypherResult() { Node n = gdb.createNode(); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
private void addToGraph( Object value ) { if ( value instanceof Node ) { add( (Node) value ); } if ( value instanceof Relationship ) { add( (Relationship) value ); } if ( value instanceof Iterable ) { for ( Object inner : (Iterable) value ) { addToGraph( inner ); } } }
private void addRelationshipsBetweenNodes() { Set<Node> newNodes = new HashSet<>(); for ( Node node : nodes.values() ) { for ( Relationship relationship : node.getRelationships() ) { if ( !relationships.containsKey( relationship.getId() ) ) { continue; } final Node other = relationship.getOtherNode( node ); if ( nodes.containsKey( other.getId() ) || newNodes.contains( other ) ) { continue; } newNodes.add( other ); } } for ( Node node : newNodes ) { add( node ); } }
@Test public void testFromRelCypherResult() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL`]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
public static SubGraph from( Result result, GraphDatabaseService gds, boolean addBetween ) final CypherResultSubGraph graph = new CypherResultSubGraph(); final List<String> columns = result.columns(); for ( Map<String, Object> row : loop( result ) ) graph.addToGraph( value ); if ( graph.getLabels().contains( label ) ) graph.addIndex( def ); break; if ( graph.getLabels().contains( def.getLabel() ) ) graph.addConstraint( def ); graph.addRelationshipsBetweenNodes();
public void add( Node node ) { final long id = node.getId(); if ( !nodes.containsKey( id ) ) { addNode( id, node ); } }
@Test public void testEscapingOfRelationshipStringPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", "Brutus \"Brutal\" Howell" ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:\"Brutus \\\"Brutal\\\" Howell\"}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingStringPropertyWithBackslash() { Node n = gdb.createNode(); n.setProperty( "name", "Some\\thing" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Some\\\\thing\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfRelationshipStringArrayPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", new String[]{"Brutus \"Brutal\" Howell", "Dr."} ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:[\"Brutus \\\"Brutal\\\" Howell\", \"Dr.\"]}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfNodeStringPropertyValue() { Node n = gdb.createNode(); n.setProperty( "name", "Brutus \"Brutal\" Howell" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Brutus \\\"Brutal\\\" Howell\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfNodeStringArrayPropertyValue() { Node n = gdb.createNode(); n.setProperty( "name", new String[]{"Brutus \"Brutal\" Howell", "Dr."} ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:[\"Brutus \\\"Brutal\\\" Howell\", \"Dr.\"]})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingStringPropertyWithBackslashAndDoubleQuote() { Node n = gdb.createNode(); n.setProperty( "name", "Some\\\"thing" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Some\\\\\\\"thing\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testFromPathCypherResult() { Node n1 = gdb.createNode(); Node n2 = gdb.createNode(); final Relationship rel = n1.createRelationshipTo( n2, RelationshipType.withName( "REL" ) ); final Path path = new PathImpl.Builder( n1 ).push( rel ).build(); final ExecutionResult result = result( "path", path ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_1)" + lineSeparator() + "create (_0)-[:`REL`]->(_1)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }