Skip to content

Commit

Permalink
Updated validation logic (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrsarapulovgl authored Jun 24, 2021
1 parent fe57da2 commit d45e32a
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 78 deletions.
35 changes: 35 additions & 0 deletions .idea/sonarIssues.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions engine/src/androidTest/resources/rule.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"IDENTIFIER": "VR-DE-1",
"VERSION": "1.0.0",
"SCHEMAVERSION":"1.0.0",
"ENGINE":"CERTLOGIC",
"ENGINEVERSION":"1.0.0",
"TYPE":"ACCEPTANCE",
"COUNTRY":"DE",
"CERTIFICATETYPE":"VACCINATION",
"DESCRIPTION":[{"LANG":"EN","DESC":"VACCINATION MUST BE FROM JUNE AND DOSES MUST BE 2"}],
"VALIDFROM":"2021-06-27T07:46:40Z",
"VALIDTO":"2021-08-01T07:46:40Z",
"AFFECTEDFIELDS":["DT","DN"],
"LOGIC":{
"AND": [
{">=":[ {"VAR":"DT"}, "2021-06-01T00:00:00Z" ]},
{">=":[ {"VAR":"DN"}, 2 ]}
"Identifier": "VR-DE-1",
"Version": "1.0.0",
"SchemaVersion":"1.0.0",
"Engine":"CERTLOGIC",
"EngineVersion":"1.0.0",
"Type":"Acceptance",
"Country":"DE",
"CertificateType":"Vaccination",
"Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}],
"ValidFrom":"2021-06-27T07:46:40Z",
"ValidTo":"2021-08-01T07:46:40Z",
"AffectedFields":["dt","dn"],
"Logic":{
"and": [
{">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]},
{">=":[ {"var":"dn"}, 2 ]}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DefaultCertLogicEngine(private val jsonLogicValidator: JsonLogicValidator)
companion object {
private const val EXTERNAL_KEY = "external"
private const val HCERT_KEY = "hcert"
private const val DESCRIPTION = "description"
}

init {
Expand Down Expand Up @@ -66,23 +67,26 @@ class DefaultCertLogicEngine(private val jsonLogicValidator: JsonLogicValidator)
val validationResults = mutableListOf<ValidationResult>()
val schemaJsonNode = objectMapper.readValue<JsonNode>(schemaJson)
val dataJsonNode = prepareData(externalParameter, payload)
rules.forEach { it ->
val isValid = jsonLogicValidator.isDataValid(it.logic, dataJsonNode)
rules.forEach { rule ->
val isValid = jsonLogicValidator.isDataValid(rule.logic, dataJsonNode)
val res = when {
isValid -> Result.PASSED
else -> Result.FAIL
}
val cur = StringBuilder()
it.affectedString.forEach { affectedField ->
cur.append(
"${
schemaJsonNode.findValue(affectedField).findValue("description").asText()
}: ${dataJsonNode.findValue(affectedField).asText()}\n"
)
rule.affectedString.forEach { affectedField ->
val description =
schemaJsonNode.findValue(affectedField)?.findValue(DESCRIPTION)?.asText()
val currentState = dataJsonNode.findValue(affectedField)?.asText()
if (description?.isNotBlank() == true && currentState?.isNotBlank() == true) {
cur.append(
"$description: $currentState\n"
)
}
}
validationResults.add(
ValidationResult(
it,
rule,
res,
cur.toString(),
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
* Created by osarapulov on 11.06.21 11:00
*/
data class DescriptionRemote(
@JsonProperty("LANG") val lang: String,
@JsonProperty("DESC") val desc: String
@JsonProperty("lang") val lang: String,
@JsonProperty("desc") val desc: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ import java.time.ZonedDateTime
* Created by osarapulov on 11.06.21 11:03
*/
data class RuleRemote(
@JsonProperty("IDENTIFIER")
@JsonProperty("Identifier")
val identifier: String,
@JsonProperty("TYPE")
@JsonProperty("Type")
val type: String,
@JsonProperty("VERSION")
@JsonProperty("Version")
val version: String,
@JsonProperty("SCHEMAVERSION")
@JsonProperty("SchemaVersion")
val schemaVersion: String,
@JsonProperty("ENGINE")
@JsonProperty("Engine")
val engine: String,
@JsonProperty("ENGINEVERSION")
@JsonProperty("EngineVersion")
val engineVersion: String,
@JsonProperty("CERTIFICATETYPE")
@JsonProperty("CertificateType")
val certificateType: String,
@JsonProperty("DESCRIPTION")
@JsonProperty("Description")
val descriptions: List<DescriptionRemote>,
@JsonProperty("VALIDFROM")
@JsonProperty("ValidFrom")
val validFrom: ZonedDateTime,
@JsonProperty("VALIDTO")
@JsonProperty("ValidTo")
val validTo: ZonedDateTime,
@JsonProperty("AFFECTEDFIELDS")
@JsonProperty("AffectedFields")
val affectedString: List<String>,
@JsonProperty("LOGIC")
@JsonProperty("Logic")
val logic: JsonNode,
@JsonProperty("COUNTRY")
@JsonProperty("Country")
val countryCode: String
)
36 changes: 14 additions & 22 deletions engine/src/test/resources/mock_rule.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
{
"IDENTIFIER": "GR-CZ-0001",
"VERSION": "1.0.0",
"SCHEMAVERSION": "1.0.0",
"ENGINE": "CERTLOGIC",
"ENGINEVERSION": "2.0.1",
"TYPE": "Acceptance",
"CERTIFICATETYPE": "Vaccination",
"COUNTRY": "at",
"DESCRIPTION": [
{
"LANG": "en",
"DESC": "The Field “Doses” MUST contain number 2 OR 2/2."
}
],
"VALIDFROM": "2021-05-27T07:46:40Z",
"VALIDTO": "2030-06-01T07:46:40Z",
"AFFECTEDFIELDS": [
"dt",
"sd"
],
"LOGIC": {
"Identifier": "VR-DE-1",
"Version": "1.0.0",
"SchemaVersion":"1.0.0",
"Engine":"CERTLOGIC",
"EngineVersion":"1.0.0",
"Type":"Acceptance",
"Country":"DE",
"CertificateType":"Vaccination",
"Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}],
"ValidFrom":"2021-06-27T07:46:40Z",
"ValidTo":"2021-08-01T07:46:40Z",
"AffectedFields":["dt","dn"],
"Logic":{
"and": [
{
">": [
Expand All @@ -41,4 +33,4 @@
}
]
}
}
}
32 changes: 16 additions & 16 deletions engine/src/test/resources/rule.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"IDENTIFIER": "VR-DE-1",
"VERSION": "1.0.0",
"SCHEMAVERSION":"1.0.0",
"ENGINE":"CERTLOGIC",
"ENGINEVERSION":"1.0.0",
"TYPE":"ACCEPTANCE",
"COUNTRY":"DE",
"CERTIFICATETYPE":"VACCINATION",
"DESCRIPTION":[{"LANG":"EN","DESC":"VACCINATION MUST BE FROM JUNE AND DOSES MUST BE 2"}],
"VALIDFROM":"2021-06-27T07:46:40Z",
"VALIDTO":"2021-08-01T07:46:40Z",
"AFFECTEDFIELDS":["DT","DN"],
"LOGIC":{
"AND": [
{">=":[ {"VAR":"DT"}, "2021-06-01T00:00:00Z" ]},
{">=":[ {"VAR":"DN"}, 2 ]}
"Identifier": "VR-DE-1",
"Version": "1.0.0",
"SchemaVersion":"1.0.0",
"Engine":"CERTLOGIC",
"EngineVersion":"1.0.0",
"Type":"Acceptance",
"Country":"DE",
"CertificateType":"Vaccination",
"Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}],
"ValidFrom":"2021-06-27T07:46:40Z",
"ValidTo":"2021-08-01T07:46:40Z",
"AffectedFields":["dt","dn"],
"Logic":{
"and": [
{">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]},
{">=":[ {"var":"dn"}, 2 ]}
]
}
}

0 comments on commit d45e32a

Please sign in to comment.