use of org.neo4j.ogm.response.model.DefaultGraphModel in project neo4j-ogm by neo4j.
the class GraphModelAdapter method adapt.
/**
* Parses a row from the result object and transforms it into a GraphModel
*
* @param data the data to transform, given as a map
* @return the data transformed to an {@link GraphModel}
*/
@Override
public GraphModel adapt(Map<String, Object> data) {
// These two sets keep track of which nodes and edges have already been built, so we don't redundantly
// write the same node or relationship entity many times.
final Set<Long> nodeIdentities = new HashSet<>();
final Set<Long> edgeIdentities = new HashSet<>();
DefaultGraphModel graphModel = new DefaultGraphModel();
for (Map.Entry<String, Object> mapEntry : data.entrySet()) {
final Object value = mapEntry.getValue();
String resultKey = mapEntry.getKey();
boolean generatedNodes = ResultAdapter.describesGeneratedNode(resultKey);
adaptInternal(nodeIdentities, edgeIdentities, graphModel, value, generatedNodes);
}
return graphModel;
}
use of org.neo4j.ogm.response.model.DefaultGraphModel in project neo4j-ogm by neo4j.
the class GraphRowModelAdapter method adapt.
/**
* Reads the next row from the result object and transforms it into a RowModel object
*
* @param data the data to transform, given as a map
* @return the data transformed to an {@link RowModel}
*/
public GraphRowModel adapt(Map<String, Object> data) {
if (columns == null) {
throw new ResultProcessingException("Result columns should not be null");
}
Set<Long> nodeIdentities = new HashSet<>();
Set<Long> edgeIdentities = new HashSet<>();
DefaultGraphModel graphModel = new DefaultGraphModel();
List<String> variables = new ArrayList<>();
List<Object> values = new ArrayList<>();
// there is no guarantee that the objects in the data are ordered the same way as required by the columns
// so we use the columns information to extract them in the correct order for post-processing.
Iterator<String> iterator = columns.iterator();
adapt(iterator, data, graphModel, variables, values, nodeIdentities, edgeIdentities);
DefaultRowModel rowModel = new DefaultRowModel(values.toArray(new Object[] {}), variables.toArray(new String[] {}));
return new DefaultGraphRowModel(graphModel, rowModel.getValues());
}
Aggregations