Skip to main content

Model assets as a graph

Most domains are a hierarchy of things that contain or feed each other — a plant contains lines, a line contains machines, a machine emits sensor readings. Model that as resources (the nodes) and relations (the edges), and the SDK returns the persisted graph in one call.

Create the graph​

Create the nodes and the edges between them together. Each node needs at least one label (a type such as Plant or Machine). Relationship-type names and labels are upper-cased by the server; external ids are not touched at all and are stored exactly as you send them, so you can mirror the tags your operation already maintains (COM-99-PT-1034, =K1-M3+B02). The example below uses snake_case because that reads well in code, not because the server requires it. External ids & naming →

ResourceForm plant = new ResourceForm();
plant.setExternalId("plant_oslo");
plant.setName("Oslo Plant");
plant.setLabels(List.of("Plant")); // at least one label is required

ResourceForm line = new ResourceForm();
line.setExternalId("line_a");
line.setName("Assembly line A");
line.setLabels(List.of("Line"));

ResourceForm press = new ResourceForm();
press.setExternalId("press_07");
press.setName("Hydraulic press 07");
press.setLabels(List.of("Machine"));

RelForm plantLine = new RelForm();
plantLine.setName("contains");
plantLine.setFromExternalId("plant_oslo");
plantLine.setToExternalId("line_a");

RelForm lineMachine = new RelForm();
lineMachine.setName("contains");
lineMachine.setFromExternalId("line_a");
lineMachine.setToExternalId("press_07");

var graph = client.resources().create(
List.of(plant, line, press), List.of(plantLine, lineMachine));

System.out.println(graph.getNodes().size() + " nodes, "
+ graph.getRelations().size() + " edges");

Attach time-series to a node​

A machine's sensors are time-series. Tie a series to the machine that produces it with a relation, exactly as above (press_07 → produces → press_07_oil_temp), then ingest its datapoints.

Read the graph back​

Fetch nodes by external id; each resource carries its outgoing edges.

var some = client.resources().byIds(List.of(
IdCollection.createFromExternalId("press_07")));

Resource press = some.getItems().iterator().next();
press.getRelations().forEach(edge ->
System.out.println(edge.getType() + " -> " + edge.getEnd()));
Group with datasets

Relations model structure. To slice assets by ownership, environment or tenant — "everything in the Oslo plant" — also put them in a dataset (see the Datasets reference). A resource can sit in a graph and a dataset at once.