use of org.neo4j.ogm.model.GraphRowModel in project neo4j-ogm by neo4j.
the class JsonGraphRowResponseTest method shouldParseDataInFilterGraphResponseCorrectly.
@Test
public void shouldParseDataInFilterGraphResponseCorrectly() throws IOException {
when(entity.getContent()).thenReturn(filterQueryGraphRowResponse());
try (Response<GraphRowListModel> rsp = new GraphRowsModelResponse(response)) {
GraphRowListModel graphRowListModel = rsp.next();
assertThat(graphRowListModel).isNotNull();
List<GraphRowModel> graphRowModels = graphRowListModel.model();
assertThat(graphRowModels).hasSize(8);
GraphRowModel model = graphRowModels.get(0);
GraphModel graph = model.getGraph();
assertThat(graph.getNodes().iterator().next().getId()).isEqualTo(Long.valueOf(26));
assertThat(graph.getRelationships()).isEmpty();
Object[] rows = model.getRow();
assertThat(rows.length).isEqualTo(2);
Map row1 = (Map) ((List) rows[0]).get(0);
assertThat(row1.get("name")).isEqualTo("GraphAware");
assertThat(rows[1]).isEqualTo(26L);
}
}
use of org.neo4j.ogm.model.GraphRowModel in project neo4j-ogm by neo4j.
the class GraphRowListModelMapper method map.
public <T> Iterable<T> map(Class<T> type, Response<GraphRowListModel> response) {
Set<Long> idsOfResultEntities = new LinkedHashSet<>();
Response<GraphModel> graphResponse = new Response<GraphModel>() {
GraphRowListModel currentIteratedModel;
int currentIndex = 0;
@Override
public GraphModel next() {
if (currentIteratedModel == null) {
currentIteratedModel = response.next();
if (currentIteratedModel == null) {
return null;
}
currentIndex = 0;
}
List<GraphRowModel> listOfRowModels = currentIteratedModel.model();
if (listOfRowModels.size() <= currentIndex) {
currentIteratedModel = null;
return next();
}
GraphRowModel graphRowModel = listOfRowModels.get(currentIndex++);
Set<Long> idsInCurrentRow = Arrays.stream(graphRowModel.getRow()).filter(Number.class::isInstance).map(Number.class::cast).map(Number::longValue).collect(toSet());
idsOfResultEntities.addAll(idsInCurrentRow);
return graphRowModel.getGraph();
}
@Override
public void close() {
response.close();
}
@Override
public String[] columns() {
return response.columns();
}
};
// although it looks like that the `idsOfResultEntities` will stay empty, they won't, trust us.
BiFunction<GraphModel, Long, Boolean> includeModelObject = (graphModel, nativeId) -> idsOfResultEntities.contains(nativeId);
return delegate.map(type, graphResponse, includeModelObject);
}
Aggregations