fix errors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-04-06 01:43:43 +02:00
parent a43b692acf
commit f4ce568aa8
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
4 changed files with 24 additions and 13 deletions

View File

@ -25,7 +25,7 @@ services:
POSTGRES_DB: "output-service-rdb"
DB_URL: "jdbc:postgresql://output-service-postgres:5432/output-service-rdb"
MQ_HOST: rabbitmq
MQ_USERNMAE: rabbitmq
MQ_USERNAME: rabbitmq
MQ_PASSWORD: rabbitmq
depends_on:
- rabbitmq

View File

@ -26,6 +26,7 @@ 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
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@ -45,21 +46,27 @@ fun Application.module(testing: Boolean = false) {
}
DatabaseFactory.init()
transaction{
SchemaUtils.create(ResultObjects)
}
val appConfig = HoconApplicationConfig(ConfigFactory.load())
val factory = ConnectionFactory()
factory.host = appConfig.property("mq.host").getString()
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, "FANOUT")
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("test_queue") {
consume(queueName) {
consumeMessageWithConfirm({
val resultObjectService = ResultObjectService()
val rawJson = String(it.body)
@ -93,6 +100,10 @@ fun Application.module(testing: Boolean = false) {
exception<HttpException> { _ ->
call.respond(HttpStatusCode.BadRequest)
}
exception<IllegalStateException> { _ ->
call.respond(HttpStatusCode.NotAcceptable)
}
}
OutputServiceRDBServer().apply {

View File

@ -24,13 +24,13 @@ class OutputServiceRDBServer() {
}
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
@ -39,7 +39,7 @@ class OutputServiceRDBServer() {
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) ?: error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
@ -48,14 +48,14 @@ class OutputServiceRDBServer() {
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) ?: error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/{tagID}") {
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: error(HttpStatusCode.NotFound)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultObject)
}

View File

@ -14,11 +14,11 @@ object DatabaseFactory {
@KtorExperimentalAPI
private val appConfig = HoconApplicationConfig(ConfigFactory.load())
@KtorExperimentalAPI
private val dbUrl = appConfig.property("db.jdbc").getString()
private val dbUrl = appConfig.property("ktor.db.jdbc").getString()
@KtorExperimentalAPI
private val dbUser = appConfig.property("db.user").getString()
private val dbUser = appConfig.property("ktor.db.user").getString()
@KtorExperimentalAPI
private val dbPassword = appConfig.property("db.password").getString()
private val dbPassword = appConfig.property("ktor.db.password").getString()
@KtorExperimentalAPI
fun init() {