use of org.neo4j.ogm.exception.ResultProcessingException 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());
}
use of org.neo4j.ogm.exception.ResultProcessingException in project neo4j-ogm by neo4j.
the class AbstractHttpResponse method nextDataRecord.
T nextDataRecord(String key) {
try {
if (results.hasNext()) {
JsonNode dataNode = results.next();
T t = dataNode.has(key) ? mapper.treeToValue(dataNode.get(key), resultClass) : null;
return t;
}
} catch (IOException e) {
throw new ResultProcessingException("Error processing results", e);
}
return null;
}
use of org.neo4j.ogm.exception.ResultProcessingException in project neo4j-ogm by neo4j.
the class StatisticsModelAdapter method adapt.
@Override
public QueryStatisticsModel adapt(Result response) {
try {
org.neo4j.graphdb.QueryStatistics statistics = response.getQueryStatistics();
String stats = mapper.writeValueAsString(statistics);
stats = stats.replace("Deleted", "_deleted");
stats = stats.replace("Added", "_added");
stats = stats.replace("Updates", "_updates");
stats = stats.replace("Created", "_created");
stats = stats.replace("Set", "_set");
stats = stats.replace("Removed", "_removed");
stats = stats.replace("deletedNodes", "nodes_deleted");
stats = stats.replace("deletedRelationships", "relationships_deleted");
// Modify the string to include contains_updates as it is a calculated value
String containsUpdates = ",\"contains_updates\":" + statistics.containsUpdates();
int closingBraceIndex = stats.lastIndexOf("}");
stats = stats.substring(0, closingBraceIndex) + containsUpdates + "}";
return mapper.readValue(stats, QueryStatisticsModel.class);
} catch (Exception e) {
throw new ResultProcessingException("Could not read response statistics", e);
}
}
use of org.neo4j.ogm.exception.ResultProcessingException in project neo4j-ogm by neo4j.
the class HttpRequest method cypherRequest.
// we use the OBJECT_MAPPER to create the request string from the statement.
// this driver is the only one that needs to do this, because the request format
// is different for each type of request - GraphModelRequest/RowModelRequest, etc
private String cypherRequest(Statement statement) {
List<Statement> statementList = new ArrayList<>();
statementList.add(statement);
try {
return OBJECT_MAPPER.writeValueAsString(new Statements(statementList));
} catch (JsonProcessingException jpe) {
throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe);
}
}
Aggregations