Database Reference
In-Depth Information
@Description("Get all nodes related to this node")
@PluginTarget(Node.class)
public Iterable<Relationship> getRelatedNodes(@Source Node node)
{
ArrayList<Relationship> relationships = new ArrayList<>();
try (Transaction tx = node.getGraphDatabase().beginTx())
{
for (Relationship relationship : node.getRelationships(Direction.BOTH))
{
relationships.add(relationship);
}
tx.success();
}
return relationships;
}
}
Make sure to include a file in the METa-INF/services directory called org.neo4j.server.plugins.
ServerPlugin that includes the path to your plugin. This must be included in your .jar file. an example in the chapter
code can be reused in your own project.
Important
Adding and Accessing the Plugin
To deploy the code to your Neo4j server instance, simply compile it into a .jar file and place it in the server classpath
(which is typically the “plugins” directory under the Neo4j server home directory). You will need to restart the server
in order for the plugin to be accessible.
Once the server has been restarted, you can call the Listing 6-2 from the command line or some other tool, such
as the Chrome extension POSTMAN.
Listing 6-2. Executing the Plugin Endpoint via Command Line and Curl
curl -X POST http://localhost:7474/db/data/ext/GraphStoryPlugin/node/7/getRelatedNodes -H "Content-
Type: application/json"
Security Plugins
You may also use the plugin methodology to introduce a finer level of security control for your applications. In such
cases, instead of extending the org.neo4j.server.plugins.ServerPlugin class, your code would need to implement
the org.neo4j.server.rest.security.SecurityRule . Listing 6-3 exemplifies how to verify a list of IPs before
allowing access.
 
 
Search WWH ::




Custom Search