Java Code Examples for org.neo4j.driver.v1.types.Node#id()

The following examples show how to use org.neo4j.driver.v1.types.Node#id() . 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: RelationshipProcedureTest.java    From neo4j-versioner-core with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateTheRelationshipAndTheNewCurrentStateBetweenEntities() throws Throwable {

    try (Driver driver = GraphDatabase
            .driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) {

        // Given
        Node entityA = initEntity(session);
        Node entityB = initEntity(session);
        String testType = "testType";

        // When
        String query = "MATCH (a:Entity), (b:Entity) WHERE id(a) = %d AND id(b) = %d WITH a, b CALL graph.versioner.relationship.create(a, b, '%s') YIELD relationship RETURN relationship";
        Relationship relationship = session.run(String.format(query, entityA.id(), entityB.id(), testType)).single().get("relationship").asRelationship();

        // Then
        String querySourceCurrent = "MATCH (e:Entity)-[:CURRENT]-(s:State) WHERE id(e) = %d RETURN s";
        String queryDestinationR = "MATCH (e:Entity)<-[:FOR]-(r:R) WHERE id(e) = %d RETURN r";
        Node sourceCurrent = session.run(String.format(querySourceCurrent, entityA.id())).single().get("s").asNode();
        Node destinationR = session.run(String.format(queryDestinationR, entityB.id())).single().get("r").asNode();
        Relationship expected = new InternalRelationship(0L, sourceCurrent.id(), destinationR.id(), testType);

        assertThat(relationship).isEqualToIgnoringGivenFields(expected, "id");
    }
}
 
Example 2
Source File: BoltContentHandler.java    From jcypher with Apache License 2.0 6 votes vote down vote up
private Entity getPropertiesObject(long id, int rowIndex, ElemType typ) {
	Record rec = this.records.get(rowIndex);
	List<Pair<String, Value>> flds = rec.fields();
	for (Pair<String, Value> pair : flds) {
		if (typ == ElemType.NODE && pair.value() instanceof NodeValue) {
			Node nd = pair.value().asNode();
			if (nd.id() == id)
				return nd;
		} else if (typ == ElemType.RELATION && pair.value() instanceof RelationshipValue) {
			Relationship rel = pair.value().asRelationship();
			if (rel.id() == id)
				return rel;
		}
	}
	
	// element with id may not have been loaded
	return this.reloaded.getEntity(id, typ);
}
 
Example 3
Source File: Neo4jConversionUtils.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public static org.apache.zeppelin.tabledata.Node toZeppelinNode(Node n,
    Map<String, String> graphLabels) {
  Set<String> labels = new LinkedHashSet<>();
  String firstLabel = null;
  for (String label : n.labels()) {
    if (firstLabel == null) {
      firstLabel = label;
    }
    labels.add(label);
  }
  return new org.apache.zeppelin.tabledata.Node(n.id(), n.asMap(),
      labels);
}
 
Example 4
Source File: InsightsGraphDBHandler.java    From Insights with Apache License 2.0 4 votes vote down vote up
private List<InsightsGraphNode> getNodes(StatementResult result){
	List<InsightsGraphNode> insightNodes = new ArrayList<>();
	
	while(result.hasNext()) {
		Record record = result.next();
		Iterable<String> keys = record.keys();
		log.debug(keys);
		Iterator<String> keyItr = keys.iterator();
		Node node =  null;
		Relationship relation = null;
		InsightsGraphNode graphNode = new InsightsGraphNode();
		InsightsRelationShip nodeRelationShip = null;
		while(keyItr.hasNext()) {
			String key = keyItr.next();
			Object o = record.get(key);
			if(o instanceof NodeValue) {
				node = ((NodeValue)o).asNode();
				graphNode = new InsightsGraphNode();
				
				Iterable<String> nodeLabel = node.labels(); //.iterator()
				List<String> labelList =(List<String>) StreamSupport
						.stream(nodeLabel.spliterator(), false)
						.collect(Collectors.toList());
				
				log.debug(" labelList ==== "+labelList.toString()); 				
				graphNode.setLabels(labelList);
				graphNode.setPropertyMap(node.asMap());
				
				if(relation != null && node.id() == relation.startNodeId()) {
					graphNode.setRelation(nodeRelationShip);
					if(node != null && node.id() == relation.startNodeId()) {
						if(graphNode != null) {
							graphNode.setRelation(nodeRelationShip);
						}
						nodeRelationShip.setStartNode(graphNode);
					} else if (node != null && node.id() == relation.endNodeId()) {
						if(graphNode != null) {
							graphNode.setRelation(nodeRelationShip);
						}
						nodeRelationShip.setEndNode(graphNode);
					}
				}
				
			} else if (o instanceof RelationshipValue) {
				relation = ((RelationshipValue)o).asRelationship();
				
				nodeRelationShip = new InsightsRelationShip();
				nodeRelationShip.setPropertyMap(relation.asMap());
				nodeRelationShip.setName(relation.type());
				
				if(node != null && node.id() == relation.startNodeId()) {
					if(graphNode != null) {
						graphNode.setRelation(nodeRelationShip);
					}
					nodeRelationShip.setStartNode(graphNode);
				} else if (node != null && node.id() == relation.endNodeId()) {
					if(graphNode != null) {
						graphNode.setRelation(nodeRelationShip);
					}
					nodeRelationShip.setEndNode(graphNode);
				}
			}
			
		}
	}
	
	return insightNodes;
}