Skip to content

Commit

Permalink
Merge pull request #162 from ostelco/develop
Browse files Browse the repository at this point in the history
New version of pseudonym server
  • Loading branch information
prasanthu authored Jun 11, 2018
2 parents 1a47b98 + 8ed22b6 commit 3de3546
Show file tree
Hide file tree
Showing 41 changed files with 633 additions and 107 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
Expand Down
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
language: java

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.gradle/caches/
Expand All @@ -15,5 +11,13 @@ before_install:
#- wget -O ~/codacy-coverage-reporter-assembly-latest.jar $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r .assets[0].browser_download_url)
- wget -O ~/codacy-coverage-reporter-assembly-latest.jar https://github.com/codacy/codacy-coverage-reporter/releases/download/4.0.0/codacy-coverage-reporter-4.0.0-assembly.jar

install: echo "skip 'gradle assemble' step"

script: ./gradlew build

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

after_success:
- java -cp ~/codacy-coverage-reporter-assembly-latest.jar com.codacy.CodacyCoverageReporter report -l Java -r prime/build/reports/jacoco/test/jacocoTestReport.xml
1 change: 1 addition & 0 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation project(":prime-client-api")

implementation 'io.jsonwebtoken:jjwt:0.9.0'
// tests fail when updated to 2.27
implementation "org.glassfish.jersey.media:jersey-media-json-jackson:2.25.1"

