-
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.
Merge pull request #162 from ostelco/develop
New version of pseudonym server
- Loading branch information
Showing
41 changed files
with
633 additions
and
107 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 |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
*.zip | ||
|
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
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
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" | ||
} |
61 changes: 61 additions & 0 deletions
61
app-notifier/src/main/kotlin/org/ostelco/prime/appnotifier/FirebaseAppNotifier.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,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") | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app-notifier/src/main/kotlin/org/ostelco/prime/appnotifier/FirebaseModule.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,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 | ||
} |
1 change: 1 addition & 0 deletions
1
app-notifier/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
app-notifier/src/main/resources/META-INF/services/org.ostelco.prime.appnotifier.AppNotifier
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.appnotifier.FirebaseAppNotifier |
1 change: 1 addition & 0 deletions
1
app-notifier/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.appnotifier.FirebaseModule |
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
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
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
Binary file not shown.
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,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 |
Oops, something went wrong.