I'm working with NEO4J and Java to create a prototype for an application that integrates a graph database that holds patient information (with fake, made up data).
I've created a simple two class program, and created nodes (haven't assigned relationships yet). However, I want to be able to view the nodes that I've created in order to make sure that my application is working properly, and to be able to see the results in the NEO4J Browser / Community Server.
How can I get the nodes to appear visually? I know I could test the fact that they're being created by querying them, but I also want to know how to visually display them.
What I've tried to do is go into the Neo4j.conf file, and change the active database from the default "graph.db" to "Users/andrew/eclipse-workspace/patients-database/target/patient-db", since in the Java class I've created, I use this line of code to set my database:
private static final File Patient_DB = new File("target/patient-db");
However, whenever I open the NEO4J browser at localhost:7474, after running my code there are no nodes visible.
Below, I'll paste the code to my PatientGraph class (the other class is just a Patient class that creates the Patients and their attributes)
package com.andrewhe.neo4j.Patients_Database;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.io.fs.FileUtils;
public class PatientGraph {
private static final File Patient_DB = new File("target/patient-db");
private ArrayList<Patient> patients = new ArrayList<Patient>();
private long patientZero;
private GraphDatabaseService graphDb;
public ArrayList<Patient> getPatients() { return patients; }
public void manualPatientSetUp() throws IOException {
Patient homeNode = new Patient("");
Patient jan = new Patient("Jan");
patients.add(jan);
Patient kim = new Patient("Kim");
patients.add(kim);
Patient ahmad = new Patient("Ahmad");
patients.add(ahmad);
Patient andrew = new Patient("Andrew");
patients.add(andrew);
}
public void createPatientNodes() throws IOException {
FileUtils.deleteRecursively(Patient_DB);
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(Patient_DB);
registerShutdownHook();
try (Transaction tx = graphDb.beginTx()) {
for (Patient patient : patients) {
Node patientNode = graphDb.createNode();
System.out.println("Node created");
setProperties(patientNode, patient);
}
tx.success();
}
}
//Method to create and set properties for node instead of using 5 set properties each time.
public void setProperties(Node node, Patient patient) {
node.setProperty("name", patient.getName());
node.setProperty("weight", patient.getWeight());
node.setProperty("pat_id", new String(patient.getPatientID()));
node.setProperty("age", patient.getAge());
//Don't worry about diagnoses yet;
//To get it to work, just turn the diagnoses ArrayList into a String separated by commas.
}
public void setUp() throws IOException {
//reads in patients using a file
}
public void shutdown()
{
graphDb.shutdown();
}
private void registerShutdownHook()
{
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running example before it's completed)
Runtime.getRuntime().addShutdownHook(new Thread(() -> graphDb.shutdown()));
}
public static void main(String[] args) throws IOException {
PatientGraph pg = new PatientGraph();
pg.manualPatientSetUp();
pg.createPatientNodes();
for (int i = 0; i < pg.getPatients().size(); i++) {
pg.getPatients().get(i).printAllData();
}
pg.shutdown();
}
}