Skip to content

Commit

Permalink
Set all props from downloaded protos
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalig committed Mar 11, 2021
1 parent 17a5906 commit 3a7d712
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -230,22 +230,25 @@ private int calculateDsos(GaenKeyForInterops gaenKey) {
return (int) Duration.between(receivedAt, rollingStartNumber).toDays() + 2000;
}

private List<GaenKeyForInterops> mapToGaenKeyWithOriginList(DiagnosisKeyBatch diagnosisKeyBatch) {
private List<GaenKeyForInterops> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 3a7d712

Please sign in to comment.