#59 -- send time series to remove service
parent
0dc4dc46d7
commit
bca338e2ee
@ -0,0 +1,13 @@
|
||||
package ru.ulstu.extractor.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@Configuration
|
||||
public class WebClientConfiguration {
|
||||
@Bean
|
||||
public WebClient webClient(WebClient.Builder webClientBuilder) {
|
||||
return webClientBuilder.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ru.ulstu.extractor.http;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class HttpService {
|
||||
private final Logger log = LoggerFactory.getLogger(HttpService.class);
|
||||
private final WebClient client;
|
||||
|
||||
public HttpService(WebClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public JSONObject post(String url, JSONObject postData) {
|
||||
log.debug("Service call: {}", url);
|
||||
JSONObject response = new JSONObject(Optional.ofNullable(client
|
||||
.post()
|
||||
.uri(url)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(postData.toString()))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.retrieve()
|
||||
.bodyToMono(String.class)
|
||||
.block()).orElse("{response:\"empty\"}"));
|
||||
log.debug("Service response: {}", response);
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package ru.ulstu.extractor.http;
|
||||
|
||||
import ru.ulstu.extractor.model.TimeSeries;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JsonTimeSeries {
|
||||
private String name;
|
||||
private List<JsonTimeSeriesValue> values;
|
||||
|
||||
public JsonTimeSeries(TimeSeries timeSeries) {
|
||||
this.name = timeSeries.getName();
|
||||
this.values = timeSeries.getValues()
|
||||
.stream()
|
||||
.map(JsonTimeSeriesValue::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<JsonTimeSeriesValue> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public void setValues(List<JsonTimeSeriesValue> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package ru.ulstu.extractor.http;
|
||||
|
||||
import ru.ulstu.extractor.model.TimeSeriesValue;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class JsonTimeSeriesValue {
|
||||
private LocalDateTime date;
|
||||
private Double value;
|
||||
|
||||
public JsonTimeSeriesValue(TimeSeriesValue timeSeriesValue) {
|
||||
this.value = timeSeriesValue.getValue();
|
||||
this.date = timeSeriesValue.getDate()
|
||||
.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
|
||||
public LocalDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDateTime date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue