-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,7 @@ secrets/* | |
.swagger_gen_dir | ||
|
||
ocs_descriptor.pb | ||
metrics_descriptor.pb | ||
metrics_descriptor.pb | ||
|
||
.Mac | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.key | ||
*.crt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
34 changes: 34 additions & 0 deletions
34
imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiLookupModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
28 changes: 28 additions & 0 deletions
28
imei-lookup/src/main/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ImeiLookupError, Imei> { | ||
return Either.left(ImeaiNotFoundError("Not implemented jet")) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
imei-lookup/src/main/resources/META-INF/services/io.dropwizard.jackson.Discoverable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ostelco.prime.module.PrimeModule |
1 change: 1 addition & 0 deletions
1
imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.imei.ImeiLookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ostelco.prime.imei.imeilookup.ImeiSqliteDb |
1 change: 1 addition & 0 deletions
1
imei-lookup/src/main/resources/META-INF/services/org.ostelco.prime.module.PrimeModule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.ostelco.prime.imei.ImeiDb.ImeiLookupModule |
55 changes: 55 additions & 0 deletions
55
imei-lookup/src/test/kotlin/org/ostelco/prime/imei/imeilookup/ImeiSqliteDbTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestConfig>() { | ||
|
||
override fun initialize(bootstrap: Bootstrap<TestConfig>) { | ||
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<PrimeModule> | ||
} | ||
|
||
|
||
class ImeiSqliteDbTest { | ||
|
||
private val imeiLookup by lazy { getResource<ImeiLookup>() } | ||
|
||
companion object { | ||
init { | ||
TestApp().run("server", "src/test/resources/config.yaml") | ||
} | ||
} | ||
|
||
@Test | ||
fun getImeiResult() { | ||
val result = imeiLookup.getImeiInformation("3550900831237501") | ||
assertEquals(true, result.isRight()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
modules: | ||
- type: Imei-lookup | ||
config: | ||
sqlite: | ||
csvFile: test.txt | ||
logging: | ||
level: INFO | ||
loggers: | ||
org.ostelco: DEBUG | ||
appenders: | ||
- type: console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...integration-tests/kotlin/org/ostelco/prime/paymentprocessor/StripePaymentProcessorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
prime-modules/src/main/kotlin/org/ostelco/prime/imei/ImeiLookup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ImeiLookupError, Imei> | ||
} |
9 changes: 9 additions & 0 deletions
9
prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/ImeiLookupError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
10 changes: 10 additions & 0 deletions
10
prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/Model.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters