This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Tan generation refactoring #264
Open
damirseit
wants to merge
3
commits into
corona-warn-app:master
Choose a base branch
from
damirseit:tan_generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/app/coronawarn/verification/factories/tan/verifier/HashedGuidTanVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.domain.VerificationAppSession; | ||
import app.coronawarn.verification.exception.VerificationServerException; | ||
import app.coronawarn.verification.model.HashedGuid; | ||
import app.coronawarn.verification.model.LabTestResult; | ||
import app.coronawarn.verification.model.TanSourceOfTrust; | ||
import app.coronawarn.verification.model.TestResult; | ||
import app.coronawarn.verification.service.TestResultServerService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.util.StopWatch; | ||
|
||
public class HashedGuidTanVerifier extends TanVerifier { | ||
@Override | ||
public void generateTan(VerificationAppSession appSession, | ||
TestResultServerService testResultServerService, | ||
StopWatch stopWatch, | ||
TanSourceOfTrust tanSourceOfTrust) { | ||
TestResult covidTestResult = testResultServerService.result(new HashedGuid(appSession.getHashedGuid())); | ||
if (covidTestResult.getTestResult() != LabTestResult.POSITIVE.getTestResult() | ||
&& covidTestResult.getTestResult() != LabTestResult.QUICK_POSITIVE.getTestResult() | ||
) { | ||
stopWatch.stop(); | ||
throw new VerificationServerException(HttpStatus.BAD_REQUEST, | ||
"Tan cannot be created, caused by the non positive result of the labserver"); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/app/coronawarn/verification/factories/tan/verifier/TanVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.domain.VerificationAppSession; | ||
import app.coronawarn.verification.model.TanSourceOfTrust; | ||
import app.coronawarn.verification.service.TestResultServerService; | ||
import org.springframework.util.StopWatch; | ||
|
||
public abstract class TanVerifier { | ||
public abstract void generateTan(VerificationAppSession appSession, | ||
TestResultServerService testResultServerService, | ||
StopWatch stopWatch, | ||
TanSourceOfTrust tanSourceOfTrust); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/app/coronawarn/verification/factories/tan/verifier/TanVerifierFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.model.AppSessionSourceOfTrust; | ||
|
||
public interface TanVerifierFactory { | ||
public TanVerifier makeTanVerifier(AppSessionSourceOfTrust appSessionSourceOfTrust); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/app/coronawarn/verification/factories/tan/verifier/TanVerifierFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.model.AppSessionSourceOfTrust; | ||
|
||
public class TanVerifierFactoryImpl implements TanVerifierFactory { | ||
@Override | ||
public TanVerifier makeTanVerifier(AppSessionSourceOfTrust appSessionSourceOfTrust) { | ||
switch (appSessionSourceOfTrust) { | ||
case HASHED_GUID: | ||
return new HashedGuidTanVerifier(); | ||
case TELETAN: | ||
return new TeletanTanVerifier(); | ||
default: | ||
return new UnknownTanVerifier(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/app/coronawarn/verification/factories/tan/verifier/TeletanTanVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.domain.VerificationAppSession; | ||
import app.coronawarn.verification.model.TanSourceOfTrust; | ||
import app.coronawarn.verification.service.TestResultServerService; | ||
import org.springframework.util.StopWatch; | ||
|
||
public class TeletanTanVerifier extends TanVerifier { | ||
|
||
@Override | ||
public void generateTan(VerificationAppSession appSession, | ||
TestResultServerService testResultServerService, | ||
StopWatch stopWatch, | ||
TanSourceOfTrust tanSourceOfTrust) { | ||
tanSourceOfTrust = TanSourceOfTrust.TELETAN; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/app/coronawarn/verification/factories/tan/verifier/UnknownTanVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package app.coronawarn.verification.factories.tan.verifier; | ||
|
||
import app.coronawarn.verification.domain.VerificationAppSession; | ||
import app.coronawarn.verification.exception.VerificationServerException; | ||
import app.coronawarn.verification.model.TanSourceOfTrust; | ||
import app.coronawarn.verification.service.TestResultServerService; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.util.StopWatch; | ||
|
||
public class UnknownTanVerifier extends TanVerifier { | ||
@Override | ||
public void generateTan(VerificationAppSession appSession, | ||
TestResultServerService testResultServerService, | ||
StopWatch stopWatch, | ||
TanSourceOfTrust tanSourceOfTrust) { | ||
stopWatch.stop(); | ||
throw new VerificationServerException(HttpStatus.BAD_REQUEST, | ||
"Unknown source of trust inside the appsession for the registration token"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Spring Dependency Injection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @f11h ,
Thank you very much for your feedback! I appreciate it.
I have pushed the changes into the branch.