Search in sources :

Example 1 with NodeRepresentation

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

the class DatabaseActions method createNode.

// Nodes
public NodeRepresentation createNode(Map<String, Object> properties, Label... labels) throws PropertyValueException {
    Node node = graphDb.createNode();
    propertySetter.setProperties(node, properties);
    if (labels != null) {
        for (Label label : labels) {
            node.addLabel(label);
        }
    }
    return new NodeRepresentation(node);
}
Also used : ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label)

Example 2 with NodeRepresentation

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

the class TransactionWrappedDatabaseActions method createNode.

@Override
public NodeRepresentation createNode(Map<String, Object> properties, Label... labels) throws PropertyValueException {
    try (Transaction transaction = graph.beginTx()) {
        NodeRepresentation nodeRepresentation = super.createNode(properties, labels);
        transaction.success();
        return nodeRepresentation;
    }
}
Also used : NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) Transaction(org.neo4j.graphdb.Transaction)

Example 3 with NodeRepresentation

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

the class TransactionWrappedDatabaseActions method getNode.

@Override
public NodeRepresentation getNode(long nodeId) throws NodeNotFoundException {
    try (Transaction transaction = graph.beginTx()) {
        NodeRepresentation node = super.getNode(nodeId);
        transaction.success();
        return node;
    }
}
Also used : NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) Transaction(org.neo4j.graphdb.Transaction)

Example 4 with NodeRepresentation

use of org.neo4j.server.rest.repr.NodeRepresentation 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)

Example 5 with NodeRepresentation

use of org.neo4j.server.rest.repr.NodeRepresentation 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

NodeRepresentation (org.neo4j.server.rest.repr.NodeRepresentation)6 Node (org.neo4j.graphdb.Node)4 Transaction (org.neo4j.graphdb.Transaction)3 Map (java.util.Map)2 Path (org.neo4j.graphdb.Path)2 Relationship (org.neo4j.graphdb.Relationship)2 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)2 RelationshipRepresentation (org.neo4j.server.rest.repr.RelationshipRepresentation)2 Test (org.junit.jupiter.api.Test)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Label (org.neo4j.graphdb.Label)1 ScoredNodeRepresentation (org.neo4j.server.rest.repr.ScoredNodeRepresentation)1 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)1