File tree 5 files changed +51
-1
lines changed
java/org/opentripplanner/client
test/java/org/opentripplanner
5 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 17
17
import org .apache .hc .core5 .http .ContentType ;
18
18
import org .apache .hc .core5 .http .io .entity .StringEntity ;
19
19
import org .opentripplanner .client .model .Agency ;
20
+ import org .opentripplanner .client .model .Alert ;
20
21
import org .opentripplanner .client .model .Pattern ;
21
22
import org .opentripplanner .client .model .Route ;
22
23
import org .opentripplanner .client .model .Stop ;
@@ -152,6 +153,13 @@ public List<Stop> stopSearch(String nameMask) throws IOException {
152
153
return deserializeList (jsonNode , listType (Stop .class ), "/data/stops" );
153
154
}
154
155
156
+ /** Get all alerts. */
157
+ public List <Alert > alerts () throws IOException {
158
+ var query = GraphQLQueries .alerts ();
159
+ final var jsonNode = sendRequest (query );
160
+ return deserializeList (jsonNode , listType (Alert .class ), "/data/alerts" );
161
+ }
162
+
155
163
private <T > T deserialize (JsonNode jsonNode , String path , Class <T > clazz ) throws IOException {
156
164
try {
157
165
var plan = jsonNode .at (path );
Original file line number Diff line number Diff line change
1
+ package org .opentripplanner .client .model ;
2
+
3
+ import com .fasterxml .jackson .annotation .JsonProperty ;
4
+ import java .util .Objects ;
5
+
6
+ public record Alert (
7
+ @ JsonProperty ("alertHeaderText" ) String header ,
8
+ @ JsonProperty ("alertDescriptionText" ) String description ) {
9
+ public Alert {
10
+ Objects .requireNonNull (header );
11
+ Objects .requireNonNull (description );
12
+ }
13
+ }
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ public static String stops() {
33
33
return loadQuery ("stops" );
34
34
}
35
35
36
+ public static String alerts () {
37
+ return loadQuery ("alerts" );
38
+ }
39
+
36
40
private static String loadQuery (String name ) {
37
41
var is =
38
42
GraphQLQueries .class
Original file line number Diff line number Diff line change
1
+ query {
2
+ alerts {
3
+ alertHeaderText
4
+ alertDescriptionText
5
+ alertSeverityLevel
6
+ alertCause
7
+ alertSeverityLevel
8
+ }
9
+ }
Original file line number Diff line number Diff line change @@ -64,7 +64,13 @@ public void plan() throws IOException {
64
64
65
65
var leg = result .itineraries ().get (0 ).legs ().get (0 );
66
66
67
- var transitLeg = result .transitItineraries ().get (0 ).transitLegs ().get (0 );
67
+ var transitLeg =
68
+ result .transitItineraries ().stream ()
69
+ .filter (i -> i .legs ().stream ().anyMatch (l -> !l .intermediatePlaces ().isEmpty ()))
70
+ .findFirst ()
71
+ .get ()
72
+ .transitLegs ()
73
+ .get (0 );
68
74
assertFalse (transitLeg .from ().stop ().isEmpty ());
69
75
assertNotNull (transitLeg .from ().coordinate ());
70
76
assertNotNull (transitLeg .from ().point ());
@@ -365,6 +371,16 @@ public void stops() throws IOException {
365
371
assertNotNull (stop .id ());
366
372
}
367
373
374
+ @ Test
375
+ public void alerts () throws IOException {
376
+ var result = client .alerts ();
377
+
378
+ LOG .info ("Received {} alerts" , result .size ());
379
+
380
+ assertNotNull (result );
381
+ assertFalse (result .isEmpty ());
382
+ }
383
+
368
384
@ Disabled
369
385
@ Test
370
386
public void seattleFares () throws IOException {
You can’t perform that action at this time.
0 commit comments