Skip to content

Commit

Permalink
Feature/config file check up (eu-digital-green-certificates#211)
Browse files Browse the repository at this point in the history
* Version update

* Added config file check up

* Update

* Update
  • Loading branch information
oleksandrsarapulovgl committed Sep 14, 2021
1 parent b85966c commit d312c29
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: build
working-directory: ./dgca-verifier-app-android
run: |-
./gradlew --no-daemon build
./gradlew --no-daemon build -PCONFIG_FILE_NAME="verifier-context.jsonc"
- name: sign-tst
working-directory: ./dgca-verifier-app-android
run: |-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
- name: build
working-directory: ./dgca-verifier-app-android
run: |-
./gradlew --no-daemon build
./gradlew --no-daemon build -PCONFIG_FILE_NAME="verifier-context.jsonc"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ android-app
|___dgc-certlogic-android
```

- To build project - it's required to add config json file to application assets folder. Structure of the file should be similar to:
'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc', depending on chosen flavor.
After related file has been added - it's name should be passed via gradle properties:
gradlew -PCONFIG_FILE_NAME="config.json"

#### Android Studio based build

This project uses the Gradle build system. To build this project, use the `gradlew build` command or use "Run" in Android Studio.
Expand Down
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ android {
versionCode Config.versionCode
versionName Config.versionName

// It's required to provide config json files, and path to it.
// Examples based on different flavors could be found here: 'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc'

buildConfigField "String", "CONFIG_FILE_NAME", "\"$CONFIG_FILE_NAME\""

testInstrumentationRunner Config.androidTestInstrumentation
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/dgca/verifier/app/android/DgcaApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.*
import dagger.hilt.android.HiltAndroidApp
import dgca.verifier.app.android.data.ConfigRepository
import dgca.verifier.app.android.worker.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.FileNotFoundException
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.reflect.KClass
Expand All @@ -38,6 +42,9 @@ class DgcaApplication : Application(), Configuration.Provider {
@Inject
lateinit var workerFactory: HiltWorkerFactory

@Inject
lateinit var configDataSource: ConfigRepository

override fun getWorkManagerConfiguration(): Configuration {
return Configuration.Builder()
.setWorkerFactory(workerFactory)
Expand All @@ -50,6 +57,14 @@ class DgcaApplication : Application(), Configuration.Provider {
Timber.plant(Timber.DebugTree())
}

GlobalScope.launch {
try {
configDataSource.local().getConfig()
} catch (fileNotFoundException: FileNotFoundException) {
throw IllegalStateException("It's required to provide config json files. As an example may be used 'app/src/acc/assets/verifier-context.jsonc' or 'app/src/tst/assets/verifier-context.jsonc' files")
}
}

WorkManager.getInstance(this).apply {
schedulePeriodicWorker<ConfigsLoadingWorker>(WORKER_CONFIGS)
schedulePeriodicWorker<RulesLoadWorker>(WORKER_RULES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package dgca.verifier.app.android.data.local
import android.content.Context
import com.fasterxml.jackson.databind.ObjectMapper
import dagger.hilt.android.qualifiers.ApplicationContext
import dgca.verifier.app.android.BuildConfig
import dgca.verifier.app.android.data.Config
import timber.log.Timber
import java.io.*
Expand All @@ -38,7 +39,6 @@ class LocalConfigDataSource @Inject constructor(
private lateinit var config: Config

companion object {
const val DEFAULT_CONFIG_FILE = "verifier-context.jsonc"
const val CONFIG_FILE = "config.json"
}

Expand Down Expand Up @@ -76,7 +76,7 @@ class LocalConfigDataSource @Inject constructor(
}

private fun defaultConfig(): Config =
context.assets.open(DEFAULT_CONFIG_FILE).bufferedReader().use {
context.assets.open(BuildConfig.CONFIG_FILE_NAME).bufferedReader().use {
objectMapper.readValue(it.readText(), Config::class.java)
}
}

0 comments on commit d312c29

Please sign in to comment.