Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

#183: Use configuration classes instead of @value annotations #238

Merged
merged 20 commits into from
May 23, 2020

Conversation

indyaah
Copy link
Contributor

@indyaah indyaah commented May 21, 2020

No description provided.

this.diagnosisKeyService = diagnosisKeyService;
this.retentionDays = distributionServiceConfig.getRetentionDays();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasnt sure if this would be an acceptable pattern but started with it thinking this would be least intrusive change to service/controller layer.

Would love to see/explore better design.

(Applies to most changes)

}

public Integer getMaxNumberOfKeys() {
return payload.getMaxNumberOfKeys();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more design decision that needs critical review/thought.

Idea was to abstract away complexities (additional classes/getters) in configuration structure and only expose single contract outside.

Applies to DistributionServiceConfig as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

When abstracting the payload away, you will lose the information that getMaxNumberOfKeys refers to the payload. Then you would need to rename this to getMaxNumberOfPayloadKeys. Not sure if this is worth it. But if there is some redundant more complex operations done on the properties across the code, then this could be moved to this class.

Maybe @ConstructorBinding should be used to prevent in incomplete object that could result in NPEs (e.g. in `return payload.getMaxNumberOfKeys();).

Also, @ConfigurationProperties can be annotated with @Validated which will actually crash the app at start-up time with a proper readable error message in case non-optional properties are missing:

https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-validation

@ole-lilienthal ole-lilienthal linked an issue May 21, 2020 that may be closed by this pull request
@pithumke pithumke mentioned this pull request May 21, 2020
@pithumke
Copy link
Member

Hi @indyaah,
your PR looks really great so far, thanks for your support! Could you please do us a huge favor and also include configuration properties for the signature information, once #240 is merged? I tried to already incorporate @ConfigurationProperties in that PR but didn't have any luck with it (and can't look into it anymore because of time constraints). I pushed my attempt to 7d752e8 and added a comment here: #183 (comment).

@indyaah
Copy link
Contributor Author

indyaah commented May 22, 2020

@pithumke : Definitely, will incorporate 240 changes once it's merged. Thanks for the references.


@Value("${services.submission.payload.max-number-of-keys}")
private Integer maxNumberOfKeys;
@Autowired
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned before, @Autowired is not required at constructors when there is only one constructor.

@stevesap stevesap added the community This item is well suited to be worked on by the community. label May 22, 2020
@pithumke
Copy link
Member

Hi @indyaah,
#240 has been merged and #272 is on its way to master.

// N = fakeDelayMovingAverageSamples.
private Double initialFakeDelayMilliseconds;
private Double fakeDelayMovingAverageSamples;
private Integer retentionDays;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to use java.time.Duration instead of int. Spring Boot should convert the input automatically. Using Duration in DiagnosisKey would make the implementation easier. Something like
return Duration.between(Instant.ofEpochMilli(rollingStartNumber), Instant.now()) .compareTo(durationToRetain) <= 0;

Copy link
Member

Choose a reason for hiding this comment

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

Hey @elch78,
thanks for the feedback! Yes I guess you are right and we should use domain specific types where ever possible. However, please understand that the purpose of this PR is to "only" remove the @Value annotations and not to much more refactoring above that. Since this PR is already clocking in at almost 1000 LOC delta, I kindly ask you to create an issue for this so we can pick it up in a separate (more manageable) PR. Thanks! :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree

@pithumke
Copy link
Member

Closes #207

@pithumke pithumke merged commit 576fd8b into corona-warn-app:master May 23, 2020
@pithumke
Copy link
Member

pithumke commented May 23, 2020

Big thank you to all community contributors, you rock! 🚀 ⭐ ❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community This item is well suited to be worked on by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use configuration classes instead of @Value annotations
8 participants