Search in sources :

Example 1 with ResultProcessingException

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());
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) ArrayList(java.util.ArrayList) DefaultRowModel(org.neo4j.ogm.response.model.DefaultRowModel) DefaultGraphRowModel(org.neo4j.ogm.response.model.DefaultGraphRowModel) DefaultGraphModel(org.neo4j.ogm.response.model.DefaultGraphModel) HashSet(java.util.HashSet)

Example 2 with ResultProcessingException

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;
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with ResultProcessingException

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);
    }
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException)

Example 4 with ResultProcessingException

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);
    }
}
Also used : ResultProcessingException(org.neo4j.ogm.exception.ResultProcessingException) Statement(org.neo4j.ogm.request.Statement) ArrayList(java.util.ArrayList) Statements(org.neo4j.ogm.request.Statements) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ResultProcessingException (org.neo4j.ogm.exception.ResultProcessingException)4 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 HashSet (java.util.HashSet)1 Statement (org.neo4j.ogm.request.Statement)1 Statements (org.neo4j.ogm.request.Statements)1 DefaultGraphModel (org.neo4j.ogm.response.model.DefaultGraphModel)1 DefaultGraphRowModel (org.neo4j.ogm.response.model.DefaultGraphRowModel)1 DefaultRowModel (org.neo4j.ogm.response.model.DefaultRowModel)1