org.neo4j.driver.internal.value.NodeValue Java Examples

The following examples show how to use org.neo4j.driver.internal.value.NodeValue. 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: Neo4jBoltPersistReader.java    From streams with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public ObjectNode apply(@Nullable Value value) {
  ObjectNode resultNode = null;
  if (value instanceof StringValue) {
    StringValue stringValue = (StringValue) value;
    String string = stringValue.asLiteralString();
    try {
      resultNode = mapper.readValue(string, ObjectNode.class);
    } catch (IOException ex) {
      LOGGER.error("IOException", ex);
    }
  } else if ( value instanceof NodeValue) {
    NodeValue nodeValue = (NodeValue) value;
    Node node = nodeValue.asNode();
    Map<String, Object> nodeMap = node.asMap();
    resultNode = PropertyUtil.getInstance(mapper).unflattenMap(nodeMap);
  } else if (value instanceof RelationshipValue) {
    RelationshipValue relationshipValue = (RelationshipValue) value;
    Relationship relationship = relationshipValue.asRelationship();
    Map<String, Object> relationshipMap = relationship.asMap();
    resultNode = PropertyUtil.getInstance(mapper).unflattenMap(relationshipMap);
  }
  return resultNode;
}
 
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: 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;
}