diff --git a/decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt b/decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt index 8c20bc6..ddffaf4 100644 --- a/decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt +++ b/decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt @@ -24,6 +24,9 @@ package dgca.verifier.app.decoder.model import com.fasterxml.jackson.annotation.JsonProperty import java.io.Serializable +import java.time.OffsetDateTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter data class Test( @@ -60,4 +63,35 @@ data class Test( @JsonProperty("ci") val certificateIdentifier: String -) : Serializable \ No newline at end of file +) : Serializable { + + fun isTestValid(): Boolean { + return testResult == TestResult.NOT_DETECTED.value && + parseToUtcTimestamp(dateTimeOfCollection).isBefore(OffsetDateTime.now()) + } + + fun getTestResultType(): TestResult { + return when (testResult) { + TestResult.DETECTED.value -> TestResult.DETECTED + TestResult.NOT_DETECTED.value -> TestResult.NOT_DETECTED + else -> TestResult.NOT_DETECTED + } + } + + private fun parseToUtcTimestamp(value: String?): OffsetDateTime { + if (value.isNullOrEmpty()) { + return OffsetDateTime.MAX + } + + return try { + DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value, OffsetDateTime::from).withOffsetSameInstant(ZoneOffset.UTC) + } catch (ex: Exception) { + OffsetDateTime.MAX + } + } + + enum class TestResult(val value: String) { + DETECTED("260373001"), + NOT_DETECTED("260415000") + } +} diff --git a/decoder/src/main/java/dgca/verifier/app/decoder/model/VerificationResult.kt b/decoder/src/main/java/dgca/verifier/app/decoder/model/VerificationResult.kt index 5123e05..a8328ac 100644 --- a/decoder/src/main/java/dgca/verifier/app/decoder/model/VerificationResult.kt +++ b/decoder/src/main/java/dgca/verifier/app/decoder/model/VerificationResult.kt @@ -28,11 +28,14 @@ data class VerificationResult( var zlibDecoded: Boolean = false, var coseVerified: Boolean = false, var cborDecoded: Boolean = false, - var isSchemaValid: Boolean = false + var isSchemaValid: Boolean = false, + var testVerification: TestVerificationResult? = null ) { - fun isValid(): Boolean = - base45Decoded && zlibDecoded && coseVerified && cborDecoded && isSchemaValid + fun isValid(): Boolean { + val isTestValid = testVerification?.isDetected ?: true + return base45Decoded && zlibDecoded && coseVerified && cborDecoded && isSchemaValid && isTestValid + } override fun toString(): String { return "VerificationResult: \n" + @@ -43,4 +46,8 @@ data class VerificationResult( "cborDecoded: $cborDecoded \n" + "isSchemaValid: $isSchemaValid" } -} \ No newline at end of file +} + +data class TestVerificationResult( + val isDetected: Boolean +) \ No newline at end of file