From 3a7d712a21c9e5fa4b7073ac8ae82dfa5d2bf102 Mon Sep 17 00:00:00 2001 From: alig Date: Thu, 11 Mar 2021 18:02:45 +0100 Subject: [PATCH] Set all props from downloaded protos --- .../sdk/interops/syncer/efgs/EfgsClient.java | 29 ++++++++++--------- .../backend/sdk/model/gaen/ReportType.java | 19 ++++++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/syncer/efgs/EfgsClient.java b/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/syncer/efgs/EfgsClient.java index 9d528603..9e7f0e4d 100644 --- a/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/syncer/efgs/EfgsClient.java +++ b/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/syncer/efgs/EfgsClient.java @@ -103,7 +103,7 @@ public GaenKeyBatch download(LocalDate date, String batchTag) { try { if (response.getBody() != null) { DiagnosisKeyBatch diagnosisKeyBatch = DiagnosisKeyBatch.parseFrom(response.getBody()); - keyBatch.setKeys(mapToGaenKeyWithOriginList(diagnosisKeyBatch)); + keyBatch.setKeys(mapToGaenKeyForInteropsList(diagnosisKeyBatch)); } } catch (Exception e) { logger.error( @@ -230,22 +230,25 @@ private int calculateDsos(GaenKeyForInterops gaenKey) { return (int) Duration.between(receivedAt, rollingStartNumber).toDays() + 2000; } - private List mapToGaenKeyWithOriginList(DiagnosisKeyBatch diagnosisKeyBatch) { + private List mapToGaenKeyForInteropsList( + DiagnosisKeyBatch diagnosisKeyBatch) { return diagnosisKeyBatch.getKeysList().stream() - .map(k -> mapToGaenKeyWithOrigin(k)) + .map(k -> mapToGaenKeyForInterops(k)) .collect(Collectors.toList()); } - private GaenKeyForInterops mapToGaenKeyWithOrigin(DiagnosisKey diagnosisKey) { - GaenKeyForInterops keyWithOrigin = new GaenKeyForInterops(); - keyWithOrigin.setGaenKey(new GaenKey()); - keyWithOrigin.setKeyData( + private GaenKeyForInterops mapToGaenKeyForInterops(DiagnosisKey diagnosisKey) { + GaenKeyForInterops keyForInterops = new GaenKeyForInterops(); + keyForInterops.setGaenKey(new GaenKey()); + keyForInterops.setKeyData( java.util.Base64.getEncoder().encodeToString(diagnosisKey.getKeyData().toByteArray())); - keyWithOrigin.setRollingStartNumber(diagnosisKey.getRollingStartIntervalNumber()); - keyWithOrigin.setRollingPeriod(diagnosisKey.getRollingPeriod()); - keyWithOrigin.setTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel()); - keyWithOrigin.setFake(0); - keyWithOrigin.setOrigin(diagnosisKey.getOrigin()); - return keyWithOrigin; + keyForInterops.setRollingStartNumber(diagnosisKey.getRollingStartIntervalNumber()); + keyForInterops.setRollingPeriod(diagnosisKey.getRollingPeriod()); + keyForInterops.setTransmissionRiskLevel(diagnosisKey.getTransmissionRiskLevel()); + keyForInterops.setFake(0); + keyForInterops.setOrigin(diagnosisKey.getOrigin()); + keyForInterops.setReportType(ReportType.fromEfgsProtoReportType(diagnosisKey.getReportType())); + keyForInterops.setDaysSinceOnsetOfSymptoms(diagnosisKey.getDaysSinceOnsetOfSymptoms()); + return keyForInterops; } } diff --git a/dpppt-backend-sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/model/gaen/ReportType.java b/dpppt-backend-sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/model/gaen/ReportType.java index 2cd16193..de2d141e 100644 --- a/dpppt-backend-sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/model/gaen/ReportType.java +++ b/dpppt-backend-sdk/dpppt-backend-sdk-model/src/main/java/org/dpppt/backend/sdk/model/gaen/ReportType.java @@ -28,4 +28,23 @@ public EfgsProto.ReportType toEfgsProtoReportType() { throw new RuntimeException("no efgs proto report type mapping for: " + this); } } + + public static ReportType fromEfgsProtoReportType(EfgsProto.ReportType protoReportType) { + switch (protoReportType) { + case UNKNOWN: + return UNKNOWN; + case CONFIRMED_TEST: + return CONFIRMED_TEST; + case CONFIRMED_CLINICAL_DIAGNOSIS: + return CONFIRMED_CLINICAL_DIAGNOSIS; + case SELF_REPORT: + return SELF_REPORT; + case RECURSIVE: + return RECURSIVE; + case REVOKED: + return REVOKED; + default: + throw new RuntimeException("no report type mapping for: " + protoReportType); + } + } }