|
@@ -1,448 +0,0 @@
|
|
|
-package io.connector.module.senslog1;
|
|
|
|
|
-
|
|
|
|
|
-import io.connector.core.http.HttpClient;
|
|
|
|
|
-import io.connector.core.http.HttpRequest;
|
|
|
|
|
-import io.connector.core.http.HttpResponse;
|
|
|
|
|
-import io.connector.core.http.URLBuilder;
|
|
|
|
|
-import io.connector.core.config.HostConfig;
|
|
|
|
|
-import io.connector.model.senslog1.*;
|
|
|
|
|
-import io.vertx.core.json.JsonArray;
|
|
|
|
|
-import io.vertx.core.json.JsonObject;
|
|
|
|
|
-import org.apache.logging.log4j.LogManager;
|
|
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
|
|
-
|
|
|
|
|
-import java.time.OffsetDateTime;
|
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
-
|
|
|
|
|
-import static io.connector.core.http.ContentType.TEXT_PLAIN;
|
|
|
|
|
-import static java.lang.String.format;
|
|
|
|
|
-import static java.time.format.DateTimeFormatter.ofPattern;
|
|
|
|
|
-
|
|
|
|
|
-public class SensLog1HttpClient {
|
|
|
|
|
-
|
|
|
|
|
- private static final Logger logger = LogManager.getLogger(SensLog1HttpClient.class);
|
|
|
|
|
-
|
|
|
|
|
- private static final DateTimeFormatter FORMATTER = ofPattern("yyyy-MM-dd HH:mm:ssZ");
|
|
|
|
|
-
|
|
|
|
|
- private Map<Long, UnitInfo> unitInfoList;
|
|
|
|
|
-
|
|
|
|
|
- private final SensLog1Config config;
|
|
|
|
|
- private final HttpClient httpClient;
|
|
|
|
|
-
|
|
|
|
|
- SensLog1HttpClient(SensLog1Config config, HttpClient httpClient) {
|
|
|
|
|
- this.config = config;
|
|
|
|
|
- this.httpClient = httpClient;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private Map<Long, UnitInfo> getUnitInfos() {
|
|
|
|
|
- if (unitInfoList == null || unitInfoList.isEmpty()) {
|
|
|
|
|
- units();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// {
|
|
|
|
|
-// Map<Long, UnitInfo> infos = new HashMap<>(1);
|
|
|
|
|
-// for (Map.Entry<Long, UnitInfo> unitEntry : unitInfoList.entrySet()) {
|
|
|
|
|
-// for (SensorInfo sensor : unitEntry.getValue().getSensors()) {
|
|
|
|
|
-// List<SensorInfo> sensors = new ArrayList<>();
|
|
|
|
|
-// sensors.add(sensor);
|
|
|
|
|
-// unitEntry.getValue().setSensors(sensors);
|
|
|
|
|
-// break;
|
|
|
|
|
-// }
|
|
|
|
|
-// infos.put(unitEntry.getKey(), unitEntry.getValue());
|
|
|
|
|
-// break;
|
|
|
|
|
-// }
|
|
|
|
|
-// unitInfoList = infos;
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- return unitInfoList;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> lastObservations() {
|
|
|
|
|
-
|
|
|
|
|
- HostConfig host = config.getSensorServiceHost();
|
|
|
|
|
- logger.info("Getting observations from {}.", host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "GetLastObservations")
|
|
|
|
|
- .addParam("user", config.getUser())
|
|
|
|
|
- .addParam("group", config.getGroup())
|
|
|
|
|
- .build())
|
|
|
|
|
- .build();
|
|
|
|
|
- logger.info("Creating a http request to {}.", request);
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
- logger.info("Received a response with a status: {} for the domain {}.", response.getStatus(), host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- JsonArray jsonArray = new JsonArray(response.getBody());
|
|
|
|
|
- Map<Long, UnitData> units = new HashMap<>(1);
|
|
|
|
|
- for (Object jsonObject : jsonArray) {
|
|
|
|
|
- if (jsonObject instanceof JsonObject) {
|
|
|
|
|
- JsonObject jsonObservations = (JsonObject)jsonObject;
|
|
|
|
|
- long unitId = jsonObservations.getLong("unitId");
|
|
|
|
|
- long sensorId = jsonObservations.getLong("sensorId");
|
|
|
|
|
- SensorData sensor = units.computeIfAbsent(unitId, UnitData::new).getSensor(sensorId);
|
|
|
|
|
- if (sensor == null) {
|
|
|
|
|
- sensor = new SensorData(sensorId);
|
|
|
|
|
- units.get(unitId).addSensor(sensor);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Observation observation = Observation.parse(jsonObservations);
|
|
|
|
|
- if (observation != null) {
|
|
|
|
|
- sensor.addObservation(observation);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return new ArrayList<>(units.values());
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void uploadPositions(List<UnitData> unitData) {
|
|
|
|
|
- HostConfig host = config.getFeederServiceHost();
|
|
|
|
|
-
|
|
|
|
|
- for (UnitData multiSensor : unitData) {
|
|
|
|
|
- for (Position position : multiSensor.getPositions()) {
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
- .contentType(TEXT_PLAIN)
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "InsertPosition")
|
|
|
|
|
- .addParam("date", position.getTimestamp().format(FORMATTER))
|
|
|
|
|
- .addParam("unit_id", multiSensor.getId())
|
|
|
|
|
- .addParam("lat", position.getLatitude())
|
|
|
|
|
- .addParam("lon", position.getLongitude())
|
|
|
|
|
- .addParam("alt", position.getAltitude())
|
|
|
|
|
- .addParam("speed", position.getSpeed())
|
|
|
|
|
- .addParam("dop", position.getDilutionOfPrecision())
|
|
|
|
|
- .build())
|
|
|
|
|
- .GET().build();
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- logger.debug("Parsing body of the response.");
|
|
|
|
|
- boolean result = Boolean.parseBoolean(response.getBody());
|
|
|
|
|
-
|
|
|
|
|
- if (!result) {
|
|
|
|
|
- logger.warn("Position {} was rejected.", position);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- logger.warn("Position {} was rejected.", position);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> uploadObservations(List<UnitData> unitData) {
|
|
|
|
|
-
|
|
|
|
|
- HostConfig host = config.getFeederServiceHost();
|
|
|
|
|
-
|
|
|
|
|
- Map<Long, UnitData> badObservations = new HashMap<>();
|
|
|
|
|
- for (UnitData multiSensor : unitData) {
|
|
|
|
|
- for (SensorData sensor : multiSensor.getSensors()) {
|
|
|
|
|
- for (Observation observation : sensor.getObservations()) {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder()
|
|
|
|
|
- .contentType(TEXT_PLAIN)
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "InsertObservation")
|
|
|
|
|
- .addParam("value", observation.getValue())
|
|
|
|
|
- .addParam("date", observation.getTimestamp().format(FORMATTER))
|
|
|
|
|
- .addParam("unit_id", multiSensor.getId())
|
|
|
|
|
- .addParam("sensor_id", sensor.getId())
|
|
|
|
|
- .build())
|
|
|
|
|
- .GET().build();
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- logger.debug("Parsing body of the response.");
|
|
|
|
|
- boolean result = Boolean.parseBoolean(response.getBody());
|
|
|
|
|
-
|
|
|
|
|
- if (!result) {
|
|
|
|
|
- logger.warn("Observation {} was rejected.", observation);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- SensorObservation sensorObservation = badObservations
|
|
|
|
|
- .computeIfAbsent(multiSensor.getId(), UnitData::new)
|
|
|
|
|
- .getSensor(sensor.getId());
|
|
|
|
|
-
|
|
|
|
|
- if (sensorObservation == null) {
|
|
|
|
|
- sensorObservation = new SensorObservation(sensor.getId());
|
|
|
|
|
- badObservations.get(multiSensor.getId()).addSensor(sensorObservation);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- sensorObservation.addObservation(observation);
|
|
|
|
|
-
|
|
|
|
|
- logger.warn("Observation {} was rejected.", observation);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- */
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return new ArrayList<>(badObservations.values());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> positions(OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- List<UnitData> units = new ArrayList<>();
|
|
|
|
|
- for (UnitInfo multiSensor : getUnitInfos().values()) {
|
|
|
|
|
- units.addAll(positions(multiSensor.getId(), fromDate, toDate));
|
|
|
|
|
- }
|
|
|
|
|
- return units;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> positions(long unitId, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- UnitData unitData = new UnitData(unitId);
|
|
|
|
|
- positions(unitData, fromDate, toDate);
|
|
|
|
|
- return Collections.singletonList(unitData);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void positions(UnitData multiSensor, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- HostConfig host = config.getDataServiceHost();
|
|
|
|
|
- logger.info("Getting observations from {}.", host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "GetPositionsDay")
|
|
|
|
|
- .addParam("user", config.getUser())
|
|
|
|
|
- .addParam("unit_id", multiSensor.getId())
|
|
|
|
|
- .addParam("fromTime", fromDate.format(FORMATTER))
|
|
|
|
|
- .addParam("toTime", toDate.format(FORMATTER))
|
|
|
|
|
- .build())
|
|
|
|
|
- .build();
|
|
|
|
|
- logger.info("Creating a http request to {}.", request);
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
- logger.info("Received a response with a status: {} for the domain {}.", response.getStatus(), host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- JsonArray json = new JsonArray(response.getBody());
|
|
|
|
|
- for (Object objJson : json) {
|
|
|
|
|
- if (objJson instanceof JsonObject) {
|
|
|
|
|
- Position position = Position.parse((JsonObject)objJson);
|
|
|
|
|
-
|
|
|
|
|
- if (position != null) {
|
|
|
|
|
- multiSensor.addPosition(position);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<Unit> observationsWithInfo(OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- Collection<UnitInfo> unitInfos = getUnitInfos().values();
|
|
|
|
|
- List<Unit> units = new ArrayList<>(unitInfos.size());
|
|
|
|
|
- for (UnitInfo unitInfo : unitInfos) {
|
|
|
|
|
- UnitData unitData = new UnitData(unitInfo.getId());
|
|
|
|
|
- Collection<SensorInfo> sensorInfos = unitInfo.getSensors();
|
|
|
|
|
- List<Sensor> sensors = new ArrayList<>(sensorInfos.size());
|
|
|
|
|
- for (SensorInfo sensorInfo : sensorInfos) {
|
|
|
|
|
- SensorData sensorObs = new SensorData(sensorInfo.getId());
|
|
|
|
|
- observations(unitData, sensorObs, fromDate, toDate);
|
|
|
|
|
- sensors.add(new Sensor(sensorInfo, sensorObs.getObservations()));
|
|
|
|
|
- }
|
|
|
|
|
- units.add(new Unit(unitInfo, sensors));
|
|
|
|
|
- }
|
|
|
|
|
- return units;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<Unit> observationsWithInfo(long unitId, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- UnitInfo unitInfo = getUnitInfos().get(unitId);
|
|
|
|
|
- if (unitInfo == null) {
|
|
|
|
|
- throw new RuntimeException(format("Unknown multiSensor with id %s.", unitId));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- UnitData unitData = new UnitData(unitInfo.getId());
|
|
|
|
|
- Collection<SensorInfo> sensorInfos = unitInfo.getSensors();
|
|
|
|
|
- List<Sensor> sensors = new ArrayList<>(sensorInfos.size());
|
|
|
|
|
- for (SensorInfo sensorInfo : sensorInfos) {
|
|
|
|
|
- SensorData sensorObs = new SensorData(sensorInfo.getId());
|
|
|
|
|
- observations(unitData, sensorObs, fromDate, toDate);
|
|
|
|
|
- sensors.add(new Sensor(sensorInfo, sensorObs.getObservations()));
|
|
|
|
|
- }
|
|
|
|
|
- List<Unit> units = new ArrayList<>(1);
|
|
|
|
|
- units.add(new Unit(unitInfo, sensors));
|
|
|
|
|
- return units;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<Unit> observationsWithInfo(long unitId, long sensorId, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- UnitInfo unitInfo = getUnitInfos().get(unitId);
|
|
|
|
|
- if (unitInfo == null) {
|
|
|
|
|
- throw new RuntimeException(format("Unknown multiSensor with id %s.", unitId));
|
|
|
|
|
- }
|
|
|
|
|
- SensorInfo sensorInfo = unitInfo.getSensor(sensorId);
|
|
|
|
|
- if (sensorInfo == null) {
|
|
|
|
|
- throw new RuntimeException(format("Unknown sensor with id %s for the multiSensor %s.", sensorId, unitId));
|
|
|
|
|
- }
|
|
|
|
|
- UnitData unitData = new UnitData(unitInfo.getId());
|
|
|
|
|
- SensorData sensorObs = new SensorData(sensorInfo.getId());
|
|
|
|
|
- observations(unitData, sensorObs, fromDate, toDate);
|
|
|
|
|
- List<Sensor> sensors = new ArrayList<>(1);
|
|
|
|
|
- sensors.add(new Sensor(sensorInfo, sensorObs.getObservations()));
|
|
|
|
|
-
|
|
|
|
|
- List<Unit> units = new ArrayList<>(1);
|
|
|
|
|
- units.add(new Unit(unitInfo, sensors));
|
|
|
|
|
- return units;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> observations(OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- List<UnitData> units = new ArrayList<>();
|
|
|
|
|
- for (UnitInfo multiSensor : getUnitInfos().values()) {
|
|
|
|
|
- units.addAll(observations(multiSensor.getId(), fromDate, toDate));
|
|
|
|
|
- }
|
|
|
|
|
- return units;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> observations(long unitId, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- UnitInfo unitInfo = getUnitInfos().get(unitId);
|
|
|
|
|
- if (unitInfo != null) {
|
|
|
|
|
- UnitData multiSensor = new UnitData(unitInfo.getId());
|
|
|
|
|
- for (SensorInfo sensorInfo : unitInfo.getSensors()) {
|
|
|
|
|
- SensorData sensor = new SensorData(sensorInfo.getId());
|
|
|
|
|
- multiSensor.addSensor(sensor);
|
|
|
|
|
- observations(multiSensor, sensor, fromDate, toDate);
|
|
|
|
|
- }
|
|
|
|
|
- return Arrays.asList(multiSensor);
|
|
|
|
|
- }
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitData> observations(long unitId, long sensorId, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
- UnitData multiSensor = new UnitData(unitId);
|
|
|
|
|
- SensorData sensor = new SensorData(sensorId);
|
|
|
|
|
- multiSensor.addSensor(sensor);
|
|
|
|
|
- observations(multiSensor, sensor, fromDate, toDate);
|
|
|
|
|
- return Arrays.asList(multiSensor);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void observations(UnitData multiSensor, SensorData sensor, OffsetDateTime fromDate, OffsetDateTime toDate) {
|
|
|
|
|
-
|
|
|
|
|
- HostConfig host = config.getSensorServiceHost();
|
|
|
|
|
- logger.info("Getting observations from {}.", host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "GetObservations")
|
|
|
|
|
- .addParam("user", config.getUser())
|
|
|
|
|
- .addParam("unit_id", multiSensor.getId())
|
|
|
|
|
- .addParam("sensor_id", sensor.getId())
|
|
|
|
|
- .addParam("from", fromDate.format(FORMATTER))
|
|
|
|
|
- .addParam("to", toDate.format(FORMATTER))
|
|
|
|
|
- .build())
|
|
|
|
|
- .build();
|
|
|
|
|
- logger.info("Creating a http request to {}.", request);
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
- logger.info("Received a response with a status: {} for the domain {}.", response.getStatus(), host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
-
|
|
|
|
|
- JsonArray json = new JsonArray(response.getBody());
|
|
|
|
|
- for (Object obsJson : json) {
|
|
|
|
|
- if (obsJson instanceof JsonObject) {
|
|
|
|
|
- Observation observation = Observation.parse((JsonObject)obsJson);
|
|
|
|
|
-
|
|
|
|
|
- if (observation != null) {
|
|
|
|
|
- sensor.addObservation(observation);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<UnitInfo> units() {
|
|
|
|
|
- HostConfig host = config.getDataServiceHost();
|
|
|
|
|
- logger.info("Getting last observations from {}.", host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "GetUnitsList")
|
|
|
|
|
- .addParam("user", config.getUser())
|
|
|
|
|
- .build())
|
|
|
|
|
- .build();
|
|
|
|
|
- logger.info("Creating a http request to {}.", request);
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
- logger.info("Received a response with a status: {} for the domain {}.", response.getStatus(), host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- logger.debug("Parsing body of the response to the list of class {}.", UnitInfo.class);
|
|
|
|
|
- JsonArray json = new JsonArray(response.getBody());
|
|
|
|
|
- List<UnitInfo> units = new ArrayList<>(json.size());
|
|
|
|
|
- unitInfoList = new HashMap<>(json.size());
|
|
|
|
|
- for (Object unitJson : json) {
|
|
|
|
|
- if (unitJson instanceof JsonObject) {
|
|
|
|
|
- UnitInfo multiSensor = UnitInfo.parse((JsonObject)unitJson);
|
|
|
|
|
- if (multiSensor != null) {
|
|
|
|
|
- units.add(multiSensor);
|
|
|
|
|
- unitInfoList.put(multiSensor.getId(), multiSensor);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for (UnitInfo multiSensor : units) {
|
|
|
|
|
- List<SensorInfo> sensors = sensors(multiSensor.getId());
|
|
|
|
|
- multiSensor.setSensors(sensors);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return units;
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- logger.error("Can not get data from the server {}. Error {} {}",
|
|
|
|
|
- host.getDomain(), response.getStatus(), response.getBody());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<SensorInfo> sensors(long unitId) {
|
|
|
|
|
- HostConfig host = config.getSensorServiceHost();
|
|
|
|
|
- logger.debug("Getting last observations from {}.", host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
|
|
- .url(URLBuilder.newBuilder(host.getDomain(), host.getPath())
|
|
|
|
|
- .addParam("Operation", "GetSensors")
|
|
|
|
|
- .addParam("user", config.getUser())
|
|
|
|
|
- .addParam("unit_id", unitId)
|
|
|
|
|
- .build())
|
|
|
|
|
- .build();
|
|
|
|
|
- logger.info("Creating a http request to {}.", request);
|
|
|
|
|
-
|
|
|
|
|
- HttpResponse response = httpClient.send(request);
|
|
|
|
|
- logger.info("Received a response with a status: {} for the domain {}.", response.getStatus(), host.getDomain());
|
|
|
|
|
-
|
|
|
|
|
- if (response.isOk()) {
|
|
|
|
|
- logger.debug("Parsing body of the response to the list of class {}.", SensorInfo.class);
|
|
|
|
|
- JsonArray json = new JsonArray(response.getBody());
|
|
|
|
|
- List<SensorInfo> sensors = new ArrayList<>(json.size());
|
|
|
|
|
- for (Object sensorJson : json) {
|
|
|
|
|
- if (sensorJson instanceof JsonObject) {
|
|
|
|
|
- SensorInfo sensor = SensorInfo.parse((JsonObject)sensorJson);
|
|
|
|
|
- if (sensor != null) {
|
|
|
|
|
- sensors.add(sensor);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- logger.info("For the multiSensor {} was added {} sensors.", unitId, sensors.size());
|
|
|
|
|
-
|
|
|
|
|
- return sensors;
|
|
|
|
|
- } else {
|
|
|
|
|
- logger.error("Can not get data from the server {}. Error {} {}",
|
|
|
|
|
- host.getDomain(), response.getStatus(), response.getBody());
|
|
|
|
|
-
|
|
|
|
|
- return Collections.emptyList();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|