Skip to content

Commit

Permalink
extend support to API 23 (#47)
Browse files Browse the repository at this point in the history
* extend support to API 23

* Updated code to follow API 23 of Android limitations

* Set min version to 21

Co-authored-by: Oleksandr Sarapulov <[email protected]>
  • Loading branch information
SimeoneVilardo and oleksandrsarapulovgl authored Jul 27, 2021
1 parent 29c565f commit 10eb5a8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 28 deletions.
25 changes: 25 additions & 0 deletions .idea/sonarIssues.xml

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

2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.gradle.api.JavaVersion

object Config {
const val minSdk = 26
const val minSdk = 21
const val compileSdk = 29
const val targetSdk = 29
val javaVersion = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class DefaultAffectedFieldsDataRetriever(
certificateType: CertificateType
): String {
var affectedFields = StringBuilder()
rule.affectedString.forEach { affectedFiledString ->

for (i in rule.affectedString.indices) {
val affectedFiledString = rule.affectedString[i]
val description: String? = try {
val res = evaluate(
objectMapper.readTree(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

package dgca.verifier.app.engine.data.source.remote.rules

import dgca.verifier.app.engine.data.RuleCertificateType
import dgca.verifier.app.engine.data.Description
import dgca.verifier.app.engine.data.Rule
import dgca.verifier.app.engine.data.RuleCertificateType
import dgca.verifier.app.engine.data.Type
import java.util.*

Expand Down Expand Up @@ -68,8 +68,9 @@ fun RuleRemote.toRule(): Rule = Rule(

fun List<RuleRemote>.toRules(): List<Rule> {
val rules = mutableListOf<Rule>()
forEach {
rules.add(it.toRule())
for (i in this.indices) {
val ruleRemote = this[i]
rules.add(ruleRemote.toRule())
}
return rules
}
Expand All @@ -81,8 +82,9 @@ fun DescriptionRemote.toDescriptions(): Description = Description(

fun List<DescriptionRemote>.toDescriptions(): Map<String, String> {
val descriptions = mutableMapOf<String, String>()
forEach {
descriptions[it.lang.toLowerCase(Locale.ROOT)] = it.desc
for (i in this.indices) {
val descriptionRemote = this[i]
descriptions[descriptionRemote.lang.toLowerCase(Locale.ROOT)] = descriptionRemote.desc
}
return descriptions
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

package dgca.verifier.app.engine.data.source.remote.valuesets

import dgca.verifier.app.engine.data.*
import java.util.*
import dgca.verifier.app.engine.data.ValueSet

/*-
* ---license-start
Expand Down Expand Up @@ -54,8 +53,9 @@ fun ValueSetRemote.toValueSet(): ValueSet = ValueSet(

fun List<ValueSetRemote>.toValueSets(): List<ValueSet> {
val valueSets = mutableListOf<ValueSet>()
forEach {
valueSets.add(it.toValueSet())
for (i in this.indices) {
val valueSetRemote = this[i]
valueSets.add(valueSetRemote.toValueSet())
}
return valueSets
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class DefaultValueSetsRepository(
val valueSetsRemote = mutableListOf<ValueSetRemote>()
val valueSetsIdentifiersRemote = remoteDataSource.getValueSetsIdentifiers(url)

valueSetsIdentifiersRemote.forEach {
for (i in valueSetsIdentifiersRemote.indices) {
val ruleIdentifierRemote = valueSetsIdentifiersRemote[i]
val valueSetRemote =
remoteDataSource.getValueSet("$url/${it.hash}")
remoteDataSource.getValueSet("$url/${ruleIdentifierRemote.hash}")
if (valueSetRemote != null) {
valueSetsRemote.add(valueSetRemote)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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.Rule
import dgca.verifier.app.engine.data.Type
Expand Down Expand Up @@ -58,32 +57,42 @@ class DefaultGetRulesUseCase(private val rulesRepository: RulesRepository) : Get
certificateType: CertificateType,
region: String?
): List<Rule> {
val acceptanceRules = mutableMapOf<String, Rule>()
val filteredAcceptanceRules = mutableMapOf<String, Rule>()
val selectedRegion: String = region?.trim() ?: ""
rulesRepository.getRulesBy(
acceptanceCountryIsoCode, validationClock, Type.ACCEPTANCE, certificateType.toRuleCertificateType()
).forEach {
val ruleRegion: String = it.region?.trim() ?: ""
val acceptanceRules = rulesRepository.getRulesBy(
acceptanceCountryIsoCode,
validationClock,
Type.ACCEPTANCE,
certificateType.toRuleCertificateType()
)
for (i in acceptanceRules.indices) {
val rule = acceptanceRules[i]
val ruleRegion: String = rule.region?.trim() ?: ""
if (selectedRegion.equals(
ruleRegion,
ignoreCase = true
) && (acceptanceRules[it.identifier]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0)
) && (filteredAcceptanceRules[rule.identifier]?.version?.toVersion() ?: -1 < rule.version.toVersion() ?: 0)
) {
acceptanceRules[it.identifier] = it
filteredAcceptanceRules[rule.identifier] = rule
}
}

val invalidationRules = mutableMapOf<String, Rule>()
val filteredInvalidationRules = mutableMapOf<String, Rule>()
if (issuanceCountryIsoCode.isNotBlank()) {
rulesRepository.getRulesBy(
issuanceCountryIsoCode, validationClock, Type.INVALIDATION, certificateType.toRuleCertificateType()
).forEach {
if (invalidationRules[it.identifier]?.version?.toVersion() ?: -1 < it.version.toVersion() ?: 0) {
invalidationRules[it.identifier] = it
val invalidationRules = rulesRepository.getRulesBy(
issuanceCountryIsoCode,
validationClock,
Type.INVALIDATION,
certificateType.toRuleCertificateType()
)
for (i in invalidationRules.indices) {
val rule = invalidationRules[i]
if (filteredInvalidationRules[rule.identifier]?.version?.toVersion() ?: -1 < rule.version.toVersion() ?: 0) {
filteredInvalidationRules[rule.identifier] = rule
}
}
}
return acceptanceRules.values + invalidationRules.values
return filteredAcceptanceRules.values + filteredInvalidationRules.values
}

private fun String.toVersion(): Int? = try {
Expand Down

0 comments on commit 10eb5a8

Please sign in to comment.