Compare commits

...

41 Commits

Author SHA1 Message Date
f7757d31fb upload to docker hub
All checks were successful
continuous-integration/drone/push Build is passing
2022-01-31 23:16:41 +01:00
d638b98d1a Merge branch 'master' of ssh://git.kmlabz.com:2222/birbnetes/output-service-rdb
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-18 16:44:39 +02:00
4fc8db6fa4 use kotlin serialize 2021-08-18 16:44:29 +02:00
1997df3da9 remove deprecated stuff
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 18:00:11 +02:00
f46386d465 get count from db layer as well
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 16:09:10 +02:00
4f67c48f7a pagination in db layer
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 15:57:58 +02:00
5f2d88d3d2 pajeet nation
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 15:34:49 +02:00
9c432ae60d update koin
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-16 14:29:49 +02:00
ac4e01b1e9 update gradle
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-12 12:25:23 +02:00
3c3beff2e4 remove consumer and update deps
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-12 12:24:03 +02:00
9793ccc593 update dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2020-11-19 02:38:15 +01:00
204dfcabbc Update 'k8s/deployment.yml'
All checks were successful
continuous-integration/drone/push Build is passing
2020-08-06 14:57:26 +02:00
f27eec0f8f update manifests
All checks were successful
continuous-integration/drone/push Build is passing
2020-08-02 15:29:22 +00:00
264545215b analysis via sonar
All checks were successful
continuous-integration/drone/push Build is passing
2020-07-07 22:58:09 +02:00
2b89400168 use string instead of uuid
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-29 13:27:53 +02:00
8d7f05d122 add back notification
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-29 13:25:22 +02:00
0615d63610 Merge pull request 'Merge improvements' (#1) from kotlin-hazi into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-29 13:23:31 +02:00
597c0a24db charset utf8
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build is passing
2020-05-22 04:45:32 +02:00
9074619914 queue name
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-22 04:34:16 +02:00
495ebae5f9 use a consumer to interact with db
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-22 04:29:58 +02:00
0e5f4e593f remove cache
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-22 03:41:40 +02:00
609a90adc2 use uuid
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-22 03:40:09 +02:00
062f2c9ede remove unneeded junk
Some checks reported errors
continuous-integration/drone/push Build was killed
2020-05-20 17:37:36 +02:00
24692d7635 don't use cgroups in docker
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-20 17:12:29 +02:00
d4a2d9925c use fancy di
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-20 17:06:15 +02:00
d8e0819f00 fucking adduser
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-20 15:43:41 +02:00
15095f2d9f revert to old build script
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:37:21 +02:00
f2cb3e4e91 hasznalj java 11-et te geci
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:24:27 +02:00
82f64dcfdf use default jre
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:22:57 +02:00
cba0e79b08 target java 11
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:22:10 +02:00
da708d2347 use oracle base image
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:19:54 +02:00
a68abd2c6b add stuff
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-20 15:16:29 +02:00
c84b4a597e bumb kotlin version
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-20 15:06:00 +02:00
26a52d54e9 ide suggestions
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-20 14:59:08 +02:00
ab2c0e8f25 use host path volume
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-08 22:38:25 +02:00
92401f69cb cache gradle
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-06 15:21:07 +02:00
03df50a4fa use kaniko to build container image
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-28 19:22:03 +02:00
5d3bd760b6 fix drone lint
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-28 17:48:07 +02:00
1e3cd454da update docker namespace and add teams webhook 2020-04-28 17:42:38 +02:00
cb3f9874a8 Merge branch 'master' of gitea:birbnetes/output-service-rdb
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-13 16:21:33 +02:00
2bfc385681 configurable exchange 2020-04-13 16:21:02 +02:00
22 changed files with 188 additions and 382 deletions

View File

@ -3,36 +3,48 @@ type: docker
name: default
steps:
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
sonar_host:
from_secret: SONAR_HOST
sonar_token:
from_secret: SONAR_CODE
- name: build_application
image: openjdk:8-jdk
image: openjdk:11-jdk
commands:
- ./gradlew build -x test
- name: build_container
image: docker:stable-dind
volumes:
- name: dockersock
path: /var/run
environment:
DOCKER_USERNAME:
- name: kaniko
image: banzaicloud/drone-kaniko
settings:
registry: registry.kmlabz.com
repo: birbnetes/${DRONE_REPO_NAME}
username:
from_secret: DOCKER_USERNAME
DOCKER_PASSWORD:
password:
from_secret: DOCKER_PASSWORD
commands:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin registry.kmlabz.com
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME" .
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME:$DRONE_BUILD_NUMBER" .
- docker push "registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME"
- docker push "registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME:$DRONE_BUILD_NUMBER"
tags:
- latest
- ${DRONE_BUILD_NUMBER}
services:
- name: docker
image: docker:stable-dind
privileged: true
volumes:
- name: dockersock
path: /var/run
- name: dockerhub
image: plugins/docker
settings:
repo: birbnetes/${DRONE_REPO_NAME}
username:
from_secret: DOCKERHUB_USER
password:
from_secret: DOCKERHUB_PASSWORD
tags:
- latest
- ${DRONE_BUILD_NUMBER}
volumes:
- name: dockersock
temp: {}
- name: ms-teams
image: kuperiu/drone-teams
settings:
webhook:
from_secret: TEAMS_WEBHOOK
when:
status: [ failure ]

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
*.iml
*.ipr
*.iws
*.log

View File

@ -1,7 +1,7 @@
FROM openjdk:8-jre-alpine
FROM openjdk:11-jre
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN useradd $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
@ -11,4 +11,4 @@ USER $APPLICATION_USER
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]

