View Javadoc
1   package de.dlr.shepard.neo4Core.dao;
2   
3   import de.dlr.shepard.influxDB.Timeseries;
4   import de.dlr.shepard.util.CypherQueryHelper;
5   import jakarta.enterprise.context.RequestScoped;
6   import java.util.Map;
7   
8   @RequestScoped
9   public class TimeseriesDAO extends GenericDAO<Timeseries> {
10  
11    /**
12     * Find a timeseries by properties
13     *
14     * @param measurement  measurement
15     * @param device       device
16     * @param location     location
17     * @param symbolicName symbolicName
18     * @param field        field
19     *
20     * @return the found timeseries or null
21     */
22    public Timeseries find(String measurement, String device, String location, String symbolicName, String field) {
23      var query = String.format(
24        "MATCH (t:Timeseries { measurement: $measurement, device: $device, location: $location, symbolicName: $symbolicName, field: $field }) %s",
25        CypherQueryHelper.getReturnPart("t")
26      );
27      Map<String, Object> params = Map.of(
28        "measurement",
29        measurement,
30        "device",
31        device,
32        "location",
33        location,
34        "symbolicName",
35        symbolicName,
36        "field",
37        field
38      );
39      var results = findByQuery(query, params);
40      return results.iterator().hasNext() ? results.iterator().next() : null;
41    }
42  
43    @Override
44    public Class<Timeseries> getEntityType() {
45      return Timeseries.class;
46    }
47  }