org.neo4j.driver.v1.types.Path Java Examples
The following examples show how to use
org.neo4j.driver.v1.types.Path.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoltContentHandler.java From jcypher with Apache License 2.0 | 6 votes |
@Override public PathInfo getPathInfo(String colKey) { PathInfo pathInfo = null; Value val; try { val = this.record.get(colKey); } catch (NoSuchRecordException e) { throw new RuntimeException("no result column: " + colKey); } String typName = val.type().name(); if ("PATH".equals(typName)) { Path p = val.asPath(); long startId = p.start().id(); long endId = p.end().id(); List<Long> relIds = new ArrayList<Long>(); Iterator<Relationship> it = p.relationships().iterator(); while(it.hasNext()) { Relationship rel = it.next(); relIds.add(Long.valueOf(rel.id())); } pathInfo = new PathInfo(startId, endId, relIds, p); } return pathInfo; }
Example #2
Source File: BoltContentHandler.java From jcypher with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public long gePathtNodeIdAt(PathInfo pathInfo, int index) { Object obj = pathInfo.getContentObject(); List<Node> nodes = null; if (obj instanceof List<?>) nodes = (List<Node>) obj; else if (obj instanceof Path) { nodes = new ArrayList<Node>(); Iterator<Node> it = ((Path)obj).nodes().iterator(); while(it.hasNext()) nodes.add(it.next()); pathInfo.setContentObject(nodes); } return nodes.get(index).id(); }
Example #3
Source File: City2City.java From Getaviz with Apache License 2.0 | 5 votes |
private void setBuildingSegmentAttributesPanels(Long segment) { Path path = connector.executeRead( "MATCH p = (parent)-[:CONTAINS]->(s)-[:VISUALIZES]->(e) WHERE ID(s) = " + segment + " RETURN p").next().get( "p").asPath(); Node relatedEntity = path.end(); long parent = path.start().id(); List<Node> childsM = connector.executeRead( "MATCH (s)-[:CONTAINS]->(child)-[r:VISUALIZES]->(e:Method) WHERE ID(s) = " + parent + " AND (e:Field OR e:Method)" + " AND NOT (e)<-[:DECLARES]-(:Enum) RETURN e").stream().map(s -> s.get("e").asNode()).collect(Collectors.toList()); List<Node> childsA = connector.executeRead( "MATCH (s)-[:CONTAINS]->(child)-[r:VISUALIZES]->(e:Field) WHERE ID(s) = " + parent + " AND NOT (e)<-[:DECLARES]-(:Enum) RETURN e").stream().map(s -> s.get("e").asNode()).collect(Collectors.toList()); int areaUnit; if (classElementsMode == ClassElementsModes.ATTRIBUTES_ONLY) { areaUnit = childsM.size(); } else { areaUnit = childsA.size(); } double width; double length; if (areaUnit <= 1) { width = widthMin; length = widthMin; } else { width = widthMin * areaUnit; length = widthMin * areaUnit; } int index = 0; int effectiveLineCount = relatedEntity.get("effectiveLineCount").asInt(0); while (index < panelHeightTresholdNos.length && effectiveLineCount >= panelHeightTresholdNos[index]) { index = index + 1; } double height = panelHeightUnit * (index + 1); connector.executeWrite( cypherSetBuildingSegmentAttributes(segment, width, length, height, CityUtils.setBuildingSegmentColor(relatedEntity))); }
Example #4
Source File: City2City.java From Getaviz with Apache License 2.0 | 5 votes |
private void setBuildingSegmentAttributesBricks(Long segment) { Path path = connector.executeRead( "MATCH p = (parent)-[:CONTAINS]->(s)-[:VISUALIZES]->(e) WHERE ID(s) = " + segment + " RETURN p").next().get( "p").asPath(); Node relatedEntity = path.end(); connector.executeWrite( cypherSetBuildingSegmentAttributes(segment, brickSize, brickSize, brickSize, CityUtils.setBuildingSegmentColor(relatedEntity))); CityUtils.setBuildingSegmentColor(relatedEntity); }
Example #5
Source File: GetTest.java From neo4j-versioner-core with Apache License 2.0 | 5 votes |
@Test public void shouldGetCurrentPathByGivenEntity() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})"); session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)"); Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode(); Node state = session.run("MATCH (s:State) RETURN s").single().get("s").asNode(); // When StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.current.path(e) YIELD path RETURN path"); Path current = result.single().get("path").asPath(); Iterator<Relationship> relsIterator = current.relationships().iterator(); Map<String, Object> rels = new HashMap<>(); while (relsIterator.hasNext()) { Relationship support = relsIterator.next(); rels.put(support.type(), support); } // Then assertThat(current.contains(entity), equalTo(true)); assertThat(rels.containsKey(Utility.CURRENT_TYPE), equalTo(true)); assertThat(current.contains(state), equalTo(true)); } }
Example #6
Source File: GetTest.java From neo4j-versioner-core with Apache License 2.0 | 5 votes |
@Test public void shouldGetAllStateNodesByGivenEntity() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})"); session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)"); session.run("MATCH (e)-[hs:HAS_STATE]->(s) CREATE (e)-[:HAS_STATE {startDate: localdatetime('1988-10-26T00:00:00'), endDate: hs.startDate}]->(:State{key:'oldState'})"); session.run("MATCH (s1:State {key:'oldState'}), (s2:State {key:'initialValue'}) CREATE (s1)<-[:PREVIOUS {date: localdatetime('1988-10-26T00:00:00')}]-(s2) "); Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode(); Node stateNew = session.run("MATCH (s:State {key:'initialValue'}) RETURN s").single().get("s").asNode(); Node stateOld = session.run("MATCH (s:State {key:'oldState'}) RETURN s").single().get("s").asNode(); // When StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.all(e) YIELD path RETURN path"); Path current = result.single().get("path").asPath(); Iterator<Relationship> relsIterator = current.relationships().iterator(); Map<String, Object> rels = new HashMap<>(); while (relsIterator.hasNext()) { Relationship support = relsIterator.next(); rels.put(support.type(), support); } // Then assertThat(current.contains(entity), equalTo(true)); assertThat(current.contains(stateNew), equalTo(true)); assertThat(rels.containsKey(Utility.PREVIOUS_TYPE), equalTo(true)); assertThat(current.contains(stateOld), equalTo(true)); } }
Example #7
Source File: GetTest.java From neo4j-versioner-core with Apache License 2.0 | 5 votes |
@Test public void shouldGetAllStateNodesByGivenEntityWithOnlyOneCurrentState() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given session.run("CREATE (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'})"); session.run("MATCH (e:Entity {key:'immutableValue'})-[:CURRENT {date:localdatetime('1988-10-27T00:00:00')}]->(s:State {key:'initialValue'}) CREATE (e)-[:HAS_STATE {startDate:localdatetime('1988-10-27T00:00:00')}]->(s)"); Node entity = session.run("MATCH (e:Entity) RETURN e").single().get("e").asNode(); Node stateNew = session.run("MATCH (s:State {key:'initialValue'}) RETURN s").single().get("s").asNode(); // When StatementResult result = session.run("MATCH (e:Entity) WITH e CALL graph.versioner.get.all(e) YIELD path RETURN path"); Path current = result.single().get("path").asPath(); Iterator<Relationship> relsIterator = current.relationships().iterator(); Map<String, Object> rels = new HashMap<>(); while (relsIterator.hasNext()) { Relationship support = relsIterator.next(); rels.put(support.type(), support); } // Then assertThat(current.contains(entity), equalTo(true)); assertThat(current.contains(stateNew), equalTo(true)); } }
Example #8
Source File: City2City.java From Getaviz with Apache License 2.0 | 4 votes |
private void setDistrictAttributes(Path districtPath) { String color = PCKG_colors.get(districtPath.length() - 1); connector.executeWrite( String.format("MATCH (n) WHERE ID(n) = %d SET n.height = %f, n.color = '%s'", districtPath.end().id(), heightMin, color)); }