2021-12-10 10:21:06 +00:00
|
|
|
package cc.pogoda.mobile.meteosystem.dao;
|
2021-01-26 21:07:51 +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;
|
|
|
|
|
2021-01-26 21:07:51 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2021-12-10 10:21:06 +00:00
|
|
|
import cc.pogoda.mobile.meteosystem.type.web.Trend;
|
|
|
|
import cc.pogoda.mobile.meteosystem.web.RestClientConfig;
|
|
|
|
import cc.pogoda.mobile.meteosystem.web.TrendConsumer;
|
2021-01-26 21:07:51 +00:00
|
|
|
import retrofit2.Response;
|
|
|
|
|
|
|
|
public class TrendDao {
|
|
|
|
|
|
|
|
Response<Trend> trend;
|
|
|
|
|
|
|
|
String station = null;
|
|
|
|
|
|
|
|
class Worker implements Runnable {
|
|
|
|
|
2021-10-16 20:41:14 +00:00
|
|
|
RestClientConfig restClient;
|
|
|
|
|
2021-01-26 21:07:51 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
restClient = new RestClientConfig();
|
|
|
|
|
|
|
|
TrendConsumer trendConsumer = restClient.getWeatherStationClient().create(TrendConsumer.class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
trend = trendConsumer.getTrendForStation(station).execute();
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
2022-01-06 21:06:53 +00:00
|
|
|
Logger.error("[TrendDao][Worker][Exception][e = " + e.getLocalizedMessage() +"]");
|
|
|
|
|
2021-10-16 20:41:14 +00:00
|
|
|
e.printStackTrace();
|
2021-01-26 21:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Trend getStationTrend(String station) {
|
|
|
|
Trend out = new Trend();
|
|
|
|
|
|
|
|
this.station = station;
|
|
|
|
|
|
|
|
Thread thread = new Thread(new Worker());
|
|
|
|
|
|
|
|
thread.start();
|
|
|
|
try {
|
|
|
|
thread.join();
|
|
|
|
|
2022-05-11 15:04:21 +00:00
|
|
|
if (trend != null) {
|
|
|
|
out = trend.body();
|
|
|
|
}
|
2021-01-26 21:07:51 +00:00
|
|
|
} catch (InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-10-16 20:41:14 +00:00
|
|
|
catch (NullPointerException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2021-01-26 21:07:51 +00:00
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|