-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/download openweather data during sensor data fetching (#227)
- Loading branch information
1 parent
101b5f1
commit d2cecd1
Showing
8 changed files
with
262 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/de/app/fivegla/controller/tenant/OpenWeatherController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package de.app.fivegla.controller.tenant; | ||
|
||
import de.app.fivegla.api.Response; | ||
import de.app.fivegla.business.TenantService; | ||
import de.app.fivegla.config.security.marker.TenantCredentialApiAccess; | ||
import de.app.fivegla.controller.api.BaseMappings; | ||
import de.app.fivegla.integration.openweather.OpenWeatherIntegrationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.security.Principal; | ||
import java.time.LocalDate; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(BaseMappings.OPEN_WEATHER) | ||
public class OpenWeatherController implements TenantCredentialApiAccess { | ||
|
||
private final OpenWeatherIntegrationService openWeatherIntegrationService; | ||
private final TenantService tenantService; | ||
|
||
@Operation( | ||
operationId = "open-weather.import", | ||
description = "Imports weather data from OpenWeather.", | ||
tags = BaseMappings.OPEN_WEATHER | ||
) | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "The weather data was imported.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "The request is invalid.", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = Response.class) | ||
) | ||
) | ||
@PostMapping(value = "/import/{sensorId}/{startDateInThePast}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<? extends Response> importOpenWeatherDataFromThePast(@PathVariable @Schema(description = "The sensor ID.") String sensorId, | ||
@PathVariable(value = "startDateInThePast") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDateInThePast, | ||
Principal principal) { | ||
var tenant = validateTenant(tenantService, principal); | ||
log.info("Importing weather data from OpenWeather for sensor '{}'.", sensorId); | ||
openWeatherIntegrationService.importWeatherDataFromThePast(tenant, sensorId, startDateInThePast); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/de/app/fivegla/integration/openweather/dto/Data.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.app.fivegla.integration.openweather.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.ToString; | ||
|
||
/** | ||
* This class represents the current weather data returned by the OpenWeather API. | ||
*/ | ||
@ToString | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Data { | ||
|
||
@JsonProperty("dt") | ||
private long timestamp; | ||
|
||
@JsonProperty("sunrise") | ||
private long sunrise; | ||
|
||
@JsonProperty("sunset") | ||
private long sunset; | ||
|
||
@JsonProperty("temp") | ||
private double temperature; | ||
|
||
@JsonProperty("feels_like") | ||
private double feelsLike; | ||
|
||
@JsonProperty("pressure") | ||
private int pressure; | ||
|
||
@JsonProperty("humidity") | ||
private int humidity; | ||
|
||
@JsonProperty("dew_point") | ||
private double dewPoint; | ||
|
||
@JsonProperty("uvi") | ||
private double uvi; | ||
|
||
@JsonProperty("clouds") | ||
private int clouds; | ||
|
||
@JsonProperty("visibility") | ||
private int visibility; | ||
|
||
@JsonProperty("wind_speed") | ||
private double windSpeed; | ||
|
||
@JsonProperty("wind_deg") | ||
private int windDegree; | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/de/app/fivegla/integration/openweather/dto/OpenWeatherDataFromThePast.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.app.fivegla.integration.openweather.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.ToString; | ||
|
||
/** | ||
* This class represents the data returned by the OpenWeather API. | ||
*/ | ||
@ToString | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class OpenWeatherDataFromThePast { | ||
|
||
@JsonProperty("lat") | ||
private double latitude; | ||
|
||
@JsonProperty("lon") | ||
private double longitude; | ||
|
||
@JsonProperty("timezone") | ||
private String timezone; | ||
|
||
@JsonProperty("timezone_offset") | ||
private int timezoneOffset; | ||
|
||
@JsonProperty("current") | ||
private Data data; | ||
|
||
@JsonProperty("rain.1h") | ||
private double rainWithinOneHour; | ||
|
||
@JsonProperty("snow.1h") | ||
private double snowWithinOneHour; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters