Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to bugsnag and generic api controller #72

Merged
merged 23 commits into from
Oct 12, 2020
Merged

Conversation

landonreed
Copy link
Contributor

@landonreed landonreed commented Sep 10, 2020

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JavaDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

Adds pagination to bugsnag (our dev instance currently returns thousands of records) and the generic API controller. otp-admin-ui PR is ibi-group/otp-admin-ui#23 (still need changes in otp-react-redux)

@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2020

Codecov Report

Merging #72 into dev will increase coverage by 0.27%.
The diff coverage is 65.26%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev      #72      +/-   ##
============================================
+ Coverage     47.74%   48.02%   +0.27%     
- Complexity      325      329       +4     
============================================
  Files            81       82       +1     
  Lines          2260     2299      +39     
  Branches        256      256              
============================================
+ Hits           1079     1104      +25     
- Misses         1054     1070      +16     
+ Partials        127      125       -2     
Impacted Files Coverage Δ Complexity Δ
.../middleware/controllers/api/BugsnagController.java 57.14% <0.00%> (-2.86%) 3.00 <0.00> (ø)
...entripplanner/middleware/models/MonitoredTrip.java 65.07% <ø> (ø) 21.00 <0.00> (ø)
...opentripplanner/middleware/models/TripRequest.java 81.25% <ø> (-1.11%) 5.00 <0.00> (-1.00)
...iddleware/tripMonitor/jobs/MonitorAllTripsJob.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...anner/middleware/persistence/TypedPersistence.java 52.00% <33.33%> (+2.72%) 18.00 <3.00> (+3.00)
...rg/opentripplanner/middleware/utils/HttpUtils.java 56.36% <50.00%> (-0.78%) 13.00 <3.00> (+2.00) ⬇️
.../middleware/controllers/response/ResponseList.java 75.00% <75.00%> (ø) 3.00 <3.00> (?)
...nner/middleware/controllers/api/ApiController.java 55.22% <80.76%> (+5.64%) 8.00 <0.00> (ø)
...dleware/controllers/api/TripHistoryController.java 72.72% <94.44%> (+6.06%) 4.00 <1.00> (-1.00) ⬆️
.../opentripplanner/middleware/OtpMiddlewareMain.java 55.10% <100.00%> (ø) 7.00 <1.00> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b9d54a...530f20e. Read the comment docs.

@landonreed landonreed marked this pull request as ready for review September 22, 2020 20:57
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

I will need to test some more. For now, the obvious changes are documenting the request parameters, and there is probably a way to request a subset of the data directly from Mongo and/or Bugsnag.

Copy link
Contributor

@br648 br648 left a comment

Choose a reason for hiding this comment

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

Looks good so approving.

@br648 br648 removed their assignment Sep 29, 2020
Comment on lines 115 to 116
String route = HttpUtils.getRequiredQueryParamFromRequest(request, "route", false);
String route = getQueryParamFromRequest(request, "route", false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using static imports like this might actually be a bad practice. See this perspective here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is your recommendation? That we qualify the method call with the util class? I'm fine with that, but we should define an approach for our projects generally on this. Perhaps we should create an issue and handle that in a separate project-wide PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss with the team together sometime and then if we decide we want to do this, then we can handle all the changes in another PR.

responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/AdminUser[]"
$ref: "#/definitions/ResponseList"
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose this is a little better than the AdminUser[] type since the definition for that was just an empty object. It might be out of scope for this PR, but it would be nice to have the swagger docs include refs to the proper object in an array.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@evansiroky Note that AdminUser is a subclass of AbstractUser, but spark-swagger ignores inherited fields at the time this was implemented. We insert inherited fields into the AdminUserswagger type using the PublicApiDocGenerator class.

data:
type: "array"
items:
type: "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be incorrect since at the very least the items will be an object. It might be necessary to have separate ResponseList types that include the correct reference to the subclass that they return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@binh-dam-ibigroup, do you have any thoughts on how to ammend this swagger def?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The most thorough way to handle this would be to change the document generator class to create a ResponseList_Subtype object definition for each of the ResponseList responses we are publishing. We can also try creating a separate descendant of ResponseBody per @evansiroky's suggestion above and see how spark-swagger handles that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To follow up on my comment above, you could modify class PublicApiDocsGenerator to do the following:

  • Scan all ResponseList return entries in the autogenerated swagger.
  • For each instance, find the type of the elements in the list from one of the parent elements.
  • Generate a custom return type definition that correspond to ResponseList<type>
  • Replace ResponseList with the custom type generated above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Further discussion should be had in #85

Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

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

See comments

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Some light documentation updates, then it should be good to go.

responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/AdminUser[]"
$ref: "#/definitions/ResponseList"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@evansiroky Note that AdminUser is a subclass of AbstractUser, but spark-swagger ignores inherited fields at the time this was implemented. We insert inherited fields into the AdminUserswagger type using the PublicApiDocGenerator class.

@binh-dam-ibigroup binh-dam-ibigroup removed their assignment Oct 1, 2020
Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

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

  • Build is failing
  • PR has merge conflicts
  • Figuring out documentation of ResponseList typing seems to be unresolved

@evansiroky evansiroky removed their assignment Oct 5, 2020
@binh-dam-ibigroup
Copy link
Collaborator

Does a dependency need to be updated for the build to pass?

@codecov-io
Copy link

Codecov Report

Merging #72 into dev will increase coverage by 0.36%.
The diff coverage is 67.61%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev      #72      +/-   ##
============================================
+ Coverage     47.74%   48.11%   +0.36%     
- Complexity      325      329       +4     
============================================
  Files            81       82       +1     
  Lines          2260     2305      +45     
  Branches        256      256              
============================================
+ Hits           1079     1109      +30     
- Misses         1054     1071      +17     
+ Partials        127      125       -2     
Impacted Files Coverage Δ Complexity Δ
...entripplanner/middleware/models/MonitoredTrip.java 65.07% <ø> (ø) 21.00 <0.00> (ø)
...opentripplanner/middleware/models/TripRequest.java 81.25% <ø> (-1.11%) 5.00 <0.00> (-1.00)
...iddleware/tripMonitor/jobs/MonitorAllTripsJob.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...anner/middleware/persistence/TypedPersistence.java 52.00% <33.33%> (+2.72%) 18.00 <3.00> (+3.00)
.../middleware/controllers/api/BugsnagController.java 62.50% <35.71%> (+2.50%) 3.00 <0.00> (ø)
...rg/opentripplanner/middleware/utils/HttpUtils.java 56.36% <50.00%> (-0.78%) 13.00 <3.00> (+2.00) ⬇️
.../middleware/controllers/response/ResponseList.java 73.68% <73.68%> (ø) 3.00 <3.00> (?)
...nner/middleware/controllers/api/ApiController.java 55.22% <81.48%> (+5.64%) 8.00 <0.00> (ø)
...dleware/controllers/api/TripHistoryController.java 72.72% <94.73%> (+6.06%) 4.00 <1.00> (-1.00) ⬆️
.../opentripplanner/middleware/OtpMiddlewareMain.java 55.10% <100.00%> (ø) 7.00 <1.00> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b9d54a...7c1e133. Read the comment docs.

@landonreed landonreed merged commit 75b1e06 into dev Oct 12, 2020
@landonreed landonreed deleted the add-pagination branch October 12, 2020 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants