Skip to content

Commit

Permalink
- add test validation method; (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
MykhailoNester authored May 17, 2021
1 parent 26e7515 commit 1c94896
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
36 changes: 35 additions & 1 deletion decoder/src/main/java/dgca/verifier/app/decoder/model/Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Expand Down Expand Up @@ -60,4 +63,35 @@ data class Test(
@JsonProperty("ci")
val certificateIdentifier: String

) : Serializable
) : 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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -43,4 +46,8 @@ data class VerificationResult(
"cborDecoded: $cborDecoded \n" +
"isSchemaValid: $isSchemaValid"
}
}
}

data class TestVerificationResult(
val isDetected: Boolean
)

0 comments on commit 1c94896

Please sign in to comment.