This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check-Ins to submission payload (EXPOSUREAPP-5656) (#2602)
* Add check-ins to submission payload * Use new classes - map checkin fields * Rename to transformer * Satisfy tests * lint * Use new models * Add space to satisfy ktlint the magnificent * Create DefaultCheckInsTransformerTest.kt * Clear check-ins after submission * Fix tests * Update SubmissionTaskTest.kt Co-authored-by: Lukas Lechner <lukas.lechner@sap.com>
- Loading branch information
1 parent
0bc79cb
commit fc8ece0
Showing
12 changed files
with
233 additions
and
31 deletions.
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
7 changes: 7 additions & 0 deletions
7
...-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformer.kt
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 de.rki.coronawarnapp.eventregistration.checkins | ||
|
||
import de.rki.coronawarnapp.server.protocols.internal.pt.CheckInOuterClass | ||
|
||
interface CheckInsTransformer { | ||
fun transform(checkIns: List<CheckIn>): List<CheckInOuterClass.CheckIn> | ||
} |
37 changes: 37 additions & 0 deletions
37
...c/main/java/de/rki/coronawarnapp/eventregistration/checkins/DefaultCheckInsTransformer.kt
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,37 @@ | ||
package de.rki.coronawarnapp.eventregistration.checkins | ||
|
||
import com.google.protobuf.ByteString | ||
import de.rki.coronawarnapp.server.protocols.internal.pt.CheckInOuterClass | ||
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass | ||
import de.rki.coronawarnapp.util.TimeAndDateExtensions.seconds | ||
import javax.inject.Inject | ||
|
||
class DefaultCheckInsTransformer @Inject constructor() : | ||
CheckInsTransformer { | ||
override fun transform(checkIns: List<CheckIn>): List<CheckInOuterClass.CheckIn> { | ||
return checkIns.map { checkIn -> | ||
val traceLocation = TraceLocationOuterClass.TraceLocation.newBuilder() | ||
.setGuid(checkIn.guid) | ||
.setVersion(checkIn.version) | ||
.setType(TraceLocationOuterClass.TraceLocationType.forNumber(checkIn.type)) | ||
.setDescription(checkIn.description) | ||
.setAddress(checkIn.address) | ||
.setStartTimestamp(checkIn.traceLocationStart?.seconds ?: 0L) | ||
.setEndTimestamp(checkIn.traceLocationEnd?.seconds ?: 0L) | ||
.setDefaultCheckInLengthInMinutes(checkIn.defaultCheckInLengthInMinutes ?: 0) | ||
.build() | ||
|
||
val signedTraceLocation = TraceLocationOuterClass.SignedTraceLocation.newBuilder() | ||
.setLocation(traceLocation) | ||
.setSignature(ByteString.copyFrom(checkIn.signature.toByteArray())) | ||
.build() | ||
|
||
CheckInOuterClass.CheckIn.newBuilder() | ||
.setSignedLocation(signedTraceLocation) | ||
.setStartIntervalNumber(checkIn.checkInStart.seconds.toInt()) | ||
.setEndIntervalNumber(checkIn.checkInEnd?.seconds?.toInt() ?: 0) | ||
// TODO .setTransmissionRiskLevel() | ||
.build() | ||
} | ||
} | ||
} |
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
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
96 changes: 96 additions & 0 deletions
96
...st/java/de/rki/coronawarnapp/eventregistration/checkins/DefaultCheckInsTransformerTest.kt
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,96 @@ | ||
package de.rki.coronawarnapp.eventregistration.checkins | ||
|
||
import com.google.protobuf.ByteString | ||
import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass | ||
import io.kotest.matchers.shouldBe | ||
import org.joda.time.Instant | ||
import org.junit.jupiter.api.Test | ||
import testhelpers.BaseTest | ||
|
||
class DefaultCheckInsTransformerTest : BaseTest() { | ||
|
||
private val checkInTransformer = DefaultCheckInsTransformer() | ||
|
||
@Test | ||
fun `transform check-ins`() { | ||
val checkIn1 = CheckIn( | ||
id = 0, | ||
guid = "3055331c-2306-43f3-9742-6d8fab54e848", | ||
version = 1, | ||
type = 2, | ||
description = "description1", | ||
address = "address1", | ||
traceLocationStart = Instant.ofEpochMilli(2687955 * 1_000L), | ||
traceLocationEnd = Instant.ofEpochMilli(2687991 * 1_000L), | ||
defaultCheckInLengthInMinutes = 10, | ||
signature = "signature1", | ||
checkInStart = Instant.ofEpochMilli(2687955 * 1_000L), | ||
checkInEnd = Instant.ofEpochMilli(2687991 * 1_000L), | ||
targetCheckInEnd = null, | ||
createJournalEntry = true | ||
) | ||
|
||
val checkIn2 = CheckIn( | ||
id = 1, | ||
guid = "fca84b37-61c0-4a7c-b2f8-825cadd506cf", | ||
version = 1, | ||
type = 1, | ||
description = "description2", | ||
address = "address2", | ||
traceLocationStart = null, | ||
traceLocationEnd = null, | ||
defaultCheckInLengthInMinutes = 20, | ||
signature = "signature2", | ||
checkInStart = Instant.ofEpochMilli(2687955 * 1_000L), | ||
checkInEnd = null, | ||
targetCheckInEnd = null, | ||
createJournalEntry = false | ||
) | ||
|
||
val outCheckIns = checkInTransformer.transform( | ||
listOf( | ||
checkIn1, | ||
checkIn2 | ||
) | ||
) | ||
outCheckIns.size shouldBe 2 | ||
|
||
outCheckIns[0].apply { | ||
signedLocation.apply { | ||
location.apply { | ||
guid shouldBe "3055331c-2306-43f3-9742-6d8fab54e848" | ||
version shouldBe 1 | ||
type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_TEMPORARY_OTHER | ||
description shouldBe "description1" | ||
address shouldBe "address1" | ||
startTimestamp shouldBe 2687955 | ||
endTimestamp shouldBe 2687991 | ||
defaultCheckInLengthInMinutes shouldBe 10 | ||
} | ||
signature shouldBe ByteString.copyFrom("signature1".toByteArray()) | ||
} | ||
startIntervalNumber shouldBe 2687955 | ||
endIntervalNumber shouldBe 2687991 | ||
// TODO transmissionRiskLevel shouldBe | ||
} | ||
|
||
outCheckIns[1].apply { | ||
signedLocation.apply { | ||
location.apply { | ||
guid shouldBe "fca84b37-61c0-4a7c-b2f8-825cadd506cf" | ||
version shouldBe 1 | ||
type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_OTHER | ||
description shouldBe "description2" | ||
address shouldBe "address2" | ||
startTimestamp shouldBe 0 | ||
endTimestamp shouldBe 0 | ||
defaultCheckInLengthInMinutes shouldBe 20 | ||
} | ||
signature shouldBe ByteString.copyFrom("signature2".toByteArray()) | ||
} | ||
startIntervalNumber shouldBe 2687955 | ||
endIntervalNumber shouldBe 0 | ||
// TODO transmissionRiskLevel shouldBe | ||
} | ||
} | ||
} |
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
Oops, something went wrong.