From 8e94568e161dcefb4af858e53d3af6f6ff49aee2 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:04:00 -0400 Subject: [PATCH] fix(OtpRequestProcessor): Use batchId sent by UI for grouping OTP plan requests, instead of creating one. --- .../controllers/api/OtpRequestProcessor.java | 8 ++------ .../middleware/otp/graphql/Query.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java b/src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java index 112013f50..84a57bf9f 100644 --- a/src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java +++ b/src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java @@ -190,12 +190,8 @@ private String proxyPost(Request request, Response response) { * * Other requests will still be proxied, just not stored. */ - QueryVariables queryVariables = getPOJOFromJSON(requestBody, Query.class).variables; - - // Follows the method used in otp-ui core-utils storage.js - String randomBatchId = Integer.toString((int) (Math.random() * 1_000_000_000), 36); - - if (!handlePlanTripResponse(randomBatchId, queryVariables, otpDispatcherResponse, otpUser)) { + Query query = getPOJOFromJSON(requestBody, Query.class); + if (!handlePlanTripResponse(query.batchId, query.variables, otpDispatcherResponse, otpUser)) { logMessageAndHalt( request, HttpStatus.INTERNAL_SERVER_ERROR_500, diff --git a/src/main/java/org/opentripplanner/middleware/otp/graphql/Query.java b/src/main/java/org/opentripplanner/middleware/otp/graphql/Query.java index 7e802eb70..9b5775e2d 100644 --- a/src/main/java/org/opentripplanner/middleware/otp/graphql/Query.java +++ b/src/main/java/org/opentripplanner/middleware/otp/graphql/Query.java @@ -1,7 +1,17 @@ package org.opentripplanner.middleware.otp.graphql; -/** Wraps an OTP GraphQL query data. Field names below are defined by OTP. */ +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * Wraps an OTP GraphQL query data. + * Field names below are defined by OTP, except for batchId which helps group OTP plan requests for a particular search. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class Query { + public String batchId; + public String query; public QueryVariables variables;