View File

@ -7,10 +7,21 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'application'
@ -32,29 +43,35 @@ repositories {
}
dependencies {
compile 'org.postgresql:postgresql:42.2.2'
compile 'org.jetbrains.exposed:exposed-core:0.23.1'
compile 'org.jetbrains.exposed:exposed-dao:0.23.1'
compile 'org.jetbrains.exposed:exposed-jdbc:0.23.1'
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
compile 'com.rabbitmq:amqp-client:2.7.1'
compile 'com.zaxxer:HikariCP:2.7.8'
compile 'com.viartemev:the-white-rabbit:0.0.5'
compile 'org.postgresql:postgresql:42.2.23'
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
compile 'com.zaxxer:HikariCP:5.0.0'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.2.1"
implementation "io.insert-koin:koin-core:$koin_version"
implementation "io.insert-koin:koin-ktor:$koin_version"
implementation "io.ktor:ktor-serialization:$ktor_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
implementation "io.ktor:ktor-server-host-common:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
implementation "io.ktor:ktor-client-apache:$ktor_version"
implementation "io.ktor:ktor-auth:$ktor_version"
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}
kotlin.experimental.coroutines = 'enable'
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "11"
}
}
shadowJar {
baseName = 'output-service-rdb'

View File

@ -15,7 +15,7 @@ services:
POSTGRES_DB: "output-service-rdb"
output-service-rdb:
image: "registry.kmlabz.com/tormakris/output-service-rdb"
image: "registry.kmlabz.com/birbnetes/output-service-rdb"
restart: "always"
ports:
- "127.0.0.1:8080:8080"

View File

@ -1,4 +1,5 @@
ktor_version=1.3.2
ktor_version=1.6.2
kotlin.code.style=official
kotlin_version=1.3.70
logback_version=1.2.1
kotlin_version=1.5.21
logback_version=1.2.5
koin_version=3.1.2

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

View File

@ -12,4 +12,4 @@ data:
DB_PASSWORD: output-service-supersecret
MQ_HOST: birb-rabbitmq
MQ_USERNAME: user
MQ_PASSWORD: 1wZVQnP5vy
MQ_PASSWORD: F3ACadDRsT

View File

@ -18,7 +18,8 @@ spec:
app: output-service-rdb
spec:
containers:
- image: registry.kmlabz.com/tormakris/output-service-rdb
- image: registry.kmlabz.com/birbnetes/output-service-rdb
imagePullPolicy: Always
name: output-service-rdb
envFrom:
- configMapRef:

View File

@ -15,5 +15,7 @@ ktor {
host = ${MQ_HOST}
username = ${MQ_USERNAME}
password = ${MQ_PASSWORD}
exchange = "output"
exchange = ${?MQ_EXCHANGE}
}
}

