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

Commit

Permalink
testResultServerHash extended (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaude authored Apr 21, 2021
1 parent 82e77fd commit cdc392b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -165,6 +166,7 @@ public ResponseEntity<Void> updateQuickTestWithPersonalData(
@PathVariable String shortHash,
@Valid @RequestBody QuickTestPersonalDataRequest quickTestPersonalDataRequest) {
try {
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
quickTestService.updateQuickTestWithPersonalData(
utilities.getIdsFromToken(), shortHash,
modelMapper.map(quickTestPersonalDataRequest, QuickTest.class));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/app/coronawarn/quicktest/domain/QuickTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public class QuickTest {
@Convert(converter = DbEncryptionStringConverter.class)
private String birthday;

@Column(name = "test_result_server_hash")
@Convert(converter = DbEncryptionStringConverter.class)
private String testResultServerHash;

@PrePersist
private void onCreate() {
LocalDateTime now = Utilities.getCurrentLocalDateTimeUtc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ public class QuickTestArchive {
@Column(name = "pdf")
@Convert(converter = DbEncryptionByteArrayConverter.class)
private byte[] pdf;

@Column(name = "test_result_server_hash")
@Convert(converter = DbEncryptionStringConverter.class)
private String testResultServerHash;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package app.coronawarn.quicktest.model;

import app.coronawarn.quicktest.validation.ValidGuid;
import app.coronawarn.quicktest.validation.ValidPhoneNumber;
import app.coronawarn.quicktest.validation.ValidZipCode;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -82,4 +83,8 @@ public class QuickTestPersonalDataRequest {
@NotNull
private LocalDate birthday;

@NotNull
@ValidGuid
private String testResultServerHash;

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void updateQuickTest(Map<String, String> ids, String shortHash, short res
if (confirmationCwa != null && confirmationCwa) {
log.debug("Sending TestResult to TestResult-Server");
try {
sendResultToTestResultServer(quicktest.getHashedGuid(), result);
sendResultToTestResultServer(quicktest.getTestResultServerHash(), result);
} catch (TestResultServiceException e) {
log.error("Failed to send updated TestResult on TestResult-Server", e);
throw new QuickTestServiceException(QuickTestServiceException.Reason.TEST_RESULT_SERVER_ERROR);
Expand Down Expand Up @@ -179,18 +179,18 @@ public void updateQuickTestWithPersonalData(Map<String, String> ids, String shor
quicktest.setZipCode(quickTestPersonalData.getZipCode());
quicktest.setCity(quickTestPersonalData.getCity());
quicktest.setBirthday(quickTestPersonalData.getBirthday());
quicktest.setTestResultServerHash(quickTestPersonalData.getTestResultServerHash());
try {
quickTestRepository.saveAndFlush(quicktest);
} catch (Exception e) {
log.error("Could not save. updateQuickTestWithPersonalData failed. Exception = {}", e.getMessage());
throw new QuickTestServiceException(QuickTestServiceException.Reason.SAVE_FAILED);
}


if (quickTestPersonalData.getConfirmationCwa()) {
log.debug("Sending TestResult to TestResult-Server");
try {
sendResultToTestResultServer(quicktest.getHashedGuid(), quicktest.getTestResult());
sendResultToTestResultServer(quicktest.getTestResultServerHash(), quicktest.getTestResult());
} catch (TestResultServiceException e) {
log.error("Failed to send TestResult to TestResult-Server", e);
throw new QuickTestServiceException(QuickTestServiceException.Reason.TEST_RESULT_SERVER_ERROR);
Expand Down Expand Up @@ -240,6 +240,7 @@ private QuickTestArchive mappingQuickTestToQuickTestAchive(
quickTestArchive.setTestBrandId(quickTest.getTestBrandId());
quickTestArchive.setTestBrandName(quickTest.getTestBrandName());
quickTestArchive.setPdf(pdf);
quickTestArchive.setTestResultServerHash(quickTest.getTestResultServerHash());
return quickTestArchive;
}

Expand All @@ -253,9 +254,10 @@ private QuickTest getQuickTest(String pocId, String shortHash) throws QuickTestS
return quicktest;
}

private void sendResultToTestResultServer(String hashedGuid, short result) throws TestResultServiceException {
private void sendResultToTestResultServer(String testResultServerHash, short result)
throws TestResultServiceException {
QuickTestResult quickTestResult = new QuickTestResult();
quickTestResult.setId(hashedGuid);
quickTestResult.setId(testResultServerHash);
quickTestResult.setResult(result);
testResultService.createOrUpdateTestResult(quickTestResult);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ databaseChangeLog:
- include:
file: changelog/V001_add_privacyAgreeColumn.yml
relativeToChangelogFile: true
- include:
file: changelog/V001_add_testResultServerHash.yml
relativeToChangelogFile: true
15 changes: 15 additions & 0 deletions src/main/resources/db/changelog/V001_add_testResultServerHash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
databaseChangeLog:
- changeSet:
id: add-testResaltServerHash-column
author: agaricusbisporus
changes:
- addColumn:
tableName: quick_test
columns:
name: test_result_server_hash
type: varchar(108)
- addColumn:
tableName: quick_test_archive
columns:
name: test_result_server_hash
type: varchar(108)
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void constructorTest() {
quickTestArchive.setPrivacyAgreement(Boolean.FALSE);
quickTestArchive.setSex(Sex.DIVERSE);
quickTestArchive.setPdf("Hello".getBytes());
assertEquals("QuickTestArchive(hashedGuid=mkamhvdumyvhxeftazravmyrasozuloaghgluvbfjohpofogkylcnsybuba" +
"mwnht, shortHashedGuid=cjfybkfn, tenantId=4711, pocId=4711-A, createdAt=2021-04-08T08:11:11," +
" updatedAt=2021-04-08T08:11:12, version=null, confirmationCwa=true, testResult=5, " +
"privacyAgreement=false, lastName=Miller, firstName=Joe, [email protected], phoneNumber" +
"=00491777777777777, sex=DIVERSE, street=Boe, houseNumber=11, zipCode=12345, city=oyvkpigcga," +
" testBrandId=AT116/21, testBrandName=Panbio (TM) Covid-19 Ag Rapid Test Device (Nasal), " +
"birthday=01.01.1954, pdf=[72, 101, 108, 108, 111])",
assertEquals("QuickTestArchive(hashedGuid=mkamhvdumyvhxeftazravmyrasozuloaghgluvbfjohpofogkylcnsybubamwnht, "
+ "shortHashedGuid=cjfybkfn, tenantId=4711, pocId=4711-A, createdAt=2021-04-08T08:11:11, "
+ "updatedAt=2021-04-08T08:11:12, version=null, confirmationCwa=true, testResult=5, "
+ "privacyAgreement=false, lastName=Miller, firstName=Joe, [email protected], "
+ "phoneNumber=00491777777777777, sex=DIVERSE, street=Boe, houseNumber=11, zipCode=12345, "
+ "city=oyvkpigcga, testBrandId=AT116/21, testBrandName=Panbio (TM) Covid-19 Ag Rapid Test "
+ "Device (Nasal), birthday=01.01.1954, pdf=[72, 101, 108, 108, 111], testResultServerHash=null)",
quickTestArchive.toString());
}

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/app/coronawarn/quicktest/entity/QuickTestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void constructorTest() {
quickTest.setPrivacyAgreement(Boolean.FALSE);
quickTest.setSex(Sex.DIVERSE);
assertEquals(
"QuickTest(hashedGuid=mkamhvdumyvhxeftazravmyrasozuloaghgluvbfjohpofogkylcnsybubamwnht, " +
"shortHashedGuid=cjfybkfn, tenantId=4711, pocId=4711-A, createdAt=2021-04-08T08:11:11, " +
"updatedAt=2021-04-08T08:11:12, version=null, confirmationCwa=true, testResult=5, " +
"privacyAgreement=false, lastName=Miller, firstName=Joe, [email protected], " +
"phoneNumber=00491777777777777, sex=DIVERSE, street=Boe, houseNumber=11, zipCode=12345, " +
"city=oyvkpigcga, testBrandId=AT116/21, " +
"testBrandName=Panbio (TM) Covid-19 Ag Rapid Test Device (Nasal), birthday=null)",
"QuickTest(hashedGuid=mkamhvdumyvhxeftazravmyrasozuloaghgluvbfjohpofogkylcnsybubamwnht, "
+ "shortHashedGuid=cjfybkfn, tenantId=4711, pocId=4711-A, createdAt=2021-04-08T08:11:11, "
+ "updatedAt=2021-04-08T08:11:12, version=null, confirmationCwa=true, testResult=5, "
+ "privacyAgreement=false, lastName=Miller, firstName=Joe, [email protected], "
+ "phoneNumber=00491777777777777, sex=DIVERSE, street=Boe, houseNumber=11, zipCode=12345, "
+ "city=oyvkpigcga, testBrandId=AT116/21, testBrandName=Panbio (TM) Covid-19 Ag Rapid "
+ "Test Device (Nasal), birthday=null, testResultServerHash=null)",
quickTest.toString());
}

Expand Down

0 comments on commit cdc392b

Please sign in to comment.