From 321fadf3b8381b9d33cb6c5208d0bf6c4d7923f7 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 9 Feb 2020 00:02:38 +0100 Subject: Simplify bindings definitions for remote components (select, typeahead) --- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 8 ---- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 11 ----- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 45 ------------------ .../pl/treksoft/kvision/remote/KVServiceManager.kt | 46 ------------------- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 53 ---------------------- .../pl/treksoft/kvision/plugin/KVProcessor.kt | 7 --- 6 files changed, 170 deletions(-) diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 09239fdd..71c7d641 100644 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -110,14 +110,6 @@ expect open class KVServiceManager(serviceClass: KClass) { route: String? = null ) - /** - * Binds a given function of the receiver as a select options source - * @param function a function of the receiver - */ - protected fun bindSelectRemote( - function: suspend T.(String?, String?, String?) -> List - ) - /** * Binds a given function of the receiver as a tabulator component source * @param function a function of the receiver diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index c257645d..aaf63153 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -128,17 +128,6 @@ actual open class KVServiceManager actual constructor(serviceClass: KCl calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } - /** - * Binds a given function of the receiver as a select options source - * @param function a function of the receiver - */ - protected actual fun bindSelectRemote( - function: suspend T.(String?, String?, String?) -> List - ) { - val routeDef = "route${this::class.simpleName}${counter++}" - calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST) - } - /** * Binds a given function of the receiver as a tabulator component source * @param function a function of the receiver diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 6cc2b73d..7bb7af06 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -445,51 +445,6 @@ actual open class KVServiceManager actual constructor(val serviceClass: } } - /** - * Binds a given function of the receiver as a select options source - * @param function a function of the receiver - */ - @Suppress("TooGenericExceptionCaught") - protected actual fun bindSelectRemote( - function: suspend T.(String?, String?, String?) -> List - ) { - val routeDef = "route${this::class.simpleName}${counter++}" - routes.add { - call(HttpMethod.POST, "/kv/$routeDef") { req, res -> - val jsonRpcRequest = req.body(JsonRpcRequest::class.java) - @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 3) { - val param1 = getParameter(jsonRpcRequest.params[0]) - val param2 = getParameter(jsonRpcRequest.params[1]) - val param3 = getParameter(jsonRpcRequest.params[2]) - val injector = req.require(Injector::class.java) - val service = injector.getInstance(serviceClass.java) - GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { - try { - val result = function.invoke(service, param1, param2, param3) - res.send( - JsonRpcResponse( - id = jsonRpcRequest.id, - result = mapper.writeValueAsString(result) - ) - ) - } catch (e: Exception) { - if (!(e is ServiceException)) LOG.error(e.message, e) - res.send( - JsonRpcResponse( - id = jsonRpcRequest.id, error = e.message ?: "Error", - exceptionType = e.javaClass.canonicalName - ) - ) - } - } - } else { - res.send(JsonRpcResponse(id = jsonRpcRequest.id, error = "Invalid parameters")) - } - }.invoke(this) - } - } - /** * Binds a given function of the receiver as a tabulator component source * @param function a function of the receiver diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 19bb8db4..d3fde5c7 100644 --- a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -448,52 +448,6 @@ actual open class KVServiceManager actual constructor(val serviceClass: } } - /** - * Binds a given function of the receiver as a select options source - * @param function a function of the receiver - */ - @Suppress("TooGenericExceptionCaught") - protected actual fun bindSelectRemote( - function: suspend T.(String?, String?, String?) -> List - ) { - val routeDef = "route${this::class.simpleName}${counter++}" - addRoute(HttpMethod.POST, "/kv/$routeDef") { - val service = call.injector.createChildInjector(DummyWsSessionModule()).getInstance(serviceClass.java) - val jsonRpcRequest = call.receive() - @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 3) { - val param1 = getParameter(jsonRpcRequest.params[0]) - val param2 = getParameter(jsonRpcRequest.params[1]) - val param3 = getParameter(jsonRpcRequest.params[2]) - try { - val result = function.invoke(service, param1, param2, param3) - call.respond( - JsonRpcResponse( - id = jsonRpcRequest.id, - result = mapper.writeValueAsString(result) - ) - ) - } catch (e: Exception) { - if (!(e is ServiceException)) LOG.error(e.message, e) - call.respond( - JsonRpcResponse( - id = jsonRpcRequest.id, - error = e.message ?: "Error", - exceptionType = e.javaClass.canonicalName - ) - ) - } - } else { - call.respond( - JsonRpcResponse( - id = jsonRpcRequest.id, - error = "Invalid parameters" - ) - ) - } - } - } - /** * Binds a given function of the receiver as a tabulator component source * @param function a function of the receiver diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 291a9481..05e009a4 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -510,59 +510,6 @@ actual open class KVServiceManager actual constructor(val serviceClass: } } - /** - * Binds a given function of the receiver as a select options source - * @param function a function of the receiver - */ - @Suppress("TooGenericExceptionCaught") - protected actual fun bindSelectRemote( - function: suspend T.(String?, String?, String?) -> List - ) { - val routeDef = "route${this::class.simpleName}${counter++}" - addRoute(HttpMethod.POST, "/kv/$routeDef") { req, ctx -> - val service = ctx.getBean(serviceClass.java) - initializeService(service, req) - val jsonRpcRequest = req.awaitBody() - @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 3) { - val param1 = getParameter(jsonRpcRequest.params[0]) - val param2 = getParameter(jsonRpcRequest.params[1]) - val param3 = getParameter(jsonRpcRequest.params[2]) - try { - val result = function.invoke(service, param1, param2, param3) - ServerResponse.ok().json().bodyValueAndAwait( - mapper.writeValueAsString( - JsonRpcResponse( - id = jsonRpcRequest.id, - result = mapper.writeValueAsString(result) - ) - ) - ) - } catch (e: Exception) { - if (!(e is ServiceException)) LOG.error(e.message, e) - ServerResponse.ok().json().bodyValueAndAwait( - mapper.writeValueAsString( - JsonRpcResponse( - id = jsonRpcRequest.id, - error = e.message ?: "Error", - exceptionType = e.javaClass.canonicalName - ) - ) - ) - } - } else { - ServerResponse.ok().json().bodyValueAndAwait( - mapper.writeValueAsString( - JsonRpcResponse( - id = jsonRpcRequest.id, - error = "Invalid parameters" - ) - ) - ) - } - } - } - /** * Binds a given function of the receiver as a tabulator component source * @param function a function of the receiver diff --git a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt index e09c9021..31ed4ffd 100644 --- a/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt +++ b/kvision-tools/kvision-compiler-plugin/src/main/kotlin/pl/treksoft/kvision/plugin/KVProcessor.kt @@ -98,8 +98,6 @@ class KVProcessor : AbstractProcessor() { when { it.returnType.toString().startsWith("RemoteData") -> appendln(" bindTabulatorRemote($iName::${it.name})") - it.returnType.toString() == "List" -> - appendln(" bindSelectRemote($iName::${it.name})") else -> appendln(" bind($iName::${it.name})") } } @@ -149,11 +147,6 @@ class KVProcessor : AbstractProcessor() { params )}) = ${it.returnType.toString()}()" ) - it.returnType.toString() == "List" -> appendln( - " override suspend fun $name(${getParameterList( - params - )}) = emptyList()" - ) else -> appendln( " override suspend fun $name(${getParameterList(params)}) = call($iName::$name, ${getParameterNames( params -- cgit