Search in sources :

Example 1 with RelationshipRepresentation

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

the class TransactionWrappedDatabaseActions method getRelationship.

@Override
public RelationshipRepresentation getRelationship(long relationshipId) throws RelationshipNotFoundException {
    try (Transaction transaction = graph.beginTx()) {
        RelationshipRepresentation relationship = super.getRelationship(relationshipId);
        transaction.success();
        return relationship;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation)

Example 2 with RelationshipRepresentation

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

the class TransactionWrappedDatabaseActions method createRelationship.

@Override
public RelationshipRepresentation createRelationship(long startNodeId, long endNodeId, String type, Map<String, Object> properties) throws StartNodeNotFoundException, EndNodeNotFoundException, PropertyValueException {
    try (Transaction transaction = graph.beginTx()) {
        RelationshipRepresentation relationshipRepresentation = super.createRelationship(startNodeId, endNodeId, type, properties);
        transaction.success();
        return relationshipRepresentation;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation)

Example 3 with RelationshipRepresentation

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

the class DatabaseActionsTest method shouldAllowCreateRelationshipWithSameStartAsEndNode.

@Test
public void shouldAllowCreateRelationshipWithSameStartAsEndNode() throws Exception {
    long nodeId = graphdbHelper.createNode();
    Map<String, Object> properties = Collections.emptyMap();
    RelationshipRepresentation rel = actions.createRelationship(nodeId, nodeId, "Loves", properties);
    assertNotNull(rel);
}
Also used : RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 4 with RelationshipRepresentation

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

the class DatabaseActions method createRelationship.

public RelationshipRepresentation createRelationship(long startNodeId, long endNodeId, String type, Map<String, Object> properties) throws StartNodeNotFoundException, EndNodeNotFoundException, PropertyValueException {
    Node start, end;
    try {
        start = node(startNodeId);
    } catch (NodeNotFoundException e) {
        throw new StartNodeNotFoundException(e);
    }
    try {
        end = node(endNodeId);
    } catch (NodeNotFoundException e) {
        throw new EndNodeNotFoundException(e);
    }
    Relationship rel = start.createRelationshipTo(end, RelationshipType.withName(type));
    propertySetter.setProperties(rel, properties);
    return new RelationshipRepresentation(rel);
}
Also used : StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) Node(org.neo4j.graphdb.Node) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) Relationship(org.neo4j.graphdb.Relationship) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation)

Example 5 with RelationshipRepresentation

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

RelationshipRepresentation (org.neo4j.server.rest.repr.RelationshipRepresentation)5 Node (org.neo4j.graphdb.Node)2 Relationship (org.neo4j.graphdb.Relationship)2 Transaction (org.neo4j.graphdb.Transaction)2 Map (java.util.Map)1 Test (org.junit.Test)1 Path (org.neo4j.graphdb.Path)1 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)1 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)1 NodeRepresentation (org.neo4j.server.rest.repr.NodeRepresentation)1 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)1 PathRepresentation (org.neo4j.server.rest.repr.PathRepresentation)1 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)1 ScoredRelationshipRepresentation (org.neo4j.server.rest.repr.ScoredRelationshipRepresentation)1