diff --git a/.gitignore b/.gitignore index 1902c8e88..2278a1e2f 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,7 @@ secrets/* .swagger_gen_dir ocs_descriptor.pb -metrics_descriptor.pb \ No newline at end of file +metrics_descriptor.pb + +.Mac +*.DS_Store diff --git a/certs/.gitignore b/certs/.gitignore new file mode 100644 index 000000000..0d313d1e5 --- /dev/null +++ b/certs/.gitignore @@ -0,0 +1,2 @@ +*.key +*.crt \ No newline at end of file diff --git a/imei-lookup/build.gradle b/imei-lookup/build.gradle new file mode 100644 index 000000000..b578bdc39 --- /dev/null +++ b/imei-lookup/build.gradle @@ -0,0 +1,16 @@ +plugins { + id "org.jetbrains.kotlin.jvm" version "1.2.71" + id "java-library" + id "idea" +} + +dependencies { + implementation project(":prime-modules") + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" + implementation "io.dropwizard:dropwizard-jdbi3:$dropwizardVersion" + + testImplementation "io.dropwizard:dropwizard-testing:$dropwizardVersion" + + testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" +} \ No newline at end of file diff --git a/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiLookupModule.kt b/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiLookupModule.kt new file mode 100644 index 000000000..14657a11a --- /dev/null +++ b/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiLookupModule.kt @@ -0,0 +1,34 @@ +package org.ostelco.prime.imei.ImeiDb + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonTypeName +import io.dropwizard.setup.Environment +import org.ostelco.prime.getLogger +import org.ostelco.prime.module.PrimeModule + + +@JsonTypeName("Imei-lookup") +class ImeiLookupModule : PrimeModule { + + private val logger by getLogger() + + @JsonProperty + var config: Config? = null + + override fun init(env: Environment) { + + logger.info("ImeiLookupModule env: $env") + logger.info("CSV file set to ${config?.imeiLookupConfig?.csvFile}") + } +} + + +class Config { + @JsonProperty("sqlite") + lateinit var imeiLookupConfig: ImeiLookupConfig +} + +class ImeiLookupConfig { + @JsonProperty + var csvFile: String = "default.txt" +} \ No newline at end of file diff --git a/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDb.kt b/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDb.kt new file mode 100644 index 000000000..618e7f7a4 --- /dev/null +++ b/imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDb.kt @@ -0,0 +1,28 @@ +package org.ostelco.prime.imei.imeilookup + +import arrow.core.Either +import org.ostelco.prime.getLogger +import org.ostelco.prime.imei.ImeiLookup +import org.ostelco.prime.imei.core.Imei +import org.ostelco.prime.imei.core.ImeiLookupError +import org.ostelco.prime.imei.core.ImeaiNotFoundError + + +/** + * SQLite implementation of the IMEI lookup service + */ +class ImeiSqliteDb : ImeiLookup by jdbcSingleton { + + object jdbcSingleton : ImeiLookup { + + private val logger by getLogger() + + init { + logger.info("Singleton created") + } + + override fun getImeiInformation(imeisv: String): Either { + return Either.left(ImeaiNotFoundError("Not implemented jet")) + } + } +} diff --git a/imei-lookup/src/main/resources/META-INF/services/io.dropwizard.jackson.Discoverable b/imei-lookup/src/main/resources/META-INF/services/io.dropwizard.jackson.Discoverable new file mode 100644 index 000000000..8056fe23b --- /dev/null +++ b/imei-lookup/src/main/resources/META-INF/services/io.dropwizard.jackson.Discoverable @@ -0,0 +1 @@ +org.ostelco.prime.module.PrimeModule \ No newline at end of file diff --git a/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.imei.ImeiLookup b/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.imei.ImeiLookup new file mode 100644 index 000000000..ed9ad33f3 --- /dev/null +++ b/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.imei.ImeiLookup @@ -0,0 +1 @@ +org.ostelco.prime.imei.imeilookup.ImeiSqliteDb \ No newline at end of file diff --git a/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.module.PrimeModule b/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.module.PrimeModule new file mode 100644 index 000000000..7ae579be0 --- /dev/null +++ b/imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.module.PrimeModule @@ -0,0 +1 @@ +org.ostelco.prime.imei.ImeiDb.ImeiLookupModule \ No newline at end of file diff --git a/imei-lookup/src/test/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDbTest.kt b/imei-lookup/src/test/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDbTest.kt new file mode 100644 index 000000000..fb3571aa1 --- /dev/null +++ b/imei-lookup/src/test/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDbTest.kt @@ -0,0 +1,55 @@ +package org.ostelco.prime.imei.imeilookup + +import com.fasterxml.jackson.annotation.JsonProperty +import io.dropwizard.Application +import io.dropwizard.Configuration +import io.dropwizard.configuration.EnvironmentVariableSubstitutor +import io.dropwizard.configuration.SubstitutingSourceProvider +import io.dropwizard.setup.Bootstrap +import io.dropwizard.setup.Environment +import org.junit.Before +import org.junit.Test +import org.ostelco.prime.getLogger +import org.ostelco.prime.imei.ImeiLookup +import org.ostelco.prime.module.PrimeModule +import org.ostelco.prime.module.getResource +import kotlin.test.assertEquals + + +class TestApp : Application() { + + override fun initialize(bootstrap: Bootstrap) { + bootstrap.configurationSourceProvider = SubstitutingSourceProvider( + bootstrap.configurationSourceProvider, + EnvironmentVariableSubstitutor(false)) + } + + override fun run(configuration: TestConfig, environment: Environment) { + configuration.modules.forEach { it.init(environment) } + } +} + +class TestConfig: Configuration() { + + @JsonProperty + lateinit var modules: List +} + + +class ImeiSqliteDbTest { + + private val imeiLookup by lazy { getResource() } + + companion object { + init { + TestApp().run("server", "src/test/resources/config.yaml") + } + } + + @Test + fun getImeiResult() { + val result = imeiLookup.getImeiInformation("3550900831237501") + assertEquals(true, result.isRight()) + } + +} diff --git a/imei-lookup/src/test/resources/config.yaml b/imei-lookup/src/test/resources/config.yaml new file mode 100644 index 000000000..309e733db --- /dev/null +++ b/imei-lookup/src/test/resources/config.yaml @@ -0,0 +1,11 @@ +modules: +- type: Imei-lookup + config: + sqlite: + csvFile: test.txt +logging: + level: INFO + loggers: + org.ostelco: DEBUG + appenders: + - type: console \ No newline at end of file diff --git a/payment-processor/build.gradle b/payment-processor/build.gradle index 9c2069846..ff3d9c8b6 100644 --- a/payment-processor/build.gradle +++ b/payment-processor/build.gradle @@ -5,11 +5,8 @@ plugins { } sourceSets { - test { - java.srcDirs = ['src/test/kotlin'] - } integration { - java.srcDirs = ['src/test/kotlin', 'src/integration-tests/kotlin'] + java.srcDirs = ['src/integration-tests/kotlin'] resources.srcDir 'src/integration-tests/resources' compileClasspath += main.output + test.output runtimeClasspath += main.output + test.output diff --git a/payment-processor/src/integration-tests/kotlin/org/ostelco/prime/paymentprocessor/StripePaymentProcessorTest.kt b/payment-processor/src/integration-tests/kotlin/org/ostelco/prime/paymentprocessor/StripePaymentProcessorTest.kt index 4f1987749..d27422cbc 100644 --- a/payment-processor/src/integration-tests/kotlin/org/ostelco/prime/paymentprocessor/StripePaymentProcessorTest.kt +++ b/payment-processor/src/integration-tests/kotlin/org/ostelco/prime/paymentprocessor/StripePaymentProcessorTest.kt @@ -1,8 +1,6 @@ package org.ostelco.prime.paymentprocessor import arrow.core.getOrElse -import arrow.core.right -import arrow.core.some import com.stripe.Stripe import com.stripe.model.Source import com.stripe.model.Token diff --git a/prime-modules/src/main/kotlin/org/ostelco/prime/imei/ImeiLookup.kt b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/ImeiLookup.kt new file mode 100644 index 000000000..4414e7afa --- /dev/null +++ b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/ImeiLookup.kt @@ -0,0 +1,9 @@ +package org.ostelco.prime.imei + +import arrow.core.Either +import org.ostelco.prime.imei.core.Imei +import org.ostelco.prime.imei.core.ImeiLookupError + +interface ImeiLookup { + fun getImeiInformation(imeisv: String) : Either +} diff --git a/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/ImeiLookupError.kt b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/ImeiLookupError.kt new file mode 100644 index 000000000..6251ed020 --- /dev/null +++ b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/ImeiLookupError.kt @@ -0,0 +1,9 @@ +package org.ostelco.prime.imei.core + +import org.ostelco.prime.apierror.InternalError + +sealed class ImeiLookupError(val description: String, var externalErrorMessage : String? = null) : InternalError() + +class ImeaiNotFoundError(description: String, externalErrorMessage: String? = null) : ImeiLookupError(description, externalErrorMessage ) + +class BadGatewayError(description: String, externalErrorMessage: String? = null) : ImeiLookupError(description, externalErrorMessage) \ No newline at end of file diff --git a/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/Model.kt b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/Model.kt new file mode 100644 index 000000000..a069f001d --- /dev/null +++ b/prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/Model.kt @@ -0,0 +1,10 @@ +package org.ostelco.prime.imei.core + +data class Imei(val tac: String, + val marketingName: String, + val manufacturer: String, + val brandName: String, + val modelName: String, + val operatingSystem: String, + val deviceType: String, + val oem: String) \ No newline at end of file diff --git a/prime/build.gradle b/prime/build.gradle index 1a602b479..933f6faec 100644 --- a/prime/build.gradle +++ b/prime/build.gradle @@ -41,6 +41,7 @@ dependencies { runtimeOnly project(':payment-processor') runtimeOnly project(':analytics-module') runtimeOnly project(':slack') + runtimeOnly project(':imei-lookup') implementation "io.dropwizard:dropwizard-http2:$dropwizardVersion" runtimeOnly "io.dropwizard:dropwizard-json-logging:$dropwizardVersion" diff --git a/settings.gradle b/settings.gradle index fbd8d4601..2a16637bd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -27,6 +27,8 @@ include ':prime-modules' include ':prime-client-api' include ':pseudonym-server' include ':slack' +include ':imei-lookup' + project(':acceptance-tests').projectDir = "$rootDir/acceptance-tests" as File @@ -56,3 +58,4 @@ project(':prime-modules').projectDir = "$rootDir/prime-modules" as File project(':prime-client-api').projectDir = "$rootDir/prime-client-api" as File project(':pseudonym-server').projectDir = "$rootDir/pseudonym-server" as File project(':slack').projectDir = "$rootDir/slack" as File +project(':imei-lookup').projectDir = "$rootDir/imei-lookup" as File