Skip to content

feat!: deprecate -f #851

Merged
lionel-nj merged 19 commits intomasterfrom
optional-feed-name
Apr 20, 2021
Merged

feat!: deprecate -f #851
lionel-nj merged 19 commits intomasterfrom
optional-feed-name

Conversation

@lionel-nj
Copy link
Copy Markdown
Contributor

closes #539

Summary:

This PR provides support to make -f an optional argument when running the validator. This is required to run the validator programatically for:

  • integration to the MobilityDatabase
  • integration tests purpose

Expected behavior:

if -f is now optional. If provided, phone numbers will be validated according to the country code, else phone number validation is skipped.

No NPEs should be thrown.

Please make sure these boxes are checked before submitting your pull request - thanks!

- handle possible NPEs
- extend unit tests
@lionel-nj lionel-nj self-assigned this Apr 14, 2021
@lionel-nj lionel-nj requested a review from barbeau April 14, 2021 15:12
@lionel-nj lionel-nj changed the title feat: make -f an optional cLI argument feat: make -f an optional CLI argument Apr 14, 2021
@lionel-nj lionel-nj added this to the v2.1 milestone Apr 14, 2021
@lionel-nj lionel-nj mentioned this pull request Apr 14, 2021
4 tasks
Copy link
Copy Markdown
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

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

I support making -f optional but I'm not convinced that wrapping null within GtfsFeedName is the right way to approach this. Seems dangerous and prone to future NPEs.

Instead, I think a better approach would be to have a new -c command line parameter for country code and truly make -f optional, and deprecate it in future releases (unless we see other value in keeping it). If either are provided you can validate phone number, and if neither are provided you skip that rule.

lionel-nj added 2 commits April 14, 2021 17:14
- implement -c
  - implement new class CountryCode
    - adjust existing code to use this instead of GtfsFeedName
- add unit tests
- make phone number validation conditional
- adjust country code definition in tests
- up small caps in tests
@lionel-nj lionel-nj requested a review from barbeau April 14, 2021 21:18
@lionel-nj lionel-nj changed the title feat: make -f an optional CLI argument feat: deprecate -f Apr 14, 2021
@aababilov
Copy link
Copy Markdown
Collaborator

aababilov commented Apr 14, 2021

Thanks for working in that direction!

One more thing came to my mind. Let's remove the monolithic ValidationContext and inject only direct dependencies.

"Inject only direct dependencies" is one of the main DI principles at Google. Here is what it means.

This approach is not recommended:

public class ShowBudgets {
   private final Account account;

   @Inject
   ShowBudgets(Customer customer) {
     account = customer.getPurchasingAccount();
   }

This one is preferred:

public class ShowBudgets {
   private final Account account;

   @Inject
   ShowBudgets(Account account) {
     this.account = account;
   }

So, instead of injecting ValidationContext, we should inject the CountryCode instead.
We probably should not inject ZonedDateTime but we need a wrapper class for it (say, CurrentDateTime) because ZonedDateTime does not have a semantic that it is the current datetime.

This change will also simplify our unit tests since they will not have to create the full ValidationContext which may grow in the future.

How does that sound?

@lionel-nj
Copy link
Copy Markdown
Contributor Author

lionel-nj commented Apr 15, 2021

How does that sound?

Good to me! 👍🏾
Opened #853 to this extent.

Edit: This is implemented in #855

Copy link
Copy Markdown
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

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

Thanks @lionel-nj! Some comments in-line. The README and other docs also need to be updated.

lionel-nj added 3 commits April 15, 2021 10:27
@lionel-nj lionel-nj requested a review from barbeau April 15, 2021 14:33
Copy link
Copy Markdown
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

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

Thanks @lionel-nj, some thoughts in-line.

@barbeau
Copy link
Copy Markdown
Member

barbeau commented Apr 15, 2021

Oh, if this is a breaking change, the commit/PR title should include a ! - https://www.conventionalcommits.org/en/v1.0.0/

@lionel-nj lionel-nj changed the title feat: deprecate -f feat!: deprecate -f Apr 15, 2021
TODO: remove mocks
@lionel-nj
Copy link
Copy Markdown
Contributor Author

Removing mocks from CliParametersAnalyzerTest in #854

@lionel-nj lionel-nj requested a review from barbeau April 15, 2021 17:05
Copy link
Copy Markdown
Collaborator

@aababilov aababilov left a comment

Choose a reason for hiding this comment

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

Nice, can't wait to see it merged!

lionel-nj added 7 commits April 20, 2021 10:23
# Conflicts:
#	core/src/main/java/org/mobilitydata/gtfsvalidator/parsing/RowParser.java
#	core/src/test/java/org/mobilitydata/gtfsvalidator/parsing/RowParserTest.java
#	processor/src/main/java/org/mobilitydata/gtfsvalidator/processor/TableLoaderGenerator.java
- use special code ZZ for unknown or invalid territories
  - adapt unit tests
- override toString
- remove support for null value
@lionel-nj
Copy link
Copy Markdown
Contributor Author

lionel-nj commented Apr 20, 2021

Thanks @aababilov for reviewing! I provided the changes you suggested in the previous commits. At the exception of this one: #851 (comment)

private static final String ZZ = "ZZ";

Since we do not have support for null, I made this constant public, so that we can access from the main method in order to avoid NPE.

@lionel-nj lionel-nj requested a review from aababilov April 20, 2021 15:46
@aababilov
Copy link
Copy Markdown
Collaborator

Beautiful! Please format the code and submit it, I can't wait to see it in upstream!

google-java-format -i $(find . -name '*.java')

@lionel-nj
Copy link
Copy Markdown
Contributor Author

Thanks @aababilov for this feedback!

@lionel-nj lionel-nj requested a review from aababilov April 20, 2021 20:48
Copy link
Copy Markdown
Member

@barbeau barbeau left a comment

Choose a reason for hiding this comment

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

Nice work @lionel-nj! 👍

@lionel-nj lionel-nj merged commit d7fa7d4 into master Apr 20, 2021
@lionel-nj lionel-nj deleted the optional-feed-name branch April 20, 2021 20:48
@isabelle-dr isabelle-dr modified the milestones: v2.1, v3.0.0 Oct 28, 2021
@isabelle-dr isabelle-dr mentioned this pull request Oct 28, 2021
4 tasks
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.

Make -f an optional command-line parameter

5 participants