Add database path --do-not-notify parameters to backend

This commit is contained in:
Matte23
2021-01-22 15:21:30 +01:00
parent 6246a47b8f
commit 78bfec6919
4 changed files with 37 additions and 17 deletions

View File

@@ -27,15 +27,15 @@ object JavaDatabase {
@Volatile
private var instance: AppDatabase? = null
private fun getInstance(): AppDatabase {
private fun getInstance(path: String): AppDatabase {
return instance ?: synchronized(this) {
instance ?: AppDatabase(
DatabaseDriverFactory().createDriver()
DatabaseDriverFactory(path).createDriver()
).also { instance = it }
}
}
fun getDaoInstance(): CircularDao {
return CircularDao(getInstance())
fun getDaoInstance(path: String): CircularDao {
return CircularDao(getInstance(path))
}
}

View File

@@ -28,13 +28,29 @@ const val CHECK_DELAY_MILLIS = 900000L
fun main(args: Array<String>) {
print("Starting Circolapp Push microservice \n")
if (args.isEmpty()) {
print("ERROR: Database path not specified! Please specify the database path as a parameter \n")
return
} else {
print("Database path is: " + args[0] + " \n")
}
var enableNotifications = true
if (args.size >= 2 && args[1] == "--do-not-notify") {
print("Notifications are disabled \n")
enableNotifications = false
}
print("Initializing Firebase SDK \n")
val options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.build()
FirebaseApp.initializeApp(options)
val serverUtils = ServerUtils()
print("Initializing database and server interfaces \n")
val serverUtils = ServerUtils(args[0], enableNotifications)
print("Microservice started! \n")
runBlocking {

View File

@@ -23,10 +23,10 @@ import net.underdesk.circolapp.shared.server.KtorFactory
import net.underdesk.circolapp.shared.server.Server
import net.underdesk.circolapp.shared.server.ServerAPI
class ServerUtils {
class ServerUtils(databasePath: String, private val enableNotifications: Boolean = true) {
private val serverList: MutableList<Server> = mutableListOf()
private val ktorClient = KtorFactory().createClient()
private val circularDao = JavaDatabase.getDaoInstance()
private val circularDao = JavaDatabase.getDaoInstance(databasePath)
init {
for (serverId in ServerAPI.Companion.Servers.values()) {
@@ -75,14 +75,18 @@ class ServerUtils {
if (newCirculars.second >= 0 && newCirculars.first.isNotEmpty()) {
for (circular in newCirculars.first) {
PushNotificationUtils.createPushNotification(
circular,
ServerAPI.getServerTopic(server.serverID)
)
PushNotificationUtils.createPushNotificationiOS(
circular,
ServerAPI.getServerTopic(server.serverID)
)
if (enableNotifications) {
PushNotificationUtils.createPushNotification(
circular,
ServerAPI.getServerTopic(server.serverID)
)
PushNotificationUtils.createPushNotificationiOS(
circular,
ServerAPI.getServerTopic(server.serverID)
)
} else {
print("Skipping notification for circular ${circular.id} of school ${circular.school} \n")
}
}
}
}