brtb
brtb

Reputation: 2311

How to access a node properties on neo4j unmanaged extension

i m new in neo4j and unmanaged extension.

i just write HelloWorld example in neo4j and the code is the following

//START SNIPPET: HelloWorldResource
@Path( "/helloworld" )
public class HelloWorldResource
{
    private final GraphDatabaseService database;

    public HelloWorldResource( @Context GraphDatabaseService database )
    {
        this.database = database;
    }

    @GET
    @Produces( MediaType.TEXT_PLAIN )
    @Path( "/{nodeId}" )
    public Response hello( @PathParam( "nodeId" ) long nodeId )
    {  
        // Do stuff with the database

        return Response.status( Status.OK ).entity(
                ("Hello World2, nodeId=" + nodeId + ", ADDRESSNO = " +     "").getBytes( Charset.forName("UTF-8") ) ).build();
    }
}

how can i access to the node its id is nodeId

how can i access its address property

Upvotes: 0

Views: 76

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

inside the hello method:

try (Transaction tx = database.beginTx()) {
    Node n = database.getNodeById(nodeId);
    String address = (String)n.getProperty("address", null);

    tx.success();
}

Upvotes: 1

Related Questions