Skip to content

Commit

Permalink
Adding IMEI module to Prime
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterss committed Oct 9, 2018
1 parent b306c3d commit 1ff77c6
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ secrets/*
.swagger_gen_dir

ocs_descriptor.pb
metrics_descriptor.pb
metrics_descriptor.pb

.Mac
*.DS_Store
2 changes: 2 additions & 0 deletions certs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.key
*.crt
16 changes: 16 additions & 0 deletions imei-lookup/build.gradle
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"
}
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"
}
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"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.ostelco.prime.module.PrimeModule
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.ostelco.prime.imei.imeilookup.ImeiSqliteDb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.ostelco.prime.imei.ImeiDb.ImeiLookupModule
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())
}

}
11 changes: 11 additions & 0 deletions imei-lookup/src/test/resources/config.yaml
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
5 changes: 1 addition & 4 deletions payment-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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>
}
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 prime-modules/src/main/kotlin/org/ostelco/prime/imei/core/Model.kt
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)
1 change: 1 addition & 0 deletions prime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1ff77c6

Please sign in to comment.