View File

@ -1,48 +1,32 @@
package com.kmalbz
import com.google.gson.Gson
import com.kmalbz.api.model.ApiObject
import com.kmalbz.api.route.OutputServiceRDBServer
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.features.*
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.auth.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import com.kmalbz.database.dao.ResultObjects
import com.kmalbz.database.service.ResultObjectService
import com.kmalbz.mq.RecieveOutput
import io.ktor.serialization.*
import io.ktor.util.KtorExperimentalAPI
import com.rabbitmq.client.*
import com.typesafe.config.ConfigFactory
import io.ktor.config.HoconApplicationConfig
import com.viartemev.thewhiterabbit.channel.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.koin.ktor.ext.Koin
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@KtorExperimentalAPI
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
fun Application.module() {
install(ContentNegotiation) {
gson {
}
json()
}
val client = HttpClient(Apache) {
}
install(Authentication) {
install(Koin) {
printLogger()
modules(com.kmalbz.di.injectionModule)
}
DatabaseFactory.init()
@ -50,58 +34,13 @@ fun Application.module(testing: Boolean = false) {
SchemaUtils.create(ResultObjects)
}
val appConfig = HoconApplicationConfig(ConfigFactory.load())
val factory = ConnectionFactory()
factory.host = appConfig.property("ktor.mq.host").getString()
factory.username = appConfig.property("ktor.mq.username").getString()
factory.password = appConfig.property("ktor.mq.password").getString()
val connection = factory.newConnection()
val channel = connection.createChannel()
channel.exchangeDeclare(RecieveOutput.EXCHANGE_NAME, BuiltinExchangeType.FANOUT)
val queueName = channel.queueDeclare().queue
channel.queueBind(queueName, RecieveOutput.EXCHANGE_NAME, "")
GlobalScope.launch(Dispatchers.Default) {
connection.channel {
consume(queueName) {
consumeMessageWithConfirm({
val resultObjectService = ResultObjectService()
val rawJson = String(it.body)
val gson = Gson()
val apiObject = gson.fromJson(rawJson,ApiObject::class.java)
resultObjectService.addOne(apiObject)
})
}
}
}
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
get("/json/gson") {
call.respond(mapOf("hello" to "world"))
}
install(StatusPages) {
exception<AuthenticationException> { _ ->
call.respond(HttpStatusCode.Unauthorized)
}
exception<AuthorizationException> { _ ->
call.respond(HttpStatusCode.Forbidden)
}
exception<HttpException> { _ ->
exception<HttpException> {
call.respond(HttpStatusCode.BadRequest)
}
exception<IllegalStateException> { _ ->
exception<IllegalStateException> {
call.respond(HttpStatusCode.NotAcceptable)
}
}
@ -111,7 +50,3 @@ fun Application.module(testing: Boolean = false) {
}
}
}
class AuthenticationException : RuntimeException()
class AuthorizationException : RuntimeException()

View File

@ -1,6 +0,0 @@
package com.kmalbz
data class ApiResponse(
val status: String,
val message: String
)

View File

@ -1,77 +0,0 @@
package com.kmalbz
import io.ktor.client.*
import io.ktor.client.request.*
import java.util.*
import com.kmalbz.database.model.ResultObject
/**
* Output Service - RDB Client
*
* This is the feature extraction interface of the Birbnetes system.
*/
open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient = HttpClient()) {
/**
* Get all negative decision objects
*
* @return Array of decision objects
*/
suspend fun getallnegative(
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/negative") {
}
}
/**
* Get positive decision objects
*
* @return Array of decision objects
*/
suspend fun getallpositive(
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/positive") {
}
}
/**
* Get decision before a date
*
* @param dateAfter Date of filter
*
* @return Array of decision objects
*/
suspend fun getallafter(
dateAfter: Date // PATH
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/after/$dateAfter") {
}
}
/**
* Get decision before a date
*
* @param dateBefore Date of filter
*
* @return Array of decision objects
*/
suspend fun getallbefore(
dateBefore: Date // PATH
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/before/$dateBefore") {
}
}
/**
* Get decision by ID
*
* @param tagID ID of wave file
*
* @return Decision object
*/
suspend fun getDecision(
tagID: Int // PATH
): ResultObject {
return client.get<ResultObject>("$endpoint/output/$tagID") {
}
}
}

