From 9a65a99e81b32d68fc6e59bb74a3f9508271c6bd Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 8 May 2024 07:26:57 +0300 Subject: [PATCH 01/10] Remove duplicate of feedImpl typeWiring --- .../java/org/opentripplanner/apis/gtfs/GtfsGraphQLIndex.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/GtfsGraphQLIndex.java b/src/main/java/org/opentripplanner/apis/gtfs/GtfsGraphQLIndex.java index 1fd78765a07..53d53b9bc4b 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/GtfsGraphQLIndex.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/GtfsGraphQLIndex.java @@ -129,7 +129,6 @@ protected static GraphQLSchema buildSchema() { .type(typeWiring.build(DepartureRowImpl.class)) .type(typeWiring.build(elevationProfileComponentImpl.class)) .type(typeWiring.build(FeedImpl.class)) - .type(typeWiring.build(FeedImpl.class)) .type(typeWiring.build(GeometryImpl.class)) .type(typeWiring.build(ItineraryImpl.class)) .type(typeWiring.build(LegImpl.class)) From 0ba5df5269168b86cf5819e94d45fe895135970a Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 8 May 2024 07:28:57 +0300 Subject: [PATCH 02/10] Data fetchers for publisherName and publisherUrl of FeedInfo class --- .../apis/gtfs/datafetchers/FeedImpl.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java index 7d7c62136b6..6cf8d27b262 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java @@ -64,6 +64,22 @@ public DataFetcher feedId() { return this::getSource; } + @Override + public DataFetcher publisherName() { + return environment -> { + String id = getSource(environment); + return getTransitService(environment).getFeedInfo(id).getPublisherName(); + }; + } + + @Override + public DataFetcher publisherUrl() { + return environment -> { + String id = getSource(environment); + return getTransitService(environment).getFeedInfo(id).getPublisherUrl(); + }; + } + private List getAgencies(DataFetchingEnvironment environment) { String id = getSource(environment); return getTransitService(environment) From c43b8d56ecaab1a164500f6fd16d4add58a04669 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 8 May 2024 07:30:59 +0300 Subject: [PATCH 03/10] Update gtfs graphql schema --- .../resources/org/opentripplanner/apis/gtfs/schema.graphqls | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index 56f3528d6e3..b81ebdff4c7 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -984,6 +984,12 @@ type Feed { """List of agencies which provide data to this feed""" agencies: [Agency] + """Name of feed publisher""" + publisherName: String! + + """Web address of feed publisher""" + publisherUrl: String! + """ Alerts relevant for the feed. """ From 4b9b06592b2c433357d637683d45e7ae96682a93 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 8 May 2024 07:49:16 +0300 Subject: [PATCH 04/10] Update generated GraphQLDataFetchers.java --- .../apis/gtfs/generated/GraphQLDataFetchers.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 559acac920d..6a2e398cd91 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -380,6 +380,10 @@ public interface GraphQLFeed { public DataFetcher> alerts(); public DataFetcher feedId(); + + public DataFetcher publisherName(); + + public DataFetcher publisherUrl(); } public interface GraphQLGeometry { From 119927ea79af4a4ee511de71309da9d29a30f140 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 8 May 2024 12:43:55 +0300 Subject: [PATCH 05/10] Add test for feedinfo query --- .../apis/gtfs/GraphQLIntegrationTest.java | 14 ++++++++++++++ .../apis/gtfs/expectations/feedinfo.json | 16 ++++++++++++++++ .../apis/gtfs/queries/feedinfo.graphql | 10 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json create mode 100644 src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql diff --git a/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java b/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java index fcc59af845f..614c8778c6b 100644 --- a/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java +++ b/src/test/java/org/opentripplanner/apis/gtfs/GraphQLIntegrationTest.java @@ -43,6 +43,7 @@ import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.framework.i18n.NonLocalizedString; import org.opentripplanner.framework.model.Grams; +import org.opentripplanner.model.FeedInfo; import org.opentripplanner.model.fare.FareMedium; import org.opentripplanner.model.fare.FareProduct; import org.opentripplanner.model.fare.ItineraryFares; @@ -84,6 +85,7 @@ import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.BikeAccess; import org.opentripplanner.transit.model.network.TripPattern; +import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.model.site.StopLocation; import org.opentripplanner.transit.model.timetable.RealTimeTripTimes; @@ -151,6 +153,18 @@ static void setup() { transitModel.addTripPattern(id("pattern-1"), pattern); + var feedId = "testfeed"; + var feedInfo = FeedInfo.dummyForTest(feedId); + transitModel.addFeedInfo(feedInfo); + + var agency = Agency + .of(new FeedScopedId(feedId, "agency-xx")) + .withName("speedtransit") + .withUrl("www.otp-foo.bar") + .withTimezone("Europe/Berlin") + .build(); + transitModel.addAgency(agency); + transitModel.initTimeZone(ZoneIds.BERLIN); transitModel.index(); var routes = Arrays diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json new file mode 100644 index 00000000000..a3dbe43b0f1 --- /dev/null +++ b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json @@ -0,0 +1,16 @@ +{ + "data" : { + "feeds" : [ + { + "agencies" : [ + { + "name" : "speedtransit", + "url" : "www.otp-foo.bar" + } + ], + "publisherUrl" : "www.z.org", + "publisherName" : "publisher" + } + ] + } +} \ No newline at end of file diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql b/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql new file mode 100644 index 00000000000..f0737202786 --- /dev/null +++ b/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql @@ -0,0 +1,10 @@ +{ + feeds { + agencies { + name + url + } + publisherUrl + publisherName + } +} \ No newline at end of file From 659c9bee44724781fd5b58b673c47ca48fd4845a Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Tue, 14 May 2024 16:02:59 +0300 Subject: [PATCH 06/10] Collect feed info publisher data into object --- .../apis/gtfs/datafetchers/FeedImpl.java | 16 ++++++---------- .../gtfs/generated/GraphQLDataFetchers.java | 9 +++++++-- .../model/organization/FeedPublisher.java | 10 ++++++++++ .../opentripplanner/apis/gtfs/schema.graphqls | 19 ++++++++++++++----- .../apis/gtfs/expectations/feedinfo.json | 6 ++++-- .../apis/gtfs/queries/feedinfo.graphql | 6 ++++-- 6 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java index 6cf8d27b262..47b0fc7e106 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java @@ -13,6 +13,7 @@ import org.opentripplanner.routing.alertpatch.TransitAlert; import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.transit.model.organization.Agency; +import org.opentripplanner.transit.model.organization.FeedPublisher; import org.opentripplanner.transit.service.TransitService; public class FeedImpl implements GraphQLDataFetchers.GraphQLFeed { @@ -65,18 +66,13 @@ public DataFetcher feedId() { } @Override - public DataFetcher publisherName() { + public DataFetcher publisher() { return environment -> { String id = getSource(environment); - return getTransitService(environment).getFeedInfo(id).getPublisherName(); - }; - } - - @Override - public DataFetcher publisherUrl() { - return environment -> { - String id = getSource(environment); - return getTransitService(environment).getFeedInfo(id).getPublisherUrl(); + return new FeedPublisher( + getTransitService(environment).getFeedInfo(id).getPublisherName(), + getTransitService(environment).getFeedInfo(id).getPublisherUrl() + ); }; } diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 6a2e398cd91..455503ad8ef 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -381,9 +381,14 @@ public interface GraphQLFeed { public DataFetcher feedId(); - public DataFetcher publisherName(); + public DataFetcher publisher(); + } + + /** Feed publisher information */ + public interface GraphQLFeedPublisher { + public DataFetcher name(); - public DataFetcher publisherUrl(); + public DataFetcher url(); } public interface GraphQLGeometry { diff --git a/src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java b/src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java new file mode 100644 index 00000000000..6c9a120e81b --- /dev/null +++ b/src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java @@ -0,0 +1,10 @@ +package org.opentripplanner.transit.model.organization; + +import java.util.Objects; + +public record FeedPublisher(String name, String url) { + public FeedPublisher { + Objects.requireNonNull(name); + Objects.requireNonNull(url); + } +} diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index b81ebdff4c7..15de75f5408 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -974,6 +974,18 @@ type fareComponent { routes: [Route] @deprecated } + +""" +Feed publisher information +""" +type FeedPublisher { + """Name of feed publisher""" + name: String! + + """Web address of feed publisher""" + url: String! +} + """ A feed provides routing data (stops, routes, timetables, etc.) from one or more public transport agencies. """ @@ -984,11 +996,8 @@ type Feed { """List of agencies which provide data to this feed""" agencies: [Agency] - """Name of feed publisher""" - publisherName: String! - - """Web address of feed publisher""" - publisherUrl: String! + """publisher""" + publisher: FeedPublisher! """ Alerts relevant for the feed. diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json index a3dbe43b0f1..3cf3bd06d66 100644 --- a/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json +++ b/src/test/resources/org/opentripplanner/apis/gtfs/expectations/feedinfo.json @@ -8,8 +8,10 @@ "url" : "www.otp-foo.bar" } ], - "publisherUrl" : "www.z.org", - "publisherName" : "publisher" + "publisher" : { + "name" : "publisher", + "url" : "www.z.org" + } } ] } diff --git a/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql b/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql index f0737202786..68516d26237 100644 --- a/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql +++ b/src/test/resources/org/opentripplanner/apis/gtfs/queries/feedinfo.graphql @@ -4,7 +4,9 @@ name url } - publisherUrl - publisherName + publisher { + name + url + } } } \ No newline at end of file From c1d8f5be03a8b802f43ec308a30c32da8aa7cbaf Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Wed, 15 May 2024 08:19:34 +0300 Subject: [PATCH 07/10] Move FeedPublisher class to more suitable directory path --- .../org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java | 2 +- .../model/organization => apis/gtfs/model}/FeedPublisher.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/org/opentripplanner/{transit/model/organization => apis/gtfs/model}/FeedPublisher.java (76%) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java index 47b0fc7e106..9c5b17a62e2 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java @@ -9,11 +9,11 @@ import org.opentripplanner.apis.gtfs.GraphQLRequestContext; import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes; +import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.routing.alertpatch.EntitySelector; import org.opentripplanner.routing.alertpatch.TransitAlert; import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.transit.model.organization.Agency; -import org.opentripplanner.transit.model.organization.FeedPublisher; import org.opentripplanner.transit.service.TransitService; public class FeedImpl implements GraphQLDataFetchers.GraphQLFeed { diff --git a/src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java b/src/main/java/org/opentripplanner/apis/gtfs/model/FeedPublisher.java similarity index 76% rename from src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java rename to src/main/java/org/opentripplanner/apis/gtfs/model/FeedPublisher.java index 6c9a120e81b..ba524b537f0 100644 --- a/src/main/java/org/opentripplanner/transit/model/organization/FeedPublisher.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/model/FeedPublisher.java @@ -1,4 +1,4 @@ -package org.opentripplanner.transit.model.organization; +package org.opentripplanner.apis.gtfs.model; import java.util.Objects; From db9d8748996959aef4bb91062f09aef9f8e20319 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Mon, 27 May 2024 13:32:42 +0300 Subject: [PATCH 08/10] Add FeedPublisher type mapping --- .../org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java | 2 +- .../apis/gtfs/generated/GraphQLDataFetchers.java | 3 ++- .../opentripplanner/apis/gtfs/generated/graphql-codegen.yml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java index 9c5b17a62e2..d6488d3f375 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/FeedImpl.java @@ -66,7 +66,7 @@ public DataFetcher feedId() { } @Override - public DataFetcher publisher() { + public DataFetcher publisher() { return environment -> { String id = getSource(environment); return new FeedPublisher( diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 455503ad8ef..fbfc4965c62 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -20,6 +20,7 @@ import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRelativeDirection; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode; +import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; @@ -381,7 +382,7 @@ public interface GraphQLFeed { public DataFetcher feedId(); - public DataFetcher publisher(); + public DataFetcher publisher(); } /** Feed publisher information */ diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml b/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml index 55f76863cc6..29c2bff0257 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/graphql-codegen.yml @@ -56,6 +56,7 @@ config: elevationProfileComponent: org.opentripplanner.model.plan.ElevationProfile.Step Emissions: org.opentripplanner.model.plan.Emissions#Emissions Feed: String + FeedPublisher: org.opentripplanner.apis.gtfs.model.FeedPublisher#FeedPublisher Geometry: org.locationtech.jts.geom.Geometry#Geometry InputField: org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLInputField#GraphQLInputField Itinerary: org.opentripplanner.model.plan.Itinerary#Itinerary From 01e2a14fe45e7f22f40aa2b2690208a1849a61f1 Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Tue, 28 May 2024 12:17:35 +0300 Subject: [PATCH 09/10] Make FeedPublisher nullable --- .../resources/org/opentripplanner/apis/gtfs/schema.graphqls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index 15de75f5408..0ea8899ba32 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -997,7 +997,7 @@ type Feed { agencies: [Agency] """publisher""" - publisher: FeedPublisher! + publisher: FeedPublisher """ Alerts relevant for the feed. From a1818037c4db49fa8d83d656c8d797edf11cd43b Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Tue, 28 May 2024 15:14:25 +0300 Subject: [PATCH 10/10] Update src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls Co-authored-by: Leonard Ehrenfried --- .../resources/org/opentripplanner/apis/gtfs/schema.graphqls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index 0ea8899ba32..41ed352ebf1 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -996,7 +996,7 @@ type Feed { """List of agencies which provide data to this feed""" agencies: [Agency] - """publisher""" + "The publisher of the input transit data." publisher: FeedPublisher """