aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-common-remote
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-12-18 18:54:27 +0100
committerRobert Jaros <rjaros@finn.pl>2018-12-18 18:54:27 +0100
commit161264957dc1b41cd6716ee7777139c5e29589f5 (patch)
treec7977850428319b17888f2c7ceffc2557e68a360 /kvision-modules/kvision-common-remote
parent1fbd940e57b6917ab6677ff285f632f0d10f4809 (diff)
downloadkvision-161264957dc1b41cd6716ee7777139c5e29589f5.tar.gz
kvision-161264957dc1b41cd6716ee7777139c5e29589f5.tar.bz2
kvision-161264957dc1b41cd6716ee7777139c5e29589f5.zip
Refactor modules.
Diffstat (limited to 'kvision-modules/kvision-common-remote')
-rw-r--r--kvision-modules/kvision-common-remote/build.gradle10
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt107
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JsonRpc.kt37
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt37
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteSelectOption.kt36
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt45
-rw-r--r--kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt102
7 files changed, 374 insertions, 0 deletions
diff --git a/kvision-modules/kvision-common-remote/build.gradle b/kvision-modules/kvision-common-remote/build.gradle
new file mode 100644
index 00000000..af3703e6
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/build.gradle
@@ -0,0 +1,10 @@
+apply plugin: 'kotlin-platform-common'
+apply plugin: 'kotlinx-serialization'
+
+dependencies {
+ compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"
+ compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion"
+ compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutinesVersion"
+ testCompile "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion"
+ testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion"
+}
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt
new file mode 100644
index 00000000..cb1b44d0
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JoobyServiceManager.kt
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+/**
+ * Multiplatform service manager for Jooby.
+ */
+expect open class JoobyServiceManager<T : Any>(service: T) : ServiceManager {
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified RET> bind(
+ noinline function: suspend T.(Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR, reified RET> bind(
+ noinline function: suspend T.(PAR, Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3, Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5, Request?) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Applies all defined routes to the given server.
+ * @param k a server
+ */
+ fun applyRoutes(k: KVServer)
+
+}
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JsonRpc.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JsonRpc.kt
new file mode 100644
index 00000000..7953ea01
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/JsonRpc.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class JsonRpcRequest(val id: Int, val method: String, val params: List<String?>, val jsonrpc: String = "2.0") {
+ constructor() : this(0, "", listOf())
+}
+
+@Serializable
+data class JsonRpcResponse(
+ val id: Int? = null,
+ val result: String? = null,
+ val error: String? = null,
+ val jsonrpc: String = "2.0"
+)
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
new file mode 100644
index 00000000..cf822e66
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+/**
+ * A server.
+ */
+expect open class KVServer
+
+/**
+ * A server request.
+ */
+expect interface Request
+
+/**
+ * A user profile.
+ */
+expect class Profile
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteSelectOption.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteSelectOption.kt
new file mode 100644
index 00000000..24e68f63
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteSelectOption.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class RemoteSelectOption(
+ val value: String? = null,
+ val text: String? = null,
+ val className: String? = null,
+ val subtext: String? = null,
+ val icon: String? = null,
+ val content: String? = null,
+ val disabled: Boolean = false,
+ val divider: Boolean = false
+)
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
new file mode 100644
index 00000000..6f696475
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+enum class RpcHttpMethod {
+ POST,
+ PUT,
+ DELETE,
+ OPTIONS
+}
+
+enum class HttpMethod {
+ GET,
+ POST,
+ PUT,
+ DELETE,
+ OPTIONS
+}
+
+interface ServiceManager {
+ /**
+ * Returns the map of defined paths.
+ */
+ fun getCalls(): Map<String, Pair<String, RpcHttpMethod>> = mapOf()
+
+}
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
new file mode 100644
index 00000000..90926656
--- /dev/null
+++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package pl.treksoft.kvision.remote
+
+import kotlin.reflect.KClass
+
+/**
+ * Multiplatform service manager for Spring Boot.
+ */
+expect open class SpringServiceManager<T : Any>(serviceClass: KClass<T>) : ServiceManager {
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified RET> bind(
+ noinline function: suspend T.() -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR, reified RET> bind(
+ noinline function: suspend T.(PAR) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+
+ /**
+ * Binds a given route with a function of the receiver.
+ * @param function a function of the receiver
+ * @param route a route
+ * @param method a HTTP method
+ */
+ protected inline fun <reified PAR1, reified PAR2, reified PAR3, reified PAR4, reified PAR5, reified RET> bind(
+ noinline function: suspend T.(PAR1, PAR2, PAR3, PAR4, PAR5) -> RET,
+ route: String? = null,
+ method: RpcHttpMethod = RpcHttpMethod.POST
+ )
+}