-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated affected fields fetching logic #23
Conversation
private val RULE = "{\n" + | ||
" \"Identifier\": \"VR-DE-0001\",\n" + | ||
" \"Type\": \"Acceptance\",\n" + | ||
" \"Country\": \"DE\",\n" + | ||
" \"Version\": \"1.0.0\",\n" + | ||
" \"SchemaVersion\": \"1.0.0\",\n" + | ||
" \"Engine\": \"CERTLOGIC\",\n" + | ||
" \"EngineVersion\": \"0.7.5\",\n" + | ||
" \"CertificateType\": \"Vaccination\",\n" + | ||
" \"Description\": [\n" + | ||
" {\n" + | ||
" \"lang\": \"en\",\n" + | ||
" \"desc\": \"The vaccination schedule must be complete (e.g., 1/1, 2/2).\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"lang\": \"de\",\n" + | ||
" \"desc\": \"Die Impfreihe muss vollständig sein (z.B. 1/1, 2/2).\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"lang\": \"fr\",\n" + | ||
" \"desc\": \"La série vaccinale doit être complète (p. ex. 1/1, 2/2).\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"lang\": \"es\",\n" + | ||
" \"desc\": \"La pauta de vacunación debe estar completa (por ejemplo, 1/1, 2/2).\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"lang\": \"it\",\n" + | ||
" \"desc\": \"Il ciclo di vaccinazione deve essere stato completato (ad es. 1/1, 2/2).\"\n" + | ||
" }\n" + | ||
" ],\n" + | ||
" \"ValidFrom\": \"2021-07-03T00:00:00Z\",\n" + | ||
" \"ValidTo\": \"2030-06-01T00:00:00Z\",\n" + | ||
" \"AffectedFields\": [\n" + | ||
" \"v.0\",\n" + | ||
" \"v.0.dn\",\n" + | ||
" \"v.0.sd\"\n" + | ||
" ],\n" + | ||
" \"Logic\": {\n" + | ||
" \"if\": [\n" + | ||
" {\n" + | ||
" \"var\": \"payload.v.0\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \">=\": [\n" + | ||
" {\n" + | ||
" \"var\": \"payload.v.0.dn\"\n" + | ||
" },\n" + | ||
" {\n" + | ||
" \"var\": \"payload.v.0.sd\"\n" + | ||
" }\n" + | ||
" ]\n" + | ||
" },\n" + | ||
" true\n" + | ||
" ]\n" + | ||
" }\n" + | ||
"}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use trimIdent()
here to improve readability and make it easier to adapt the json if it changes?
private val RULE = """
{
"Identifier": "VR-DE-0001",
"Type": "Acceptance",
"Country": "DE",
"Version": "1.0.0",
"SchemaVersion": "1.0.0",
"Engine": "CERTLOGIC",
"EngineVersion": "0.7.5",
"CertificateType": "Vaccination",
"Description": [
{
"lang": "en",
"desc": "The vaccination schedule must be complete (e.g., 1/1, 2/2)."
},
{
"lang": "de",
"desc": "Die Impfreihe muss vollständig sein (z.B. 1/1, 2/2)."
},
{
"lang": "fr",
"desc": "La série vaccinale doit être complète (p. ex. 1/1, 2/2)."
},
{
"lang": "es",
"desc": "La pauta de vacunación debe estar completa (por ejemplo, 1/1, 2/2)."
},
{
"lang": "it",
"desc": "Il ciclo di vaccinazione deve essere stato completato (ad es. 1/1, 2/2)."
}
],
"ValidFrom": "2021-07-03T00:00:00Z",
"ValidTo": "2030-06-01T00:00:00Z",
"AffectedFields": [
"v.0",
"v.0.dn",
"v.0.sd"
],
"Logic": {
"if": [
{
"var": "payload.v.0"
},
{
">=": [
{
"var": "payload.v.0.dn"
},
{
"var": "payload.v.0.sd"
}
]
},
true
]
}
}
""".trimIndent()
assertEquals("\"Dose Number\": 1\n" + | ||
"\"Total Series of Doses\": 2\n", affectedFieldsString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trimIdent()
could also work here, what do you think?
assertEquals(
"""
"Dose Number": 1
"Total Series of Doses": 2
""".trimIndent(),
affectedFieldsString
)
rule.logic, | ||
dataJsonNode | ||
) -> Result.PASSED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An early return could remove a full level of nesting and make this unwieldy indentation a bit easier to read.
override fun validate(
certificateType: CertificateType,
hcertVersionString: String,
rules: List<Rule>,
externalParameter: ExternalParameter,
payload: String
): List<ValidationResult> {
if (rules.isEmpty()) return emptyList()
val validationResults = mutableListOf<ValidationResult>()
val dataJsonNode = prepareData(externalParameter, payload)
val hcertVersion = hcertVersionString.toVersion()
rules.forEach { rule ->
val ruleVersion = rule.version.toVersion()
val res = when {
hcertVersion == null || ruleVersion == null || hcertVersion.first != ruleVersion.first -> Result.OPEN
hcertVersion.isGreaterOrEqualThan(ruleVersion) &&
jsonLogicValidator.isDataValid(
rule.logic,
dataJsonNode
) -> Result.PASSED
else -> Result.FAIL
}
val cur: String = affectedFieldsDataRetriever.getAffectedFieldsData(
rule,
dataJsonNode,
certificateType
)
validationResults.add(
ValidationResult(
rule,
res,
cur,
null
)
)
}
return validationResults
}
No description provided.