Search in sources :

Example 1 with PathRepresentation

use of org.neo4j.server.rest.repr.PathRepresentation in project neo4j by neo4j.

the class TransactionWrappedDatabaseActions method findSinglePath.

@Override
public PathRepresentation findSinglePath(long startId, long endId, Map<String, Object> map) {
    try (Transaction transaction = graph.beginTx()) {
        PathRepresentation singlePath = super.findSinglePath(startId, endId, map);
        transaction.success();
        return singlePath;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation)

Example 2 with PathRepresentation

use of org.neo4j.server.rest.repr.PathRepresentation in project neo4j by neo4j.

the class DatabaseActions method findPaths.

@SuppressWarnings({ "rawtypes", "unchecked" })
public ListRepresentation findPaths(long startId, long endId, Map<String, Object> map) {
    final FindParams findParams = new FindParams(startId, endId, map).invoke();
    PathFinder finder = findParams.getFinder();
    Node startNode = findParams.getStartNode();
    Node endNode = findParams.getEndNode();
    Iterable paths = finder.findAllPaths(startNode, endNode);
    IterableWrapper<PathRepresentation, Path> pathRepresentations = new IterableWrapper<PathRepresentation, Path>(paths) {

        @Override
        protected PathRepresentation underlyingObjectToObject(Path path) {
            return findParams.pathRepresentationOf(path);
        }
    };
    return new ListRepresentation(RepresentationType.PATH, pathRepresentations);
}
Also used : Path(org.neo4j.graphdb.Path) WeightedPath(org.neo4j.graphalgo.WeightedPath) ResourceIterable(org.neo4j.graphdb.ResourceIterable) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) Node(org.neo4j.graphdb.Node) PathFinder(org.neo4j.graphalgo.PathFinder) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 3 with PathRepresentation

use of org.neo4j.server.rest.repr.PathRepresentation in project neo4j by neo4j.

the class RestRepresentationWriter method write.

private void write(JsonGenerator out, RepresentationFormat format, Object value, TransactionStateChecker checker) throws IOException {
    if (value instanceof Map<?, ?>) {
        out.writeStartObject();
        try {
            for (Map.Entry<String, ?> entry : ((Map<String, ?>) value).entrySet()) {
                out.writeFieldName(entry.getKey());
                write(out, format, entry.getValue(), checker);
            }
        } finally {
            out.writeEndObject();
        }
    } else if (value instanceof Path) {
        write(format, new PathRepresentation<>((Path) value));
    } else if (value instanceof Iterable<?>) {
        out.writeStartArray();
        try {
            for (Object item : (Iterable<?>) value) {
                write(out, format, item, checker);
            }
        } finally {
            out.writeEndArray();
        }
    } else if (value instanceof Node) {
        NodeRepresentation representation = new NodeRepresentation((Node) value);
        representation.setTransactionStateChecker(checker);
        write(format, representation);
    } else if (value instanceof Relationship) {
        RelationshipRepresentation representation = new RelationshipRepresentation((Relationship) value);
        representation.setTransactionStateChecker(checker);
        write(format, representation);
    } else {
        out.writeObject(value);
    }
}
Also used : Path(org.neo4j.graphdb.Path) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) Map(java.util.Map)

Aggregations

PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)3 Node (org.neo4j.graphdb.Node)2 Path (org.neo4j.graphdb.Path)2 Map (java.util.Map)1 PathFinder (org.neo4j.graphalgo.PathFinder)1 WeightedPath (org.neo4j.graphalgo.WeightedPath)1 Relationship (org.neo4j.graphdb.Relationship)1 ResourceIterable (org.neo4j.graphdb.ResourceIterable)1 Transaction (org.neo4j.graphdb.Transaction)1 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)1 ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)1 NodeRepresentation (org.neo4j.server.rest.repr.NodeRepresentation)1 RelationshipRepresentation (org.neo4j.server.rest.repr.RelationshipRepresentation)1 WeightedPathRepresentation (org.neo4j.server.rest.repr.WeightedPathRepresentation)1