This commit is contained in:
parent
ab2c0e8f25
commit
26a52d54e9
@ -15,7 +15,7 @@ services:
|
|||||||
POSTGRES_DB: "output-service-rdb"
|
POSTGRES_DB: "output-service-rdb"
|
||||||
|
|
||||||
output-service-rdb:
|
output-service-rdb:
|
||||||
image: "registry.kmlabz.com/tormakris/output-service-rdb"
|
image: "registry.kmlabz.com/birbnetes/output-service-rdb"
|
||||||
restart: "always"
|
restart: "always"
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
|
@ -9,9 +9,6 @@ import io.ktor.routing.*
|
|||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.gson.*
|
import io.ktor.gson.*
|
||||||
import io.ktor.features.*
|
import io.ktor.features.*
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.engine.apache.*
|
|
||||||
import io.ktor.auth.*
|
|
||||||
import org.apache.http.HttpException
|
import org.apache.http.HttpException
|
||||||
import com.kmalbz.database.DatabaseFactory
|
import com.kmalbz.database.DatabaseFactory
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
@ -31,19 +28,12 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
|||||||
|
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
@Suppress("unused") // Referenced in application.conf
|
@Suppress("unused") // Referenced in application.conf
|
||||||
@kotlin.jvm.JvmOverloads
|
fun Application.module() {
|
||||||
fun Application.module(testing: Boolean = false) {
|
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
gson {
|
gson {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val client = HttpClient(Apache) {
|
|
||||||
}
|
|
||||||
|
|
||||||
install(Authentication) {
|
|
||||||
}
|
|
||||||
|
|
||||||
DatabaseFactory.init()
|
DatabaseFactory.init()
|
||||||
transaction{
|
transaction{
|
||||||
SchemaUtils.create(ResultObjects)
|
SchemaUtils.create(ResultObjects)
|
||||||
@ -82,19 +72,19 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
|
|
||||||
routing {
|
routing {
|
||||||
install(StatusPages) {
|
install(StatusPages) {
|
||||||
exception<AuthenticationException> { _ ->
|
exception<AuthenticationException> {
|
||||||
call.respond(HttpStatusCode.Unauthorized)
|
call.respond(HttpStatusCode.Unauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception<AuthorizationException> { _ ->
|
exception<AuthorizationException> {
|
||||||
call.respond(HttpStatusCode.Forbidden)
|
call.respond(HttpStatusCode.Forbidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception<HttpException> { _ ->
|
exception<HttpException> {
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception<IllegalStateException> { _ ->
|
exception<IllegalStateException> {
|
||||||
call.respond(HttpStatusCode.NotAcceptable)
|
call.respond(HttpStatusCode.NotAcceptable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package com.kmalbz
|
|
||||||
|
|
||||||
data class ApiResponse(
|
|
||||||
val status: String,
|
|
||||||
val message: String
|
|
||||||
)
|
|
@ -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") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
package com.kmalbz.api.model
|
package com.kmalbz.api.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
data class ApiObject(
|
data class ApiObject(
|
||||||
@SerializedName("tag") val tag: String,
|
@SerializedName("tag") val tag: String,
|
||||||
|
@ -13,7 +13,7 @@ import java.time.format.DateTimeFormatter
|
|||||||
*
|
*
|
||||||
* This is the output interface of the Birbnetes system.
|
* This is the output interface of the Birbnetes system.
|
||||||
*/
|
*/
|
||||||
class OutputServiceRDBServer() {
|
class OutputServiceRDBServer {
|
||||||
/**
|
/**
|
||||||
* output
|
* output
|
||||||
*/
|
*/
|
||||||
@ -45,7 +45,7 @@ class OutputServiceRDBServer() {
|
|||||||
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ class OutputServiceRDBServer() {
|
|||||||
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
||||||
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
||||||
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList = resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user