+
+ protected void validateGraph(ReadGraph graph) throws DatabaseException {
+ Plant3D P3D = Plant3D.getInstance(graph);
+ Resource root = (Resource)mapping.inverseGet(rootNode);
+ if (!graph.isInstanceOf(root, P3D.Plant))
+ throw new DatabaseException("Root is not a Plant");
+ Set<Resource> equipment = new HashSet<>();
+ Set<Resource> pipeRuns = new HashSet<>();
+ for (Resource r : graph.getObjects(root, P3D.children)) {
+ if (graph.isInstanceOf(r, P3D.Equipment)) {
+ equipment.add(r);
+ } else if (graph.isInstanceOf(r, P3D.PipeRun)) {
+ pipeRuns.add(r);
+ } else {
+ throw new DatabaseException("Unknown resource " + r+ " " + mapping.get(r));
+ }
+ }
+ Set<Resource> nozzles = new HashSet<>();
+ for (Resource e : equipment) {
+ for (Resource n : graph.getObjects(e, P3D.HasNozzle)) {
+ if (graph.isInstanceOf(n, P3D.Nozzle)) {
+ nozzles.add(n);
+ } else {
+ throw new DatabaseException("Unknown nozzle resource " + n+ " " + mapping.get(n));
+ }
+ }
+ }
+
+ Set<Resource> components = new HashSet<>();
+ for (Resource run : pipeRuns) {
+ for (Resource c : graph.getObjects(run, P3D.children)) {
+ if (graph.isInstanceOf(c, P3D.PipelineComponent)) {
+ components.add(c);
+ } else {
+ throw new DatabaseException("Unknown component resource " + c + " " + mapping.get(c));
+ }
+ }
+ }
+
+ for (Resource c : components) {
+ for (Resource connected : graph.getObjects(c, P3D.Connects)) {
+ if (!components.contains(connected) && !nozzles.contains(connected)) {
+ throw new DatabaseException("Unbrowsable component resource " + connected + " " + mapping.get(connected) +" connected to " + c + " " + mapping.get(c));
+ }
+ Collection<Resource> connectedConnected = graph.getObjects(connected, P3D.Connects);
+ if (!connectedConnected.contains(c)) {
+ throw new DatabaseException("Component resource " + c + " " + mapping.get(c) + " is connected to " + connected + " " + mapping.get(connected) +", but its has no connection back.");
+ }
+ }
+ }
+ }