Skip to content

Commit

Permalink
Rules filtering update (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrsarapulovgl authored Jul 7, 2021
1 parent f8d9d3d commit 6e986b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ abstract class RulesDao {
generalRuleCertificateType: RuleCertificateType
): List<RuleWithDescriptionsLocal>

@Transaction
@Query("SELECT * FROM rules WHERE :countryIsoCode = countryCode")
abstract fun getRulesWithDescriptionsBy(
countryIsoCode: String
): List<RuleWithDescriptionsLocal>

@Insert
abstract fun insertRule(rule: RuleLocal): Long

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,26 +57,31 @@ class DefaultGetRulesUseCase(private val rulesRepository: RulesRepository) : Get
certificateType: CertificateType,
region: String?
): List<Rule> {
val acceptanceRules = mutableMapOf<RuleCertificateType, Rule>()
val acceptanceRules = mutableMapOf<String, Rule>()
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<RuleCertificateType, Rule>()
val invalidationRules = mutableMapOf<String, Rule>()
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
}
}
}
Expand Down

0 comments on commit 6e986b2

Please sign in to comment.