diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml
index 3de5ebb..f8c283c 100644
--- a/.github/workflows/test-and-build.yml
+++ b/.github/workflows/test-and-build.yml
@@ -11,12 +11,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- - name: Cache Maven packages
- uses: actions/cache@v2
- with:
- path: ~/.m2
- key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
- restore-keys: ${{ runner.os }}-m2
- name: Build with gradle
run: ./gradlew shadowJar
env:
diff --git a/.gitignore b/.gitignore
index 378eac2..df03b3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,164 @@
-build
+# Created by https://www.toptal.com/developers/gitignore/api/kotlin,java,gradle,intellij
+# Edit at https://www.toptal.com/developers/gitignore?templates=kotlin,java,gradle,intellij
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+### Kotlin ###
+# Compiled class file
+
+# Log file
+
+# BlueJ files
+
+# Mobile Tools for Java (J2ME)
+
+# Package Files #
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+
+### Gradle ###
+.gradle
+build/
+
+# Ignore Gradle GUI config
+gradle-app.setting
+
+# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
+!gradle-wrapper.jar
+
+# Cache of project
+.gradletasknamecache
+
+# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
+# gradle/wrapper/gradle-wrapper.properties
+
+### Gradle Patch ###
+**/build/
+
+# End of https://www.toptal.com/developers/gitignore/api/kotlin,java,gradle,intellij
\ No newline at end of file
diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin
deleted file mode 100644
index 4dbe502..0000000
Binary files a/.gradle/6.7/executionHistory/executionHistory.bin and /dev/null differ
diff --git a/.gradle/6.7/executionHistory/executionHistory.lock b/.gradle/6.7/executionHistory/executionHistory.lock
deleted file mode 100644
index 749cba5..0000000
Binary files a/.gradle/6.7/executionHistory/executionHistory.lock and /dev/null differ
diff --git a/.gradle/6.7/fileChanges/last-build.bin b/.gradle/6.7/fileChanges/last-build.bin
deleted file mode 100644
index f76dd23..0000000
Binary files a/.gradle/6.7/fileChanges/last-build.bin and /dev/null differ
diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin
deleted file mode 100644
index 73026a8..0000000
Binary files a/.gradle/6.7/fileHashes/fileHashes.bin and /dev/null differ
diff --git a/.gradle/6.7/fileHashes/fileHashes.lock b/.gradle/6.7/fileHashes/fileHashes.lock
deleted file mode 100644
index b664eb8..0000000
Binary files a/.gradle/6.7/fileHashes/fileHashes.lock and /dev/null differ
diff --git a/.gradle/6.7/fileHashes/resourceHashesCache.bin b/.gradle/6.7/fileHashes/resourceHashesCache.bin
deleted file mode 100644
index 87ae055..0000000
Binary files a/.gradle/6.7/fileHashes/resourceHashesCache.bin and /dev/null differ
diff --git a/.gradle/6.7/gc.properties b/.gradle/6.7/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
deleted file mode 100644
index e53acfc..0000000
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
deleted file mode 100644
index ebecf16..0000000
--- a/.gradle/buildOutputCleanup/cache.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-#Mon Feb 22 11:21:06 EET 2021
-gradle.version=6.7
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
deleted file mode 100644
index 32bcb8b..0000000
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and /dev/null differ
diff --git a/.gradle/checksums/checksums.lock b/.gradle/checksums/checksums.lock
deleted file mode 100644
index 4146551..0000000
Binary files a/.gradle/checksums/checksums.lock and /dev/null differ
diff --git a/.gradle/checksums/md5-checksums.bin b/.gradle/checksums/md5-checksums.bin
deleted file mode 100644
index 420be11..0000000
Binary files a/.gradle/checksums/md5-checksums.bin and /dev/null differ
diff --git a/.gradle/checksums/sha1-checksums.bin b/.gradle/checksums/sha1-checksums.bin
deleted file mode 100644
index 0d12703..0000000
Binary files a/.gradle/checksums/sha1-checksums.bin and /dev/null differ
diff --git a/.gradle/configuration-cache/gc.properties b/.gradle/configuration-cache/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties
deleted file mode 100644
index e69de29..0000000
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 213e9f6..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 774dad5..6024456 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index ac90364..977788c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,5 +1,5 @@
plugins {
- kotlin("jvm") version "1.4.21"
+ kotlin("jvm") version "1.5.21"
id("com.github.johnrengelman.shadow") version "6.0.0"
}
@@ -11,10 +11,10 @@ repositories {
jcenter()
maven{
name = "GitHub transitdata-common"
- url = uri("https://maven.pkg.github.com/hsldevcom/transitdata-common")
+ url = uri("https://maven.pkg.github.com/hsldevcom/*")
credentials {
- username = System.getenv("GITHUB_ACTOR")
- password = System.getenv("GITHUB_TOKEN")
+ username = (project.findProperty("github.user") ?: System.getenv("GITHUB_ACTOR")).toString()
+ password = (project.findProperty("github.token") ?: System.getenv("GITHUB_TOKEN")).toString()
}
}
}
@@ -34,12 +34,18 @@ val jar by tasks.getting(Jar::class){
dependencies {
- testImplementation(kotlin("test-junit"))
- implementation ("fi.hsl:transitdata-common:1.3.22")
- implementation ("io.github.microutils:kotlin-logging:1.6.22")
- implementation ("io.ktor:ktor:1.5.1")
+ testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.5.21")
+
+ implementation ("fi.hsl:transitdata-common:1.3.25")
+
+ implementation ("io.github.microutils:kotlin-logging:2.0.11")
+
+ implementation ("io.ktor:ktor:1.6.3")
+ implementation("io.ktor:ktor-server-netty:1.6.4")
+
+ implementation("org.json:json:20210307")
+
//implementation (fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
- implementation("io.ktor:ktor-server-netty:1.5.1")
}
tasks.test {
diff --git a/src/main/kotlin/fi/hsl/ekecheck/DataHolder.kt b/src/main/kotlin/fi/hsl/ekecheck/DataHolder.kt
index 3e0d01b..0534a4c 100644
--- a/src/main/kotlin/fi/hsl/ekecheck/DataHolder.kt
+++ b/src/main/kotlin/fi/hsl/ekecheck/DataHolder.kt
@@ -1,18 +1,13 @@
package fi.hsl.ekecheck
-import fi.hsl.common.transitdata.proto.Eke
-
object DataHolder {
- val dataMap = mutableMapOf>()
+ private val dataMap = mutableMapOf>()
- fun getTrainData(unitNumber : String) : MutableMap?{
- return dataMap[unitNumber]
+ fun getTrainData(unitNumber: String): Map? {
+ return dataMap[unitNumber]?.toMap()
}
- fun putEkeSummary(ekeSummary : EkeSummaryDTO){
- if(dataMap[ekeSummary.unitNumber] == null){
- dataMap[ekeSummary.unitNumber] = mutableMapOf()
- }
- dataMap[ekeSummary.unitNumber]!![ekeSummary.topic] = ekeSummary
+ fun putEkeSummary(ekeSummary: EkeSummaryDTO) {
+ dataMap.computeIfAbsent(ekeSummary.unitNumber) { mutableMapOf() }[ekeSummary.topic] = ekeSummary
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/fi/hsl/ekecheck/MessageHandler.kt b/src/main/kotlin/fi/hsl/ekecheck/MessageHandler.kt
index 27a767e..0431438 100644
--- a/src/main/kotlin/fi/hsl/ekecheck/MessageHandler.kt
+++ b/src/main/kotlin/fi/hsl/ekecheck/MessageHandler.kt
@@ -12,11 +12,18 @@ import org.apache.pulsar.client.api.MessageId
const val TOPIC_PREFIX = "eke/v1/sm5/"
-class MessageHandler(val context: PulsarApplicationContext) : IMessageHandler {
-
+class MessageHandler(context: PulsarApplicationContext) : IMessageHandler {
private val consumer: Consumer = context.consumer!!
private val log = KotlinLogging.logger {}
+
+ private var messageCounter = 0;
+
override fun handleMessage(received: Message) {
+ if (messageCounter++ >= 10000) {
+ log.info { "Handled 10000 messages, everything seems fine" }
+ messageCounter = 0
+ }
+
try {
if (TransitdataSchema.hasProtobufSchema(received, TransitdataProperties.ProtobufSchema.EkeSummary)) {
val ekeSummary = Eke.EkeSummary.parseFrom(received.data)
diff --git a/src/main/kotlin/fi/hsl/ekecheck/WebsiteController.kt b/src/main/kotlin/fi/hsl/ekecheck/WebsiteController.kt
index 2608881..2641494 100644
--- a/src/main/kotlin/fi/hsl/ekecheck/WebsiteController.kt
+++ b/src/main/kotlin/fi/hsl/ekecheck/WebsiteController.kt
@@ -5,9 +5,8 @@ import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.response.*
import io.ktor.routing.*
-import org.apache.pulsar.shade.com.google.gson.JsonArray
-import org.apache.pulsar.shade.com.google.gson.JsonObject
-import java.io.File
+import org.json.JSONArray
+import org.json.JSONObject
import java.time.Instant
object WebsiteController {
@@ -27,22 +26,23 @@ object WebsiteController {
fun Route.customerRouting(){
route("/api/train/{unitNumber}"){
- get{
- val jsonArray = JsonArray()
+ get {
+ val jsonArray = JSONArray()
val unitNumber = call.parameters["unitNumber"]
- if(unitNumber != null){
+ if (unitNumber != null) {
val trainData = DataHolder.getTrainData(unitNumber)
- if(trainData != null && trainData.isNotEmpty()) {
+ if (trainData != null && trainData.isNotEmpty()) {
trainData.values.forEach {
- val jsonObject = JsonObject()
- jsonObject.addProperty("unitNumber",it.unitNumber)
- jsonObject.addProperty("ekeDate", Instant.ofEpochMilli(it.timestamp).toString())
- jsonObject.addProperty("topicPart",it.topic)
- jsonArray.add(jsonObject)
+ val jsonObject = JSONObject()
+ jsonObject.put("unitNumber", it.unitNumber)
+ jsonObject.put("ekeDate", Instant.ofEpochMilli(it.timestamp).toString())
+ jsonObject.put("topicPart", it.topic)
+
+ jsonArray.put(jsonObject)
}
}
}
- call.respondText(jsonArray.toString(), ContentType.parse("application/json" ))
+ call.respondText(jsonArray.toString(4), ContentType.parse("application/json" ))
}
}
}
diff --git a/src/main/resources/environment.conf b/src/main/resources/environment.conf
index 7309a81..064c5e7 100644
--- a/src/main/resources/environment.conf
+++ b/src/main/resources/environment.conf
@@ -12,19 +12,6 @@ pulsar {
}
}
-doi {
- timezone="Europe/Helsinki"
- timezone=${?DOI_TIMEZONE}
- queryFutureDays=5 #How many days into future to query data for?
- queryFutureDays=${?DOI_QUERY_FUTURE_DAYS}
-}
-
application {
- blobConnectionString=""
- blobConnectionString=${?BLOBSTORAGE_ENDPOINT}
- blobContainer="eke-csv"
- blobContainer=${?BLOBCONTAINER}
- outputformat="csv"
- outputformat=${?OUTPUT_FORMAT}
}