View File

@ -1,9 +1,9 @@
package com.kmalbz.api.model
import com.google.gson.annotations.SerializedName
import java.time.LocalDate
import kotlinx.serialization.Serializable
@Serializable
data class ApiObject(
@SerializedName("tag") val tag: String,
@SerializedName("probability") val probability: Double
val tag: String,
val probability: Double
)

View File

@ -1,60 +1,76 @@
package com.kmalbz.api.route
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.http.*
import com.kmalbz.database.service.ResultObjectService
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import com.kmalbz.database.service.IResultObjectService
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.response.respond
import io.ktor.routing.Routing
import io.ktor.routing.get
import kotlinx.datetime.LocalDateTime
import org.koin.ktor.ext.inject
/**
* Output Service - RDB
*
* This is the output interface of the Birbnetes system.
*/
class OutputServiceRDBServer() {
class OutputServiceRDBServer {
/**
* output
*/
private val resultObjectService = ResultObjectService()
fun Routing.registerOutput() {
val resultObjectService: IResultObjectService by inject()
get("/output") {
call.respond(resultObjectService.getAllResultObjects())
}
get("/output/count") {
call.respond(resultObjectService.getCount())
}
get("/output/page/{page}") {
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
val pageNum = page.toLong()
call.respond(resultObjectService.getPage(pageNum))
}
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecLessthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList = resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecGreaterthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/undecided") {
val resultList = resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecEqualsProbability(0.5)
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
val localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectafterDate(localDateAfter)
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
val localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectbeforeDate(localDateBefore)
call.respond(resultList)
}

View File

@ -2,12 +2,12 @@ package com.kmalbz.database.dao
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.`java-time`.date
import java.time.LocalDate
import org.jetbrains.exposed.sql.`java-time`.datetime
import java.time.LocalDateTime
object ResultObjects : IntIdTable() {
val tag: Column<String> = varchar("tag", 32)
val date: Column<LocalDate> = date("date").default(LocalDate.now())
val date: Column<LocalDateTime> = datetime("date").default(LocalDateTime.now())
val probability: Column<Double> = double("probability")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
}

View File

@ -0,0 +1,18 @@
package com.kmalbz.database.service
import com.kmalbz.api.model.ApiObject
import kotlinx.datetime.LocalDateTime
interface IResultObjectService{
fun addOne(apiObject: ApiObject)
suspend fun getAllResultObjects(): List<ApiObject>
suspend fun getCount(): Long
suspend fun getPage(page: Long): List<ApiObject>
suspend fun getResultObjectbyTag(tag: String): ApiObject?
suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>
}

View File

@ -4,16 +4,17 @@ import com.kmalbz.database.DatabaseFactory.dbQuery
import com.kmalbz.database.model.ResultObject
import com.kmalbz.database.dao.ResultObjects
import com.kmalbz.api.model.ApiObject
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.toJavaLocalDateTime
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDate
class ResultObjectService {
class ResultObjectService : IResultObjectService {
fun addOne(apiObject: ApiObject) {
override fun addOne(apiObject: ApiObject) {
transaction {
ResultObject.new {
tag = apiObject.tag
@ -22,48 +23,56 @@ class ResultObjectService {
}
}
suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
override suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
ResultObjects.selectAll().map { toResultObject(it) }
}
suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
override suspend fun getCount(): Long = dbQuery {
ResultObjects.selectAll().count()
}
override suspend fun getPage(page: Long): List<ApiObject> = dbQuery {
ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) }
}
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
ResultObjects.select {
(ResultObjects.tag eq tag)
}.mapNotNull { toResultObject(it) }
.singleOrNull()
}
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date eq date)
(ResultObjects.date eq date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date less date)
(ResultObjects.date less date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date greater date)
(ResultObjects.date greater date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability greater probability)
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability less probability)
}.mapNotNull { toResultObject(it) }
}
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability eq probability)
}.mapNotNull { toResultObject(it) }

