diff --git a/engine/src/main/java/dgca/verifier/app/engine/data/source/local/rules/RulesDao.kt b/engine/src/main/java/dgca/verifier/app/engine/data/source/local/rules/RulesDao.kt index c6d3951..299f191 100644 --- a/engine/src/main/java/dgca/verifier/app/engine/data/source/local/rules/RulesDao.kt +++ b/engine/src/main/java/dgca/verifier/app/engine/data/source/local/rules/RulesDao.kt @@ -69,6 +69,12 @@ abstract class RulesDao { generalRuleCertificateType: RuleCertificateType ): List + @Transaction + @Query("SELECT * FROM rules WHERE :countryIsoCode = countryCode") + abstract fun getRulesWithDescriptionsBy( + countryIsoCode: String + ): List + @Insert abstract fun insertRule(rule: RuleLocal): Long diff --git a/engine/src/main/java/dgca/verifier/app/engine/domain/rules/DefaultGetRulesUseCase.kt b/engine/src/main/java/dgca/verifier/app/engine/domain/rules/DefaultGetRulesUseCase.kt index eb4fd54..da9ddc1 100644 --- a/engine/src/main/java/dgca/verifier/app/engine/domain/rules/DefaultGetRulesUseCase.kt +++ b/engine/src/main/java/dgca/verifier/app/engine/domain/rules/DefaultGetRulesUseCase.kt @@ -24,12 +24,10 @@ package dgca.verifier.app.engine.domain.rules import dgca.verifier.app.engine.UTC_ZONE_ID import dgca.verifier.app.engine.data.CertificateType -import dgca.verifier.app.engine.data.RuleCertificateType import dgca.verifier.app.engine.data.Rule import dgca.verifier.app.engine.data.Type import dgca.verifier.app.engine.data.source.rules.RulesRepository import java.time.ZonedDateTime -import java.util.* /*- * ---license-start @@ -59,26 +57,31 @@ class DefaultGetRulesUseCase(private val rulesRepository: RulesRepository) : Get certificateType: CertificateType, region: String? ): List { - val acceptanceRules = mutableMapOf() + val acceptanceRules = mutableMapOf() rulesRepository.getRulesBy( acceptanceCountryIsoCode, ZonedDateTime.now().withZoneSameInstant( UTC_ZONE_ID ), Type.ACCEPTANCE, certificateType.toRuleCertificateType() ).forEach { - if ((region.isNullOrEmpty() || region.toLowerCase(Locale.ROOT) == it.region) && (acceptanceRules[it.ruleCertificateType]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0)) { - acceptanceRules[it.ruleCertificateType] = it + if (((it.region.isNullOrEmpty() && region.isNullOrEmpty()) + || (it.region?.trim() + .equals(acceptanceCountryIsoCode, ignoreCase = true)) + || (it.region?.trim().equals(region?.trim(), ignoreCase = true)) + ) && (acceptanceRules[it.identifier]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0) + ) { + acceptanceRules[it.identifier] = it } } - val invalidationRules = mutableMapOf() + val invalidationRules = mutableMapOf() if (issuanceCountryIsoCode.isNotBlank()) { rulesRepository.getRulesBy( issuanceCountryIsoCode, ZonedDateTime.now().withZoneSameInstant( UTC_ZONE_ID ), Type.INVALIDATION, certificateType.toRuleCertificateType() ).forEach { - if (invalidationRules[it.ruleCertificateType]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0) { - invalidationRules[it.ruleCertificateType] = it + if (invalidationRules[it.identifier]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0) { + invalidationRules[it.identifier] = it } } }