aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-jooby/src/main
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
committerRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
commitebce2c4b839c0b2f8be78bc31c1ce12c45a0164c (patch)
tree7cac3c5449eb8aa398b279d62d9a67ed34fa4115 /kvision-modules/kvision-server-jooby/src/main
parent470953c78c2509224bb452c16f8bbea54e53b3d7 (diff)
downloadkvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.gz
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.bz2
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.zip
Major refactoring of the multi-platform components.
Dependencies upgrade. A lot of code style fixes.
Diffstat (limited to 'kvision-modules/kvision-server-jooby/src/main')
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt7
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt40
-rw-r--r--kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/Date.kt (renamed from kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/KDate.kt)24
3 files changed, 36 insertions, 35 deletions
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
index 76f1ee30..38edc1b8 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
@@ -19,8 +19,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-@file:Suppress("EXPERIMENTAL_FEATURE_WARNING")
-
package pl.treksoft.kvision.remote
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
@@ -31,6 +29,7 @@ import org.jooby.Kooby
import org.jooby.Session
import org.jooby.json.Jackson
import org.pac4j.core.profile.CommonProfile
+import java.text.SimpleDateFormat
import kotlinx.coroutines.async as coroutinesAsync
/**
@@ -42,7 +41,9 @@ actual open class KVServer(init: KVServer.() -> Unit) : Kooby() {
assets("/", "index.html")
@Suppress("LeakingThis")
assets("/**").onMissing(0)
- val mapper = jacksonObjectMapper()
+ val mapper = jacksonObjectMapper().apply {
+ dateFormat = SimpleDateFormat("YYYY-MM-DD HH:mm:ss")
+ }
@Suppress("LeakingThis")
use(Jackson(mapper))
@Suppress("LeakingThis")
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
index b37d7319..3091ce26 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
@@ -28,11 +28,11 @@ import org.jooby.Response
import org.jooby.Status
import org.slf4j.Logger
import org.slf4j.LoggerFactory
+import java.text.SimpleDateFormat
/**
* Multiplatform service manager.
*/
-@Suppress("EXPERIMENTAL_FEATURE_WARNING")
actual open class ServiceManager<out T> actual constructor(val service: T) {
companion object {
@@ -40,7 +40,9 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
}
protected val routes: MutableList<KVServer.() -> Unit> = mutableListOf()
- val mapper = jacksonObjectMapper()
+ val mapper = jacksonObjectMapper().apply {
+ dateFormat = SimpleDateFormat("YYYY-MM-DD HH:mm:ss")
+ }
var counter: Int = 0
/**
@@ -50,12 +52,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified RET> bind(
noinline function: T.(Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -75,7 +78,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -85,12 +88,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR, reified RET> bind(
noinline function: T.(PAR, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -115,7 +119,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -125,12 +129,13 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified RET> bind(
noinline function: T.(PAR1, PAR2, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
@@ -156,7 +161,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -166,15 +171,17 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 3) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -198,7 +205,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -208,15 +215,17 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, PAR4, Request?) -> Deferred<RET>,
route: String?, method: RpcHttpMethod, prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 4) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -242,7 +251,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
/**
@@ -252,6 +261,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
* @param method a HTTP method
* @param prefix an URL address prefix
*/
+ @Suppress("TooGenericExceptionCaught")
protected actual inline fun <reified PAR1, reified PAR2, reified PAR3,
reified PAR4, reified PAR5, reified RET> bind(
noinline function: T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> Deferred<RET>,
@@ -260,10 +270,11 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
prefix: String
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- routes.add({
+ routes.add {
call(method, "$prefix$routeDef") { req, res ->
if (service != null) {
val jsonRpcRequest = req.body(JsonRpcRequest::class.java)
+ @Suppress("MagicNumber")
if (jsonRpcRequest.params.size == 5) {
val param1 = getParameter<PAR1>(jsonRpcRequest.params[0])
val param2 = getParameter<PAR2>(jsonRpcRequest.params[1])
@@ -292,7 +303,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
res.status(Status.SERVER_ERROR)
}
}.invoke(this)
- })
+ }
}
fun call(
@@ -310,6 +321,7 @@ actual open class ServiceManager<out T> actual constructor(val service: T) {
}
}
+ @Suppress("TooGenericExceptionCaught")
protected inline fun <reified T> getParameter(str: String?): T {
return str?.let {
if (T::class == String::class) {
diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/KDate.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/Date.kt
index 9fc534c4..32c8923e 100644
--- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/KDate.kt
+++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/types/Date.kt
@@ -28,31 +28,19 @@ import com.github.andrewoma.kwery.mapper.standardConverters
import com.github.andrewoma.kwery.mapper.util.camelToLowerUnderscore
import java.sql.Timestamp
import java.text.SimpleDateFormat
-import java.util.*
-/**
- * A serializable wrapper for a multiplatform Date type.
- */
-@Suppress("MayBeConstant")
-actual val KDATE_FORMAT = "yyyy-MM-dd HH:mm:ss"
-
-actual fun nowDate(): KDate =
- KDate(Date().time)
-
-actual fun String.toKDateF(format: String): KDate =
- KDate(SimpleDateFormat(format).parse(this).time)
+actual typealias Date = java.util.Date
-actual fun KDate.toStringF(format: String) =
- SimpleDateFormat(format).format(this.toJava())
+actual fun String.toDateF(format: String): Date = SimpleDateFormat(format).parse(this)
-fun KDate.toJava(): java.util.Date = java.util.Date(this.time)
+actual fun Date.toStringF(format: String): String = SimpleDateFormat(format).format(this)
-object KDateConverter : SimpleConverter<KDate>(
- { row, c -> KDate(row.timestamp(c).time) },
+object DateConverter : SimpleConverter<Date>(
+ { row, c -> Date(row.timestamp(c).time) },
{ Timestamp(it.time) }
)
val kvTableConfig = TableConfiguration(
- converters = standardConverters + reifiedConverter(KDateConverter),
+ converters = standardConverters + reifiedConverter(DateConverter),
namingConvention = camelToLowerUnderscore
)