2021-12-10 10:21:06 +00:00
|
|
|
package cc.pogoda.mobile.meteosystem.dao;
|
2021-12-08 12:36:01 +00:00
|
|
|
|
2022-05-11 15:04:21 +00:00
|
|
|
import static cc.pogoda.mobile.meteosystem.config.WebIoConfig.TIMEOUT_SECOND;
|
|
|
|
|
2022-01-06 21:06:53 +00:00
|
|
|
import org.tinylog.Logger;
|
|
|
|
|
2022-05-03 17:56:00 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2021-12-10 10:21:06 +00:00
|
|
|
import cc.pogoda.mobile.meteosystem.type.web.AvailableParametersWeb;
|
|
|
|
import cc.pogoda.mobile.meteosystem.web.AvailableParametersConsumer;
|
|
|
|
import cc.pogoda.mobile.meteosystem.web.RestClientConfig;
|
2021-12-08 12:36:01 +00:00
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
public class AvailableParametersDao {
|
|
|
|
|
|
|
|
RestClientConfig restClient;
|
|
|
|
|
|
|
|
Response<AvailableParametersWeb> response = null;
|
|
|
|
|
|
|
|
String stationName;
|
|
|
|
|
|
|
|
class Worker implements Runnable {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
restClient = new RestClientConfig();
|
|
|
|
|
|
|
|
AvailableParametersConsumer consumer = restClient.getWeatherStationClient().create(AvailableParametersConsumer.class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = consumer.getParametersForStation(stationName).execute();
|
2022-05-03 17:56:00 +00:00
|
|
|
} catch (IOException e) {
|
2022-05-11 15:04:21 +00:00
|
|
|
Logger.error("[IOException][e = " + e.getLocalizedMessage() +"]");
|
2022-05-03 17:56:00 +00:00
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (RuntimeException e) {
|
2022-05-11 15:04:21 +00:00
|
|
|
Logger.error("[RuntimeException][e = " + e.getLocalizedMessage() +"]");
|
2022-05-03 17:56:00 +00:00
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2022-05-11 15:04:21 +00:00
|
|
|
Logger.error("[Exception][e = " + e.getLocalizedMessage() +"]");
|
2022-01-06 21:06:53 +00:00
|
|
|
|
2021-12-08 12:36:01 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-05-03 17:56:00 +00:00
|
|
|
|
|
|
|
if (response == null) {
|
2022-05-11 15:04:21 +00:00
|
|
|
Logger.error("[worker is done, response is null]");
|
2022-05-03 17:56:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-05-11 15:04:21 +00:00
|
|
|
Logger.info("[worker is done][response.code() = " + response.code() +"]");
|
2022-05-03 17:56:00 +00:00
|
|
|
}
|
2021-12-08 12:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public AvailableParametersWeb getAvaliableParamsByStationName(String name) {
|
|
|
|
AvailableParametersWeb out = null;
|
|
|
|
|
|
|
|
stationName = name;
|
|
|
|
|
|
|
|
Thread t = new Thread(new Worker());
|
|
|
|
|
|
|
|
t.start();
|
|
|
|
|
|
|
|
try {
|
|
|
|
t.join();
|
|
|
|
|
2022-05-08 14:42:45 +00:00
|
|
|
if (response != null) {
|
|
|
|
out = response.body();
|
|
|
|
}
|
2021-12-08 12:36:01 +00:00
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|