Search in sources :

Example 6 with Response

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;
}
Also used : Response(org.neo4j.ogm.response.Response) GraphModel(org.neo4j.ogm.model.GraphModel) DefaultGraphModel(org.neo4j.ogm.response.model.DefaultGraphModel) RestModel(org.neo4j.ogm.model.RestModel)

Aggregations

Response (org.neo4j.ogm.response.Response)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)3 MetaData (org.neo4j.ogm.metadata.MetaData)3 GraphModel (org.neo4j.ogm.model.GraphModel)3 RowModel (org.neo4j.ogm.model.RowModel)3 Statement (org.neo4j.ogm.request.Statement)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Set (java.util.Set)2 BiFunction (java.util.function.BiFunction)2 Collectors (java.util.stream.Collectors)2 MappingContext (org.neo4j.ogm.context.MappingContext)2 EntityInstantiator (org.neo4j.ogm.session.EntityInstantiator)2 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)2 EntityUtils (org.neo4j.ogm.utils.EntityUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Serializable (java.io.Serializable)1