implementation 'junit:junit:4.12'
Expand Down
6 changes: 3 additions & 3 deletions analytics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ plugins {
dependencies {
implementation project(':ocs-api')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation 'com.google.cloud:google-cloud-pubsub:0.46.0-beta'
implementation 'com.google.cloud:google-cloud-pubsub:1.32.0'
implementation 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.4.0'
runtime 'org.apache.beam:beam-runners-google-cloud-dataflow-java:2.4.0'
runtimeOnly 'org.apache.beam:beam-runners-google-cloud-dataflow-java:2.4.0'
implementation 'ch.qos.logback:logback-classic:1.2.3'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
testRuntime 'org.hamcrest:hamcrest-all:1.3'
testRuntimeOnly 'org.hamcrest:hamcrest-all:1.3'
}

shadowJar {
Expand Down
16 changes: 16 additions & 0 deletions app-notifier/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id "java-library"
id "jacoco"
id "com.github.johnrengelman.shadow" version "2.0.4"
id "org.jetbrains.kotlin.jvm" version "1.2.41"
id "idea"
id "project-report"
}

dependencies {
implementation project(":prime-api")
// Keep it to 5.10.0 to match netty via ocs-api
implementation 'com.google.firebase:firebase-admin:6.2.0'

testImplementation "junit:junit:4.12"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.ostelco.prime.appnotifier

import com.google.api.core.ApiFutureCallback
import com.google.api.core.ApiFutures.addCallback
import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import com.google.firebase.messaging.FirebaseMessaging
import com.google.firebase.messaging.Message
import com.google.firebase.messaging.Notification
import org.ostelco.prime.module.getResource
import org.ostelco.prime.storage.legacy.Storage
import java.io.FileInputStream
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths

class FirebaseAppNotifier: AppNotifier {

override fun notify(msisdn: String, title: String, body: String) {
println("Will try to notify msisdn : $msisdn")
sendNotification(msisdn, title, body)
}

private fun sendNotification(msisdn: String, title: String, body: String) {

val store = getResource<Storage>()

// This registration token comes from the client FCM SDKs.
val applicationToken = store.getNotificationToken(msisdn)

if (applicationToken != null) {

// See documentation on defining a message payload.
val message = Message.builder()
.setNotification(Notification(title, body))
.setToken(applicationToken)
.build()

// Send a message to the device corresponding to the provided
// registration token.
val future = FirebaseMessaging
.getInstance(FirebaseApp.getInstance("fcm"))
.sendAsync(message)

val apiFutureCallback = object : ApiFutureCallback<String> {
override fun onSuccess(result: String) {
println("Notification completed with result: $result")
}

override fun onFailure(t: Throwable) {
println("Notification failed with error: $t")
}
}

addCallback(future, apiFutureCallback)
} else {
println("Not able to fetch notification token for msisdn : $msisdn")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.ostelco.prime.appnotifier

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonTypeName
import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import org.hibernate.validator.constraints.NotEmpty
import org.ostelco.prime.module.PrimeModule
import java.io.FileInputStream
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths

@JsonTypeName("firebase-app-notifier")
class FirebaseModule : PrimeModule {

@JsonProperty("config")
fun setConfig(config: FirebaseConfig) {
println("Config set for AppNotifier")
setupFirebaseApp(config.databaseName, config.configFile)
}

private fun setupFirebaseApp(
databaseName: String,
configFile: String) {

try {
println("Setting up Firebase for FirebaseAppNotifier. databaseName : $databaseName , configFile : $configFile ")
val credentials: GoogleCredentials = if (Files.exists(Paths.get(configFile))) {
FileInputStream(configFile).use { serviceAccount -> GoogleCredentials.fromStream(serviceAccount) }
} else {
GoogleCredentials.getApplicationDefault()
}

val options = FirebaseOptions.Builder()
.setCredentials(credentials)
.setDatabaseUrl("https://$databaseName.firebaseio.com/")
.build()
try {
FirebaseApp.getInstance("fcm")
} catch (e: Exception) {
FirebaseApp.initializeApp(options, "fcm")
}

// (un)comment next line to turn on/of extended debugging
// from firebase.
// this.firebaseDatabase.setLogLevel(com.google.firebase.database.Logger.Level.DEBUG);
} catch (ex: IOException) {
throw AppNotifierException(ex)
}
}
}

class FirebaseConfig {

@NotEmpty
@JsonProperty("databaseName")
lateinit var databaseName: String

@NotEmpty
@JsonProperty("configFile")
lateinit var configFile: String
}
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.appnotifier.FirebaseAppNotifier
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.ostelco.prime.appnotifier.FirebaseModule
4 changes: 2 additions & 2 deletions auth-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ plugins {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "io.dropwizard:dropwizard-core:$dropwizardVersion"
implementation 'com.google.firebase:firebase-admin:5.11.0'
implementation 'com.google.firebase:firebase-admin:6.2.0'
testImplementation "io.dropwizard:dropwizard-testing:$dropwizardVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
testRuntime 'org.hamcrest:hamcrest-all:1.3'
testRuntimeOnly 'org.hamcrest:hamcrest-all:1.3'
}

shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subprojects {
}
ext {
kotlinVersion = "1.2.41"
dropwizardVersion = "1.3.2"
dropwizardVersion = "1.3.3"
}
}

Expand Down
9 changes: 5 additions & 4 deletions client-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ dependencies {

implementation "io.dropwizard:dropwizard-auth:$dropwizardVersion"
implementation "io.dropwizard:dropwizard-client:$dropwizardVersion"
implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.google.guava:guava:25.1-jre'

implementation 'io.jsonwebtoken:jjwt:0.9.0'
implementation "io.vavr:vavr:0.9.0"
implementation "io.vavr:vavr:0.9.2"

testImplementation "io.dropwizard:dropwizard-client:$dropwizardVersion"
testImplementation "io.dropwizard:dropwizard-testing:$dropwizardVersion"
testImplementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.5'
testImplementation "org.mockito:mockito-core:2.18.0"
testImplementation 'org.assertj:assertj-core:3.9.1'
testImplementation "org.mockito:mockito-core:2.18.3"
testImplementation 'org.assertj:assertj-core:3.10.0'

// from filter
// https://mvnrepository.com/artifact/org.glassfish.jersey.test-framework.providers/jersey-test-framework-provider-grizzly2
// Updating from 2.25.1 to 2.27 causes error
testCompile (group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-grizzly2', version: '2.25.1') {
// 2.26 (latest)
exclude group: 'javax.servlet', module: 'javax.servlet-api'
Expand Down
2 changes: 1 addition & 1 deletion diameter-stack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
}

testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
testRuntime 'org.hamcrest:hamcrest-all:1.3'
testRuntimeOnly 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.mockito:mockito-all:1.10.19'
}

Expand Down
4 changes: 2 additions & 2 deletions firebase-store/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ plugins {

dependencies {
implementation project(":prime-api")
// Keep it to 5.10.0 to match netty via ocs-api
implementation 'com.google.firebase:firebase-admin:5.10.0'
// Match netty via ocs-api
implementation 'com.google.firebase:firebase-admin:6.2.0'

testImplementation "junit:junit:4.12"
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,22 @@ object FirebaseStorageSingleton : Storage {
balanceStore.delete(msisdn)
}
}

override fun addNotificationToken(msisdn: String, token: String) {
fcmTokenStore.create(msisdn, token)
}

override fun getNotificationToken(msisdn: String): String? {
return fcmTokenStore.get(msisdn)
}
}

val balanceEntity = EntityType("balance", Long::class.java)
val productEntity = EntityType("products", Product::class.java)
val subscriptionEntity = EntityType("subscriptions", String::class.java)
val subscriberEntity = EntityType("subscribers", Subscriber::class.java)
val paymentHistoryEntity = EntityType("paymentHistory", PurchaseRecord::class.java)
val fcmTokenEntity = EntityType("notificationTokens/FCM", String::class.java)

val config = FirebaseConfigRegistry.firebaseConfig
val firebaseDatabase = setupFirebaseInstance(config.databaseName, config.configFile)
Expand All @@ -104,6 +113,7 @@ val productStore = EntityStore(firebaseDatabase, productEntity)
val subscriptionStore = EntityStore(firebaseDatabase, subscriptionEntity)
val subscriberStore = EntityStore(firebaseDatabase, subscriberEntity)
val paymentHistoryStore = EntityStore(firebaseDatabase, paymentHistoryEntity)
val fcmTokenStore = EntityStore(firebaseDatabase, fcmTokenEntity)

private fun setupFirebaseInstance(
databaseName: String,
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 3de3546

Please sign in to comment.