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

Implement SIRI Lite #6284

Open
wants to merge 25 commits into
base: dev-2.x
Choose a base branch
from

Conversation

leonardehrenfried
Copy link
Member

@leonardehrenfried leonardehrenfried commented Nov 27, 2024

Summary

Implements the SIRI Light flavour (as opposed to the request/response one that Entur and Skanetrafiken uses). This means that the entire SIRI feed is downloaded in a single GET request.

Issue

Closes #6263

Documentation

The new updater is fully documented and I took the liberty to make all references to SIRI consistent in the docs.

Unit tests

Some added, but it's mostly wiring. I'm happy to add more if requested but generally we don't test the HTTP layer a lot.

cc @rcavaliere @Jouca

@leonardehrenfried leonardehrenfried added New Feature Real-Time Update The issue/PR is related to RealTime updates labels Nov 27, 2024
@leonardehrenfried leonardehrenfried requested a review from a team as a code owner November 27, 2024 12:51
@leonardehrenfried leonardehrenfried force-pushed the siri-light branch 2 times, most recently from 6afe592 to bf2fcf2 Compare November 27, 2024 12:56
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 37.34177% with 99 lines in your changes missing coverage. Please review.

Project coverage is 69.77%. Comparing base (cd254bf) to head (defdf5f).
Report is 29 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...ater/siri/updater/configure/SiriUpdaterModule.java 0.00% 40 Missing ⚠️
...i/updater/lite/SiriETLiteHttpTripUpdateSource.java 0.00% 21 Missing ⚠️
...planner/updater/configure/UpdaterConfigurator.java 0.00% 8 Missing and 2 partials ⚠️
...ripplanner/updater/siri/updater/SiriETUpdater.java 0.00% 9 Missing ⚠️
...ripplanner/updater/siri/updater/SiriSXUpdater.java 0.00% 7 Missing ⚠️
...dater/siri/updater/SiriETHttpTripUpdateSource.java 0.00% 3 Missing ⚠️
...siri/updater/lite/SiriETLiteUpdaterParameters.java 25.00% 3 Missing ⚠️
...siri/updater/lite/SiriSXLiteUpdaterParameters.java 25.00% 3 Missing ⚠️
...routerconfig/updaters/SiriETLiteUpdaterConfig.java 95.45% 1 Missing ⚠️
...routerconfig/updaters/SiriSXLiteUpdaterConfig.java 95.45% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6284      +/-   ##
=============================================
- Coverage      69.81%   69.77%   -0.05%     
- Complexity     17825    17841      +16     
=============================================
  Files           2020     2028       +8     
  Lines          76271    76384     +113     
  Branches        7806     7806              
=============================================
+ Hits           53250    53298      +48     
- Misses         20304    20370      +66     
+ Partials        2717     2716       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried leonardehrenfried changed the title Implement SIRI light Implement SIRI Light Nov 28, 2024
@leonardehrenfried
Copy link
Member Author

@habrahamsson-skanetrafiken Can I ask you to review this one? If not let me know and I will reassign.

@leonardehrenfried
Copy link
Member Author

It never occurred to me until yesterday's meeting that I also could have made the current updater/loader configurable. Let me know if you feel that's the better option, @t2gran.

@leonardehrenfried leonardehrenfried changed the title Implement SIRI Light Implement SIRI Lite Dec 3, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good to me. Just a few typos.

@Override
public Optional<Siri> getUpdates() {
try {
var siri = siriLoader.fetchETFeed(DUMMY_REQUESTOR_REF);
Copy link
Contributor

Choose a reason for hiding this comment

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

This dummy parameter is a little bit of a code smell. But it seems to be the simplest solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative would be to make the parameter nullable.

Choose a reason for hiding this comment

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

The issue seems to be that it's required for one implementation and not required for the other implementations. So making it nullable isn't 100% accurate either. IMO sending a dummy value is a good enough solution.

Co-authored-by: Henrik Abrahamsson <[email protected]>
@t2gran t2gran added this to the 2.7 (next release) milestone Dec 11, 2024
Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

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

I read through most of the main code - not all. The wiring can be improved, so I will wait with the rest of the review to that is done.

/**
* Feed id that is used to match trip ids in the TripUpdates
*/
private final String feedId;
Copy link
Member

Choose a reason for hiding this comment

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

Is this unused, or is it the SIRI namespace?

Copy link
Member Author

@leonardehrenfried leonardehrenfried Dec 11, 2024

Choose a reason for hiding this comment

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

It was a reference to the actual id of the feed and unused.

.toString();
}

private static SiriLoader createLoader(Parameters parameters) {
Copy link
Member

Choose a reason for hiding this comment

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

DRY - This can be refactored out. Either create a SiriLoaderFactory or create it in the UpdatorConfigurator and pass it in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've done both in c7bf5ed

@leonardehrenfried leonardehrenfried force-pushed the siri-light branch 2 times, most recently from 1ab52da to c7bf5ed Compare December 11, 2024 20:42
@t2gran
Copy link
Member

t2gran commented Dec 12, 2024

Here is what I had in mind with respect to manual Dependency Injection:

package org.opentripplanner.updater.siri.configure;

/** This is doing manually dependency injection and work as a factory to create the updater components. */
class SiriUpdaterModule {

   public static SiriETUpdater createSiriETUpdater(...) {
     var loader = createLoader(...);    
     var source = createSource(loader, ...);
     return createETUpdater(source, ...);
   }

  private static createLoader(...);    
  private static createSource(...);
  private static createUpdater(...);
}

Each component define the parameters as an interface inside the class. The same parameters can be repeated, but not inherited. For example if URI uri() is used in Loader and Updater both interfaces have the same method. Then the implementation of these 3 interfaces can be passed to all 3, but each class only see the set of parameters they need. If the main class (Updator) inherit an other class and that has a Parameters inside, then the main parameter will inherit that. In other words, the Parameters classes follow the same inheritance structure as the outer main class.
A extends B ==> A.Parameters extends B.Parameters.

The factory for creating the Loader can be inlined here. The SiriUpdaterModule reduce the dependencies and remove DI code from the Updaters constructors.

@leonardehrenfried
Copy link
Member Author

@t2gran I have introduce the DI class that you requested in defdf5f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature Real-Time Update The issue/PR is related to RealTime updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SIRI Lite
3 participants