Skip to content

Validate to/from in routing request#5164

Merged
t2gran merged 4 commits into
opentripplanner:dev-2.xfrom
entur:otp2_validate_routing_request
Jun 9, 2023
Merged

Validate to/from in routing request#5164
t2gran merged 4 commits into
opentripplanner:dev-2.xfrom
entur:otp2_validate_routing_request

Conversation

@vpaturet
Copy link
Copy Markdown
Contributor

@vpaturet vpaturet commented Jun 5, 2023

Summary

As detailed in #5163, The Transmodel API does not properly report invalid routing requests that do not define the origin or the destination of the search.
This PR adds validation for missing origin or destination in routing requests.
The Transmodel API returns then a specific error message:

{
  "data": {
    "trip": {
      "nextPageCursor": null,
      "previousPageCursor": null,
      "tripPatterns": [],
      "routingErrors": [
        {
          "code": "locationNotFound",
          "inputField": "to",
          "description": "Destination is unknown.  Can you be a bit more descriptive?"
        }
      ]
    }
  }
}

The REST API returns also a specific error message:

	{
    "requestParameters": {
        "date": "04-25-2023",
        "mode": "FLEX_ACCESS,FLEX_EGRESS,TRANSIT",
        "fromPlace": "61.11741770786395,10.451345443725588",
        "time": "2:28pm"
    },
    "error": {
        "id": 450,
        "msg": "Destination is unknown.  Can you be a bit more descriptive?",
        "message": "GEOCODE_TO_NOT_FOUND"
    }

Issue

closes #5163

Unit tests

Added unit tests.

Documentation

No

@vpaturet vpaturet added the !Bug Apply to issues describing a bug and PRs witch fixes it. label Jun 5, 2023
@vpaturet vpaturet self-assigned this Jun 5, 2023
@vpaturet
Copy link
Copy Markdown
Contributor Author

vpaturet commented Jun 5, 2023

@optionsome what would be a test request to check how the GTFS API/Legacy GraphQL API handles the case where to or from are missing?

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2023

Codecov Report

Patch coverage: 25.92% and project coverage change: +0.14 🎉

Comparison is base (ae1aa0b) 65.15% compared to head (eddaf48) 65.29%.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5164      +/-   ##
=============================================
+ Coverage      65.15%   65.29%   +0.14%     
- Complexity     14334    14386      +52     
=============================================
  Files           1750     1750              
  Lines          67759    67833      +74     
  Branches        7205     7217      +12     
=============================================
+ Hits           44145    44294     +149     
+ Misses         21173    21090      -83     
- Partials        2441     2449       +8     
Impacted Files Coverage Δ
...er/ext/transmodelapi/TransmodelGraphQLPlanner.java 0.00% <0.00%> (ø)
.../opentripplanner/api/resource/PlannerResource.java 5.55% <0.00%> (-1.59%) ⬇️
...nner/routing/error/RoutingValidationException.java 22.22% <0.00%> (+22.22%) ⬆️
...ntripplanner/routing/api/request/RouteRequest.java 76.34% <75.00%> (-0.13%) ⬇️
...planner/routing/service/DefaultRoutingService.java 70.00% <100.00%> (+3.33%) ⬆️

... and 39 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@vpaturet vpaturet marked this pull request as ready for review June 6, 2023 07:09
@vpaturet vpaturet requested a review from a team as a code owner June 6, 2023 07:09
@t2gran t2gran added this to the 2.4 (next release) milestone Jun 6, 2023
@t2gran t2gran added the Entur Test This is currently being tested at Entur label Jun 6, 2023
@t2gran t2gran self-requested a review June 6, 2023 13:26
Comment thread src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java Outdated
Comment thread src/main/java/org/opentripplanner/routing/api/request/RouteRequest.java Outdated
Comment thread src/test/java/org/opentripplanner/routing/core/RouteRequestTest.java Outdated
@vpaturet vpaturet force-pushed the otp2_validate_routing_request branch from 1fb1552 to 58ee235 Compare June 6, 2023 14:51
@vpaturet vpaturet requested a review from t2gran June 6, 2023 14:53
t2gran
t2gran previously approved these changes Jun 6, 2023
@hannesj
Copy link
Copy Markdown
Contributor

hannesj commented Jun 6, 2023

This seems to break the travel time API, in which only either to or from is specified

@t2gran
Copy link
Copy Markdown
Member

t2gran commented Jun 7, 2023

This seems to break the travel time API, in which only either to or from is specified

The travel time API does not use the DefaultRoutingService where the validation happens. The Travel time API seems to be broken in dev-2.x - but that is not related to this PR.

This call give this response:

org.opentripplanner.routing.error.RoutingValidationException: RoutingError{code: LOCATION_NOT_FOUND, inputField: FROM_PLACE} RoutingError{code: LOCATION_NOT_FOUND, inputField: FROM_PLACE}
Stacktrace ``` 0:28:42.225 ERROR [grizzly-1] (OTPExceptionMapper.java:58) Unhandled exception org.opentripplanner.routing.error.RoutingValidationException: RoutingError{code: LOCATION_NOT_FOUND, inputField: FROM_PLACE} at org.opentripplanner.street.search.TemporaryVerticesContainer.checkIfVerticesFound(TemporaryVerticesContainer.java:113) at org.opentripplanner.street.search.TemporaryVerticesContainer.(TemporaryVerticesContainer.java:54) at org.opentripplanner.ext.traveltime.TravelTimeResource.getSampleGrid(TravelTimeResource.java:170) at org.opentripplanner.ext.traveltime.TravelTimeResource.getIsochrones(TravelTimeResource.java:142) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:134) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:177) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:81) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244) at org.glassfish.jersey.internal.Errors.process(Errors.java:292) at org.glassfish.jersey.internal.Errors.process(Errors.java:274) at org.glassfish.jersey.internal.Errors.process(Errors.java:244) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:367) at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:190) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515) at java.base/java.lang.Thread.run(Thread.java:833) ```

@leonardehrenfried leonardehrenfried self-requested a review June 8, 2023 14:27
Comment thread src/main/java/org/opentripplanner/routing/error/RoutingValidationException.java Outdated
Copy link
Copy Markdown
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small request.

@t2gran t2gran merged commit 069304b into opentripplanner:dev-2.x Jun 9, 2023
@t2gran t2gran deleted the otp2_validate_routing_request branch June 9, 2023 13:42
t2gran pushed a commit that referenced this pull request Jun 9, 2023
EmmaSimon added a commit to mbta/OpenTripPlanner that referenced this pull request Jun 22, 2023
* Add changelog entry for opentripplanner#5100 [ci skip]

* refactor: Add proper progress tracking for GraphQL timeouts.

* refactor: Fix spelling 'guarantied' -> 'guaranteed'

* review: Fix documentation

* feature: Trace HTTP request headers

* Add changelog entry for opentripplanner#5081 [ci skip]

* Add changelog entry for opentripplanner#5091 [ci skip]

* Add changelog entry for opentripplanner#5133 [ci skip]

* Remove unused code

* Generate full POM for shaded jar [ci skip]

* Add elevation data to Transmodel API

* Finetune elevation format

* Update documentation

* Add changelog entry for opentripplanner#5142 [ci skip]

* fix: Make sure the log key is removed from the Grizzly thread log context

* Apply suggestions from code review

Co-authored-by: Thomas Gran <t2gran@gmail.com>

* Remove San Francisco fare calculator

* Remove TimeBasedVehicleRentalFareService

* Add documentation about deleted calculators

* Remove empty lines

* Refactor null check on from and to vertices

* review: Apply review feedback

* Apply suggestions from code review

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>

* feature: Add sanity check for HTTP header value

The value must match `[^\p{Cntrl}\v]{1,512}`

* test: Add test regular expression for HTTP header value

* Apply suggestions from code review

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>

* feature: Remove batch query from Transmodel API

* refactor: re-generate doc

* fix(deps): update dependency com.google.guava:guava to v32

* fix(deps): update dependency com.graphql-java:graphql-java to v20.3

* Add changelog entry for opentripplanner#5130 [ci skip]

* fix(deps): update dependency com.google.guava:guava to v32

* Use git to figure out last-modified date

* Debug last modified check

* Increase fetch depth

* Make update frequency a Duration

* fix(deps): update dependency com.fasterxml.jackson.core:jackson-annotations to v2.15.2

* Update log messages

* Update docs

* Remove link to 1.x-dev docs

* refactor: Avoid creating builders unnecessary.

* test: Add test for bug in TripRequestMapperTest

* Add changelog entry for opentripplanner#5131 [ci skip]

* Bump serialization version id for opentripplanner#5131

* Add changelog entry for opentripplanner#5141 [ci skip]

* Bump serialization version id for opentripplanner#5141

* Improve money documentation

* Implement stop sequence in GraphQL

* Add stop sequence and test

* Fix docs, formatting and tests

* Add test for walk step mapping

* fix: Fix bug in maxDirectDurationForMode and refactor

 - The code is not DRY, so I refactored it - this also fixes the bug

* refactor: Extract mappers out off PreferencesMapper

* fix(deps): update dependency com.google.cloud:libraries-bom to v26.15.0

* fix(deps): update dependency org.onebusaway:onebusaway-gtfs to v1.4.3

* Make absolute direction optional

* Add test for GraphQL API

* Add changelog entry for opentripplanner#5140 [ci skip]

* Update documentation

* Add changelog entry for opentripplanner#5145 [ci skip]

* Consider level and layer tags when linking public transit stop area nodes

E.g. transit entrances above ground should not get directly linked to subway platforms

* Add test for ensuring that entrances do not link to platforms across different layers/levels

* Update documentation and mapping

* test: Add regression test.

* fix: Fix validation of flex area, assert isComplete and isConsistent, before isStopTimesIncreasing

* refactor: Cleanup AbstractStopTimeAdaptor

* Improve documentation

* Handle stop areas with many platforms properly

Entrances and other unconnected nodes included in stop area relation were
linked only with the first platform area. Now they are matched with all platforms.
Walkable area builder won't create connections if node is outside a platform.

* Update documenation

* Create interline transfers for trips that share the same service date and block

* Connect area boundary to entrance points inside it to prevent pruning

* Add better test data for testing area processing of stop_area relations

* Validate to/from in routing request

* Add changelog entry for opentripplanner#5152 [ci skip]

* Bump serialization version id for opentripplanner#5152

* Stop area linking tests

* Changing default value for earlyStartSec

* Add some documetation about stop area relations

* Fix formatting

* Add support for mapping NeTEx operating day in operating period

* Add error mapping in REST API

* Update documentation

* Add new doc page to mkdocs.yml

* Move getLevel to OSMWithTags andd simplify it

* Test also layer tag relevance in stop area processing

* Fix misleading data report issue content from stop area processing

* Use multimap for storing stop area link nodes

* Remove obsolete issue

Stop area which does not have entrances or other link points is really not any kind of error

* Add changelog entry for opentripplanner#5147 [ci skip]

* Improve updater log messages

* refactor: Apply code review

 - Change `earlyStartSec:int` to `earlyStart:Duration`
 - Add more doc on parameter

* Relax validity check for flex trip with null duration

* Make FlexPath fields final

* refactor: Make `SiriSXUpdaterParameters#timeout` a Duration

* Apply suggestions from code review

* refactor: Make Siri Updaters use Duration, not int, for reminding parameters

 - This also remove a bit of unnecessary mapping code.

* Update src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/SiriSXUpdaterConfig.java

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>

* chore(deps): update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.1.2

* Refactor shutdown hook

* Add changelog entry for opentripplanner#5159 [ci skip]

* Update pull_request_template.md [ci skip]

* fix(deps): update dependency com.graphql-java:graphql-java to v20.4

* Use hashmultimap in  src/main/java/org/opentripplanner/graph_builder/module/osm/OsmDatabase.java>

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>

* Add HashMultimap import

* Refactor first/last date getters

* Split method in two

* Update src/main/java/org/opentripplanner/graph_builder/module/interlining/InterlineProcessor.java

Co-authored-by: Thomas Gran <t2gran@gmail.com>

* More accurate tagging instructions, one example relation linked

* Log warning if GBFS status reports unexpected vehicle type

* Code cleanup

* refactor: Cleanup TransitRouter and AccessEgressMapper

* refactor: Sort values in DurationForEnum.toString to make it deterministic

* refactor: Add State.containsModeWalkOnly() and DefaultAccessEgress.isWalkOnly()

These methods will make it simpler to filter access/egress later

* refactor: Add Duration#requireNonNegative(Duration) : Duration to DurationUtils

* refactor: Implement openingHoursToString() for AccessEgress for testing

Having to brows through many classes and hairy logic is time-consuming when
debugging FLEX access/egress, this simplifies the process.

* refactor: Move RaptorConstants into raptor.api.model package

* feature: Search before the earliest-departure-time in Raptor with searchWindowAccessSlack.

* refactor: Move AccessEgresses to street package

* refactor: Cleanup DoubleUtils

* refactor: Add requireXyz to IntUtils

* refactor: Add Cost value-object

* refactor: Improve int and double utilities

* refactor: Small cleanups

* Apply suggestions from code review

Co-authored-by: Thomas Gran <t2gran@gmail.com>

* Formatting

* Add changelog entry for opentripplanner#5161 [ci skip]

* Add changelog entry for opentripplanner#5162 [ci skip]

* Add changelog entry for opentripplanner#5168 [ci skip]

* Apply review suggestions

* Apply review suggestions

* Fix bicyle optimise type in TransmodelApi

* Add test for optimize type in GraphQL API

* fix(deps): update dependency com.google.guava:guava to v32.0.1-jre

* Add changelog entry for opentripplanner#5167 [ci skip]

* Add reusable method

* Add union type for stop position

* Simplify type resolving

* Use interface type in data fetcher

* Applied review suggestion

* Add documentation

* Add documentation

* Apply review feedback

Co-authored-by: Joel Lappalainen <lappalj8@gmail.com>

* Generate new SiriUpdater doc

* Add changelog entry for opentripplanner#5169 [ci skip]

* Add changelog entry for opentripplanner#5175 [ci skip]

* Add changelog entry for opentripplanner#5164 [ci skip]

* Add changelog entry for opentripplanner#5165 [ci skip]

* review: Remove serialVersionUID

* Validate that from and to temporary vertices are distinct

* review: Extract TestVehicleRentalStationBuilder

* Reduce log severity for non-optimized transfers

* Return an int as the stopPosition for StopTimes

* doc: Move JavaDoc to accessors, fix typo.

* fix: Improve error handling and prevent OTP from going down when connecting to external http services.

The VehicleRentalServiceDirectoryFetcher went down with a IllegalSateException when the
http endpoint failed. Instead of returning null in some error-cases and throwing IOExceptions
in others the HttpUtils is changed to throw an IOException in all cases. This make it more
robust, and the checked exception forces the client to handle it.

* Use Finland OSM mapping as basis for constant speed mapper

* Add support for taxi mode

* Rename ConstansSpeedMapper to describe the new super class

* Add changelog entry for opentripplanner#5153 [ci skip]

* Update micrometer.version to v1.11.1

* Update src/main/java/org/opentripplanner/routing/algorithm/mapping/RaptorPathToItineraryMapper.java

Co-authored-by: Thomas Gran <t2gran@gmail.com>

* Apply review feedback

* Update dependency ch.qos.logback:logback-classic to v1.4.8

* Add changelog entry for opentripplanner#5135 [ci skip]

* Separate words with underscore in osm tag mapper enum value

* Update docs

* Bump serialization version id for opentripplanner#5176

* Make stop area linking more precise and capable to handle elevators

* Add changelog entry for opentripplanner#5181 [ci skip]

* Use EnumSet instead of Stream

* Add changelog entry for opentripplanner#5183 [ci skip]

* Add changelog entry for opentripplanner#5179 [ci skip]

* Fix formatting in RouterConfig.md

* improve: add language argument to Quay and StopPlace types

deprecate lang arguments

* fix: the overloaded getLocale method does not use the language argument

* improve: extract shared code into helper method in transmodel GqlUtil

* add test for GqlUtil.getLocale

* Fix default value for bicycle safety report

* Update dependency org.apache.maven.plugins:maven-shade-plugin to v3.5.0

* Update dependency net.logstash.logback:logstash-logback-encoder to v7.4

* Update dependency org.mockito:mockito-core to v5.4.0

* Add more tests for stop area linking
- Test that elevators get linked
- Test that stop positions will not get linked

* Fix typo

* Update src/main/java/org/opentripplanner/openstreetmap/model/OSMWithTags.java

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>

* Return set

* Update src/main/java/org/opentripplanner/openstreetmap/model/OSMWithTags.java

Co-authored-by: Joel Lappalainen <lappalj8@gmail.com>

* Update src/main/java/org/opentripplanner/openstreetmap/model/OSMWithTags.java

Co-authored-by: Joel Lappalainen <lappalj8@gmail.com>

* Add changelog entry for opentripplanner#5166 [ci skip]

---------

Co-authored-by: Leonard Ehrenfried <mail@leonard.io>
Co-authored-by: OTP Changelog Bot <changelog-bot@opentripplanner.org>
Co-authored-by: Thomas Gran <t2gran@gmail.com>
Co-authored-by: vpaturet <46598384+vpaturet@users.noreply.github.com>
Co-authored-by: Vincent Paturet <vincent.paturet@entur.org>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: OTP Serialization Version Bot <serialization-version-bot@opentripplanner.org>
Co-authored-by: Vesa Meskanen <vesa.meskanen@cgi.com>
Co-authored-by: Joel Lappalainen <lappalj8@gmail.com>
Co-authored-by: Lasse Tyrihjell <lassetyr@gmail.com>
Co-authored-by: Vesa Meskanen <vesa@realsoft.com>
Co-authored-by: Tom Erik Støwer <testower@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Bug Apply to issues describing a bug and PRs witch fixes it. Entur Test This is currently being tested at Entur

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing to/from validation of routing request

4 participants