From d31cc3fccc9ce8db3cb21b05569d60e3cdfc8b23 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 23 Mar 2020 23:44:00 +0100 Subject: [PATCH 1/2] added type to location data-model --- .../java/de/sakpaas/backend/dto/LocationApiSearchDAS.java | 1 - .../sakpaas/backend/dto/LocationSearchOSMResultDto.java | 4 ++++ .../de/sakpaas/backend/dto/LocationSearchOutputDto.java | 8 +++++--- src/main/java/de/sakpaas/backend/dto/TagsDto.java | 6 ++++-- src/main/java/de/sakpaas/backend/model/Location.java | 3 +++ .../java/de/sakpaas/backend/service/LocationMapper.java | 6 +++--- .../de/sakpaas/backend/service/OccupancyServiceTest.java | 7 ++----- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/sakpaas/backend/dto/LocationApiSearchDAS.java b/src/main/java/de/sakpaas/backend/dto/LocationApiSearchDAS.java index 0aa9b0a4..143a249e 100644 --- a/src/main/java/de/sakpaas/backend/dto/LocationApiSearchDAS.java +++ b/src/main/java/de/sakpaas/backend/dto/LocationApiSearchDAS.java @@ -37,7 +37,6 @@ public List getLocationByCoordinates(Double latitude public List getLocationsForCountry(String countryCode) { final String url = "https://overpass-api.de/api/interpreter?data=[out:json][timeout:2500];area(3600051477)->." + "searchArea;(node[\"shop\"=\"supermarket\"](area.searchArea);way[\"shop\"=\"supermarket\"](area.searchArea););out center;"; - RestTemplate restTemplate = new RestTemplate(); ResponseEntity response = restTemplate.getForEntity(url, ApiResultDto.class); diff --git a/src/main/java/de/sakpaas/backend/dto/LocationSearchOSMResultDto.java b/src/main/java/de/sakpaas/backend/dto/LocationSearchOSMResultDto.java index fd2b1c2a..efcde0ce 100644 --- a/src/main/java/de/sakpaas/backend/dto/LocationSearchOSMResultDto.java +++ b/src/main/java/de/sakpaas/backend/dto/LocationSearchOSMResultDto.java @@ -54,4 +54,8 @@ public String getCountry() { return tags.getCountry(); } + public String getType() { + return tags.getType(); + } + } diff --git a/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java b/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java index 523482fd..25aa6765 100644 --- a/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java +++ b/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java @@ -2,11 +2,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Getter; @Getter -@JsonPropertyOrder({"id", "name", "occupancy", "latitude", "longitude"}) +//@JsonPropertyOrder({"id", "name", "occupancy", "latitude", "longitude", "type"}) public class LocationSearchOutputDto { private long id; private String name; @@ -18,6 +17,7 @@ public class LocationSearchOutputDto { private String postcode; private String city; private String country; + private String type; @JsonCreator public LocationSearchOutputDto(@JsonProperty("id") long id, @@ -29,7 +29,8 @@ public LocationSearchOutputDto(@JsonProperty("id") long id, @JsonProperty("housenumber") String housenumber, @JsonProperty("postcode") String postcode, @JsonProperty("city") String city, - @JsonProperty("country") String country) { + @JsonProperty("country") String country, + @JsonProperty("type") String type) { this.id = id; if (name == null) { this.name = "Supermarkt"; @@ -44,6 +45,7 @@ public LocationSearchOutputDto(@JsonProperty("id") long id, this.postcode = postcode; this.city = city; this.country = country; + this.type = type; } } diff --git a/src/main/java/de/sakpaas/backend/dto/TagsDto.java b/src/main/java/de/sakpaas/backend/dto/TagsDto.java index e1fc06c5..f890d014 100644 --- a/src/main/java/de/sakpaas/backend/dto/TagsDto.java +++ b/src/main/java/de/sakpaas/backend/dto/TagsDto.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Getter; -@JsonPropertyOrder({"name", "addr:street", "addr:place", "addr:housenumber", "addr:postcode", "addr:city", "addr:country"}) +@JsonPropertyOrder({"name", "addr:street", "addr:place", "addr:housenumber", "addr:postcode", "addr:city", "addr:country", "shop"}) @Getter public class TagsDto { private String name; @@ -14,18 +14,20 @@ public class TagsDto { private String postcode; private String city; private String country; + private String type; @JsonCreator public TagsDto(@JsonProperty("name") String name, @JsonProperty("addr:street") String street, @JsonProperty("addr:housenumber") String housenumber, @JsonProperty("addr:postcode") String postcode, @JsonProperty("addr:city") String city, @JsonProperty("addr:country") String country, - @JsonProperty("addr:place") String place) { + @JsonProperty("addr:place") String place, @JsonProperty("shop") String type) { this.name = name; this.street = street != null ? street : place; this.housenumber = housenumber; this.postcode = postcode; this.city = city; this.country = country; + this.type = type; } } diff --git a/src/main/java/de/sakpaas/backend/model/Location.java b/src/main/java/de/sakpaas/backend/model/Location.java index 7104069f..8d8d2ad0 100644 --- a/src/main/java/de/sakpaas/backend/model/Location.java +++ b/src/main/java/de/sakpaas/backend/model/Location.java @@ -43,5 +43,8 @@ public class Location { @Column(name = "COUNTRY") private String country; + @Column(name = "TYPE") + private String type; + } diff --git a/src/main/java/de/sakpaas/backend/service/LocationMapper.java b/src/main/java/de/sakpaas/backend/service/LocationMapper.java index deca451b..e4e581a2 100644 --- a/src/main/java/de/sakpaas/backend/service/LocationMapper.java +++ b/src/main/java/de/sakpaas/backend/service/LocationMapper.java @@ -25,7 +25,7 @@ public LocationSearchOutputDto mapToOutputDto(Location location) { return new LocationSearchOutputDto(location.getId(), location.getName(), occupancyService.getAverageOccupancy(location), location.getLatitude(), location.getLongitude(), location.getStreet(), - location.getHousenumber(), location.getPostcode(), location.getCity(), location.getCountry()); + location.getHousenumber(), location.getPostcode(), location.getCity(), location.getCountry(), location.getType()); } public LocationSearchOutputDto mapToOutputDto(LocationSearchOSMResultDto apiResult) { @@ -35,7 +35,7 @@ public LocationSearchOutputDto mapToOutputDto(LocationSearchOSMResultDto apiResu return new LocationSearchOutputDto(apiResult.getId(), apiResult.getName(), null, apiResult.getLat(), apiResult.getLon(), apiResult.getStreet(), apiResult.getHousenumber(), apiResult.getPostcode(), - apiResult.getCity(), apiResult.getCountry()); + apiResult.getCity(), apiResult.getCountry(), apiResult.getType()); } public Location mapToLocation(LocationSearchOSMResultDto apiResult) { @@ -47,6 +47,6 @@ public Location mapToLocation(LocationSearchOSMResultDto apiResult) { .orElseGet(() -> new Location(apiResult.getId(), apiResult.getName() != null ? apiResult.getName() : "Supermarkt", apiResult.getLat(), apiResult.getLon(), apiResult.getStreet(), apiResult.getHousenumber(), - apiResult.getPostcode(), apiResult.getCity(), apiResult.getCountry())); + apiResult.getPostcode(), apiResult.getCity(), apiResult.getCountry(), apiResult.getType())); } } diff --git a/src/test/java/de/sakpaas/backend/service/OccupancyServiceTest.java b/src/test/java/de/sakpaas/backend/service/OccupancyServiceTest.java index b898b937..f6db6e51 100644 --- a/src/test/java/de/sakpaas/backend/service/OccupancyServiceTest.java +++ b/src/test/java/de/sakpaas/backend/service/OccupancyServiceTest.java @@ -3,17 +3,14 @@ import de.sakpaas.backend.model.Location; import de.sakpaas.backend.model.Occupancy; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest @ComponentScan @@ -21,7 +18,7 @@ class OccupancyServiceTest { @Test void getAverageOccupancy() { - Location location = new Location(1829487L, "LIDL", 42.0, 8.0, null, null, null, null, null); + Location location = new Location(1829487L, "LIDL", 42.0, 8.0, null, null, null, null, null, null); ZonedDateTime time = ZonedDateTime.now(); List occupancyList = new ArrayList<>(); From 9e36d22b8843c673b3ea24f1966be832847ed243 Mon Sep 17 00:00:00 2001 From: Joost Date: Tue, 24 Mar 2020 21:02:07 +0100 Subject: [PATCH 2/2] Fixed JsonPropertyOrder --- .../java/de/sakpaas/backend/dto/LocationSearchOutputDto.java | 3 ++- src/main/resources/application.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java b/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java index 25aa6765..37b3a2d1 100644 --- a/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java +++ b/src/main/java/de/sakpaas/backend/dto/LocationSearchOutputDto.java @@ -2,10 +2,11 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Getter; @Getter -//@JsonPropertyOrder({"id", "name", "occupancy", "latitude", "longitude", "type"}) +@JsonPropertyOrder({"id", "name", "occupancy", "lat", "lon", "street", "housenumber", "postcode", "city", "country", "type"}) public class LocationSearchOutputDto { private long id; private String name; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 579a2926..1efb173a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,7 +8,7 @@ spring: datasource: url: jdbc:postgresql://localhost:5432/postgres username: postgres - password: zuschwer + password: SAKPaaS app: presence: duration: 20