View File

@ -0,0 +1,9 @@
package com.kmalbz.di
import com.kmalbz.database.service.IResultObjectService
import com.kmalbz.database.service.ResultObjectService
import org.koin.dsl.module
val injectionModule = module(createdAtStart = true) {
single<IResultObjectService> {ResultObjectService()}
}

View File

@ -1,7 +0,0 @@
package com.kmalbz.mq
class RecieveOutput {
companion object {
const val EXCHANGE_NAME = "output"
}
}

View File

@ -1,30 +0,0 @@
package com.kmalbz
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.features.*
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.auth.*
import kotlin.reflect.*
import java.util.*
import kotlin.test.*
import io.ktor.server.testing.*
import io.ktor.util.KtorExperimentalAPI
class ApplicationTest {
@KtorExperimentalAPI
@Test
fun testRoot() {
withTestApplication({ module(testing = true) }) {
handleRequest(HttpMethod.Get, "/").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals("HELLO WORLD!", response.content)
}
}
}
}

View File

@ -1,95 +0,0 @@
package com.kmalbz
import io.ktor.config.*
import io.ktor.http.*
import io.ktor.server.testing.*
import kotlin.test.*
class SwaggerRoutesTest {
/**
* @see OutputServiceRDBServer.getallnegative
*/
@Test
fun testGetallnegative() {
withTestApplication {
// @TODO: Adjust path as required
handleRequest(HttpMethod.Get, "/output/filter/negative") {
}.apply {
// @TODO: Your test here
assertEquals(HttpStatusCode.OK, response.status())
}
}
}
/**
* @see OutputServiceRDBServer.getallpositive
*/
@Test
fun testGetallpositive() {
withTestApplication {
// @TODO: Adjust path as required
handleRequest(HttpMethod.Get, "/output/filter/positive") {
}.apply {
// @TODO: Your test here
assertEquals(HttpStatusCode.OK, response.status())
}
}
}
/**
* @see OutputServiceRDBServer.getallafter
*/
@Test
fun testGetallafter() {
withTestApplication {
// @TODO: Adjust path as required
handleRequest(HttpMethod.Get, "/output/after/{dateAfter}") {
}.apply {
// @TODO: Your test here
assertEquals(HttpStatusCode.OK, response.status())
}
}
}
/**
* @see OutputServiceRDBServer.getallbefore
*/
@Test
fun testGetallbefore() {
withTestApplication {
// @TODO: Adjust path as required
handleRequest(HttpMethod.Get, "/output/before/{dateBefore}") {
}.apply {
// @TODO: Your test here
assertEquals(HttpStatusCode.OK, response.status())
}
}
}
/**
* @see OutputServiceRDBServer.getDecision
*/
@Test
fun testGetDecision() {
withTestApplication {
// @TODO: Adjust path as required
handleRequest(HttpMethod.Get, "/output/{tagID}") {
}.apply {
// @TODO: Your test here
assertEquals(HttpStatusCode.OK, response.status())
}
}
}
fun <R> withTestApplication(test: TestApplicationEngine.() -> R): R {
return withApplication(createTestEnvironment()) {
(environment.config as MapApplicationConfig).apply {
put("jwt.secret", "TODO-change-this-supersecret-or-use-SECRET-env")
}
application.module()
test()
}
}
//fun TestApplicationRequest.setBodyJson(value: Any?) = setBody(Gson.stringify(value))
}