Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c2080d

Browse files
committed
Add geometry filter flag to Event API calls
1 parentcbf6075 commit7c2080d

File tree

6 files changed

+78
-36
lines changed

6 files changed

+78
-36
lines changed

‎src/main/java/io/kontur/disasterninja/client/EventApiClient.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
importcom.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
importio.kontur.disasterninja.dto.EventFeedDto;
5+
importio.kontur.disasterninja.dto.GeometryFilterType;
56
importio.kontur.disasterninja.dto.eventapi.EventApiEventDto;
67
importio.kontur.disasterninja.service.KeycloakAuthorizationService;
78
importio.micrometer.core.annotation.Timed;
@@ -47,10 +48,14 @@ public List<EventFeedDto> getUserFeeds() {
4748
returnOptional.ofNullable(response.getBody()).orElseGet(List::of);
4849
}
4950

50-
publicOptional<EventApiSearchEventResponse>getEvents(StringeventApiFeed,OffsetDateTimeafter,List<BigDecimal>bbox,intpageSize,SortOrdersortOrder) {
51+
publicOptional<EventApiSearchEventResponse>getEvents(StringeventApiFeed,OffsetDateTimeafter,
52+
List<BigDecimal>bbox,intpageSize,
53+
SortOrdersortOrder,GeometryFilterTypegeometryFilterType) {
5154
UriComponentsBuilderuriBuilder =UriComponentsBuilder.fromUriString(EVENT_API_EVENT_LIST_URI);
5255
uriBuilder.queryParam("episodeFilterType","NONE");
5356
uriBuilder.queryParam("sortOrder",Objects.requireNonNullElse(sortOrder,"ASC"));
57+
uriBuilder.queryParam("geometryFilterType",
58+
Objects.requireNonNullElse(geometryFilterType,GeometryFilterType.ALL));
5459

5560
if (after !=null) {
5661
uriBuilder.queryParam("after",after.atZoneSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
@@ -97,7 +102,8 @@ public List<EventApiEventDto> getLatestEvents(List<String> acceptableTypes, Stri
97102
}
98103

99104
@Timed(value ="events.getEvent",histogram =true)
100-
publicEventApiEventDtogetEvent(UUIDeventId,StringeventApiFeed,booleanincludeEpisodes) {
105+
publicEventApiEventDtogetEvent(UUIDeventId,StringeventApiFeed,booleanincludeEpisodes,
106+
GeometryFilterTypegeometryFilterType) {
101107
if (eventId ==null) {
102108
returnnull;
103109
}
@@ -107,6 +113,8 @@ public EventApiEventDto getEvent(UUID eventId, String eventApiFeed, boolean incl
107113
}else {
108114
uriBuilder.queryParam("episodeFilterType","NONE");
109115
}
116+
uriBuilder.queryParam("geometryFilterType",
117+
Objects.requireNonNullElse(geometryFilterType,GeometryFilterType.ALL));
110118
ResponseEntity<EventApiEventDto>response =restTemplate
111119
.exchange(uriBuilder.build(eventApiFeed,eventId).toString(),HttpMethod.GET,httpEntityWithUserOrDefaultBearerAuth(null),
112120
newParameterizedTypeReference<>() {

‎src/main/java/io/kontur/disasterninja/controller/EventsController.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
importio.kontur.disasterninja.dto.EventEpisodeListDto;
77
importio.kontur.disasterninja.dto.EventFeedDto;
88
importio.kontur.disasterninja.dto.EventListDto;
9+
importio.kontur.disasterninja.dto.GeometryFilterType;
910
importio.kontur.disasterninja.service.EventApiService;
1011
importio.kontur.disasterninja.service.UserProfileService;
1112
importio.swagger.v3.oas.annotations.Operation;
@@ -56,9 +57,12 @@ public List<EventListDto> getListOfEvent(
5657
"The coordinate reference system of the values is WGS 84 longitude/latitude (http://www.opengis.net/def/crs/OGC/1.3/CRS84). For WGS 84 longitude/latitude the values are the sequence of minimum longitude, minimum latitude, maximum longitude and maximum latitude.")
5758
@RequestParam(required =false)
5859
@ValidBbox
59-
List<BigDecimal>bbox
60+
List<BigDecimal>bbox,
61+
@Parameter(description ="Geometry filter type",example ="ALL")
62+
@RequestParam(defaultValue ="ALL")
63+
GeometryFilterTypegeometryFilterType
6064
) {
61-
List<EventListDto>events =service.getEvents(feed,bbox);
65+
List<EventListDto>events =service.getEvents(feed,bbox,geometryFilterType);
6266
if (offset >=events.size()) {
6367
thrownewWebApplicationException("Offset is larger than resultset size",HttpStatus.NO_CONTENT);
6468
}
@@ -73,8 +77,9 @@ public List<EventListDto> getListOfEvent(
7377
@ApiResponse(responseCode ="200",description ="Successful operation",content =@Content(mediaType ="application/json",schema =@Schema(implementation =EventDto.class)))
7478
@ApiResponse(responseCode ="404",description ="Event is not found",content =@Content(mediaType ="application/json"))
7579
@GetMapping("/{feed}/{eventId}")
76-
publicEventDtogetEvent(@PathVariableUUIDeventId,@PathVariableStringfeed) {
77-
returnservice.getEvent(eventId,feed);
80+
publicEventDtogetEvent(@PathVariableUUIDeventId,@PathVariableStringfeed,
81+
@RequestParam(defaultValue ="ALL")GeometryFilterTypegeometryFilterType) {
82+
returnservice.getEvent(eventId,feed,geometryFilterType);
7883
}
7984

8085
@Operation(tags ="Events",summary ="Returns event episodes")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
packageio.kontur.disasterninja.dto;
2+
3+
publicenumGeometryFilterType {
4+
ALL,
5+
NONE
6+
}

‎src/main/java/io/kontur/disasterninja/service/EventApiService.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
importio.kontur.disasterninja.dto.EventEpisodeListDto;
77
importio.kontur.disasterninja.dto.EventFeedDto;
88
importio.kontur.disasterninja.dto.EventListDto;
9+
importio.kontur.disasterninja.dto.GeometryFilterType;
910
importio.kontur.disasterninja.dto.eventapi.EventApiEventDto;
1011
importio.kontur.disasterninja.service.converter.EventDtoConverter;
1112
importio.kontur.disasterninja.service.converter.EventListEventDtoConverter;
@@ -36,22 +37,26 @@ public EventApiService(EventApiClient client, @Value("${kontur.platform.event-ap
3637
}
3738

3839
publicList<EventListDto>getEvents(Stringfeed,List<BigDecimal>bbox) {
40+
returngetEvents(feed,bbox,GeometryFilterType.ALL);
41+
}
42+
43+
publicList<EventListDto>getEvents(Stringfeed,List<BigDecimal>bbox,GeometryFilterTypegeometryFilterType) {
3944
OffsetDateTimeafter =OffsetDateTime.now().minusDays(4).truncatedTo(ChronoUnit.HOURS);
4045
Optional<EventApiClient.EventApiSearchEventResponse>eventsResponse =client.getEvents(feed,after,bbox,
41-
pageSize,EventApiClient.SortOrder.ASC);
46+
pageSize,EventApiClient.SortOrder.ASC,geometryFilterType);
4247

4348
List<EventApiEventDto>events =newArrayList<>();
4449
if (eventsResponse.isEmpty() ||eventsResponse.get().getData().size() <pageSize) {
4550
//in case of the amount of events in the last 4 days is less than pageSize than gather the latest 1000 events
46-
events.addAll(client.getEvents(feed,null,bbox,pageSize,EventApiClient.SortOrder.DESC)
51+
events.addAll(client.getEvents(feed,null,bbox,pageSize,EventApiClient.SortOrder.DESC,geometryFilterType)
4752
.orElse(newEventApiClient.EventApiSearchEventResponse())
4853
.getData());
4954
}else {
5055
events.addAll(eventsResponse.get().getData());
5156
after =eventsResponse.get().getPageMetadata().getNextAfterValue();
5257

5358
while (true) {
54-
eventsResponse =client.getEvents(feed,after,bbox,pageSize,EventApiClient.SortOrder.ASC);
59+
eventsResponse =client.getEvents(feed,after,bbox,pageSize,EventApiClient.SortOrder.ASC,geometryFilterType);
5560
if (eventsResponse.isEmpty() ||CollectionUtils.isEmpty(eventsResponse.get().getData())) {
5661
break;
5762
}
@@ -69,15 +74,19 @@ public List<EventListDto> getEvents(String feed, List<BigDecimal> bbox) {
6974
}
7075

7176
publicEventDtogetEvent(UUIDeventId,Stringfeed) {
72-
EventApiEventDtoevent =client.getEvent(eventId,feed,false);
77+
returngetEvent(eventId,feed,GeometryFilterType.ALL);
78+
}
79+
80+
publicEventDtogetEvent(UUIDeventId,Stringfeed,GeometryFilterTypegeometryFilterType) {
81+
EventApiEventDtoevent =client.getEvent(eventId,feed,false,geometryFilterType);
7382
if (event ==null) {
7483
thrownewWebApplicationException("Event " +eventId +" is not found",HttpStatus.NOT_FOUND);
7584
}
7685
returnEventDtoConverter.convert(event);
7786
}
7887

7988
publicList<EventEpisodeListDto>getEventEpisodes(UUIDeventId,Stringfeed) {
80-
EventApiEventDtoevent =client.getEvent(eventId,feed,true);
89+
EventApiEventDtoevent =client.getEvent(eventId,feed,true,GeometryFilterType.ALL);
8190
if (event ==null) {
8291
thrownewWebApplicationException("Event " +eventId +" is not found",HttpStatus.NOT_FOUND);
8392
}

‎src/test/java/io/kontur/disasterninja/client/EventApiClientTest.java‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageio.kontur.disasterninja.client;
22

3+
importio.kontur.disasterninja.dto.GeometryFilterType;
34
importio.kontur.disasterninja.dto.eventapi.EventApiEventDto;
45
importorg.junit.jupiter.api.Test;
56
importorg.springframework.beans.factory.annotation.Autowired;
@@ -49,7 +50,8 @@ public void testGetEventsWithoutBbox() {
4950
server.expect(ExpectedCount.times(2),r ->assertThat(r.getURI().toString(),
5051
matchesRegex(Pattern.compile(
5152
"/v1/\\?feed=testFeedName&severities=EXTREME,SEVERE,MODERATE&limit=1000" +
52-
"&episodeFilterType=NONE&sortOrder=ASC&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:\\d{2}:\\d{2}.\\d+Z"))))
53+
"&episodeFilterType=NONE&sortOrder=ASC&geometryFilterType=ALL" +
54+
"&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:\\d{2}:\\d{2}.\\d+Z"))))
5355
.andExpect(method(HttpMethod.GET))
5456
.andExpect(header(HttpHeaders.AUTHORIZATION,"Bearer " +getUserToken()))
5557
.andRespond(r -> {
@@ -76,7 +78,8 @@ public void testGetEventsTruncateAfterToHours() {
7678
server.expect(ExpectedCount.times(2),r ->assertThat(r.getURI().toString(),
7779
matchesRegex(Pattern.compile(
7880
"/v1/\\?feed=testFeedName&severities=EXTREME,SEVERE,MODERATE&limit=1000" +
79-
"&episodeFilterType=NONE&sortOrder=ASC&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:00:00Z"))))
81+
"&episodeFilterType=NONE&sortOrder=ASC&geometryFilterType=ALL" +
82+
"&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:00:00Z"))))
8083
.andExpect(method(HttpMethod.GET))
8184
.andExpect(header(HttpHeaders.AUTHORIZATION,"Bearer " +getUserToken()))
8285
.andRespond(r -> {
@@ -104,7 +107,8 @@ public void testGetEventsWithBbox() {
104107
server.expect(ExpectedCount.times(2),r ->assertThat(r.getURI().toString(),
105108
matchesRegex(Pattern.compile(
106109
"/v1/\\?feed=testFeedName&severities=EXTREME,SEVERE,MODERATE&limit=1000" +
107-
"&episodeFilterType=NONE&sortOrder=DESC&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:\\d{2}:\\d{2}.\\d+Z" +
110+
"&episodeFilterType=NONE&sortOrder=DESC&geometryFilterType=ALL" +
111+
"&after=\\d{4}-\\d{2}-\\d{2}[tT]\\d{2}:\\d{2}:\\d{2}.\\d+Z" +
108112
"&bbox=1.1&bbox=2.2&bbox=3.3&bbox=4.4"))))
109113
.andExpect(method(HttpMethod.GET))
110114
.andExpect(header(HttpHeaders.AUTHORIZATION,"Bearer " +getUserToken()))
@@ -133,7 +137,8 @@ public void testGetEventsWithoutAfter() {
133137
server.expect(ExpectedCount.times(2),r ->assertThat(r.getURI().toString(),
134138
matchesRegex(Pattern.compile(
135139
"/v1/\\?feed=testFeedName&severities=EXTREME,SEVERE,MODERATE&limit=1000" +
136-
"&episodeFilterType=NONE&sortOrder=ASC&bbox=1.1&bbox=2.2&bbox=3.3&bbox=4.4"))))
140+
"&episodeFilterType=NONE&sortOrder=ASC&geometryFilterType=ALL" +
141+
"&bbox=1.1&bbox=2.2&bbox=3.3&bbox=4.4"))))
137142
.andExpect(method(HttpMethod.GET))
138143
.andExpect(header(HttpHeaders.AUTHORIZATION,"Bearer " +getUserToken()))
139144
.andRespond(r -> {
@@ -184,14 +189,14 @@ public void testGetEvent() throws IOException {
184189
//given
185190
givenJwtTokenIs("JwtTestToken");
186191
server.expect(ExpectedCount.once(),
187-
requestTo("/v1/event?feed=testFeedName&eventId=1ec05e2b-7d18-490c-ac9f-c33609fdc7a7&episodeFilterType=ANY"))
192+
requestTo("/v1/event?feed=testFeedName&eventId=1ec05e2b-7d18-490c-ac9f-c33609fdc7a7&episodeFilterType=ANY&geometryFilterType=ALL"))
188193
.andExpect(method(HttpMethod.GET))
189194
.andExpect(header("Authorization","Bearer " +getUserToken()))
190195
.andRespond(withSuccess(readFile(this,"EventApiClientTest.testGetEvent.response.json"),
191196
MediaType.APPLICATION_JSON));
192197
//when
193198
EventApiEventDtoevent =client.getEvent(UUID.fromString("1ec05e2b-7d18-490c-ac9f-c33609fdc7a7"),
194-
"testFeedName",true);
199+
"testFeedName",true,GeometryFilterType.ALL);
195200

196201
//then
197202
verify(securityContext,times(1)).getAuthentication();
@@ -204,14 +209,14 @@ public void testGetEventWithoutEpisodes() throws IOException {
204209
//given
205210
givenJwtTokenIs("JwtTestToken");
206211
server.expect(ExpectedCount.once(),
207-
requestTo("/v1/event?feed=testFeedName&eventId=1ec05e2b-7d18-490c-ac9f-c33609fdc7a7&episodeFilterType=NONE"))
212+
requestTo("/v1/event?feed=testFeedName&eventId=1ec05e2b-7d18-490c-ac9f-c33609fdc7a7&episodeFilterType=NONE&geometryFilterType=ALL"))
208213
.andExpect(method(HttpMethod.GET))
209214
.andExpect(header("Authorization","Bearer " +getUserToken()))
210215
.andRespond(withSuccess(readFile(this,"EventApiClientTest.testGetEvent.response.json"),
211216
MediaType.APPLICATION_JSON));
212217
//when
213218
EventApiEventDtoevent =client.getEvent(UUID.fromString("1ec05e2b-7d18-490c-ac9f-c33609fdc7a7"),
214-
"testFeedName",false);
219+
"testFeedName",false,GeometryFilterType.ALL);
215220

216221
//then
217222
verify(securityContext,times(1)).getAuthentication();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp