use of org.neo4j.ogm.response.Response in project neo4j-ogm by neo4j.
the class RestModelMapper method map.
public RestStatisticsModel map(Response<RestModel> response) {
List<ResultRowBuilder> resultRowBuilders = new ArrayList<>();
Response<GraphModel> graphModelResponse = new Response<GraphModel>() {
@Override
public GraphModel next() {
RestModel model = response.next();
if (model == null) {
return null;
}
ResultRowBuilder resultRowBuilder = new ResultRowBuilder(RestModelMapper.this::getEntityOrNodeModel, mappingContext::getRelationshipEntity);
resultRowBuilders.add(resultRowBuilder);
model.getRow().forEach(resultRowBuilder::handle);
return resultRowBuilder.buildGraphModel();
}
@Override
public void close() {
response.close();
}
@Override
public String[] columns() {
return response.columns();
}
};
// Run the actual mapping
delegate.map(Object.class, graphModelResponse);
// Recreate the original structure
RestStatisticsModel restStatisticsModel = new RestStatisticsModel();
response.getStatistics().ifPresent(restStatisticsModel::setStatistics);
restStatisticsModel.setResult(resultRowBuilders.stream().map(ResultRowBuilder::finish).collect(Collectors.toList()));
return restStatisticsModel;
}
Aggregations