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

Tan generation refactoring #264

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Michael Schulte [mschulte-tsi], T-Systems International GmbH
Lars Stelzner [lstelzne-tech], T-Systems International GmbH
Andreas Mandel [amandel], T-Systems International GmbH
Martin Scheffler [martinschefflerTSI] T-Systems International GmbH
Damir Seit [damirseit], Nazarbayev University
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import app.coronawarn.verification.config.VerificationApplicationConfig;
import app.coronawarn.verification.domain.VerificationAppSession;
import app.coronawarn.verification.exception.VerificationServerException;
import app.coronawarn.verification.factories.tan.verifier.TanVerifier;
import app.coronawarn.verification.factories.tan.verifier.TanVerifierFactory;
import app.coronawarn.verification.factories.tan.verifier.TanVerifierFactoryImpl;
import app.coronawarn.verification.model.AppSessionSourceOfTrust;
import app.coronawarn.verification.model.HashedGuid;
import app.coronawarn.verification.model.LabTestResult;
import app.coronawarn.verification.model.RegistrationToken;
import app.coronawarn.verification.model.Tan;
import app.coronawarn.verification.model.TanSourceOfTrust;
import app.coronawarn.verification.model.TestResult;
import app.coronawarn.verification.service.AppSessionService;
import app.coronawarn.verification.service.FakeDelayService;
import app.coronawarn.verification.service.FakeRequestService;
Expand Down Expand Up @@ -133,25 +133,13 @@ public DeferredResult<ResponseEntity<Tan>> generateTan(@Valid @RequestBody Regis
if (appSession.getTanCounter() < tancountermax) {
AppSessionSourceOfTrust appSessionSourceOfTrust = appSession.getSourceOfTrust();
TanSourceOfTrust tanSourceOfTrust = TanSourceOfTrust.CONNECTED_LAB;
switch (appSessionSourceOfTrust) {
case HASHED_GUID:
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");
}
break;
case TELETAN:
tanSourceOfTrust = TanSourceOfTrust.TELETAN;
break;
default:
stopWatch.stop();
throw new VerificationServerException(HttpStatus.BAD_REQUEST,
"Unknown source of trust inside the appsession for the registration token");
}

TanVerifierFactory tanVerifierFactory = new TanVerifierFactoryImpl();
Copy link
Member

Choose a reason for hiding this comment

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

Use Spring Dependency Injection

Copy link
Author

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.


TanVerifier tanVerifier = tanVerifierFactory.makeTanVerifier(appSessionSourceOfTrust);

tanVerifier.generateTan(appSession, testResultServerService, stopWatch, tanSourceOfTrust);

appSession.incrementTanCounter();
appSession.setUpdatedAt(LocalDateTime.now());

Expand Down
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");
}
}
}
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);
}
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);
}
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();
}
}
}
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;
}
}
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");
}
}