aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-remote/src
diff options
context:
space:
mode:
Diffstat (limited to 'kvision-modules/kvision-remote/src')
-rw-r--r--kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt36
-rw-r--r--kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt24
2 files changed, 42 insertions, 18 deletions
diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt
index fea16b99..2f6b765a 100644
--- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt
+++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt
@@ -44,7 +44,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
*/
suspend inline fun <reified RET : Any, T> call(noinline function: suspend T.() -> RET): RET {
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, method = method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -67,7 +68,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
noinline function: suspend T.() -> List<RET>
): List<RET> {
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, method = method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
@@ -90,7 +92,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
): RET {
val data = serialize(p)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data), method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -114,7 +117,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
): List<RET> {
val data = serialize(p)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data), method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
@@ -138,7 +142,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data1 = serialize(p1)
val data2 = serialize(p2)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2), method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -163,7 +168,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data1 = serialize(p1)
val data2 = serialize(p2)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2), method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
@@ -188,7 +194,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data2 = serialize(p2)
val data3 = serialize(p3)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3), method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -214,7 +221,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data2 = serialize(p2)
val data3 = serialize(p3)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3), method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
@@ -240,7 +248,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data3 = serialize(p3)
val data4 = serialize(p4)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4), method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -271,7 +280,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data3 = serialize(p3)
val data4 = serialize(p4)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4), method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
@@ -305,7 +315,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data4 = serialize(p4)
val data5 = serialize(p5)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4, data5), method).then {
try {
@Suppress("UNCHECKED_CAST")
@@ -340,7 +351,8 @@ open class SpringRemoteAgent<T : Any>(val serviceManager: SpringServiceManager<T
val data4 = serialize(p4)
val data5 = serialize(p5)
val (url, method) =
- serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!")
+ serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
+ ?: throw IllegalStateException("Function not specified!")
return callAgent.jsonRpcCall(url, listOf(data1, data2, data3, data4, data5), method).then {
try {
deserializeList<RET>(it, RET::class.js.name)
diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
index 524347d7..61ae32ba 100644
--- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
+++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt
@@ -42,7 +42,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
route: String?, method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method)
}
/**
@@ -56,7 +56,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
route: String?, method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method)
}
/**
@@ -70,7 +70,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
route: String?, method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method)
}
/**
@@ -84,7 +84,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
route: String?, method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method)
}
/**
@@ -98,7 +98,7 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
route: String?, method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method)
}
/**
@@ -114,11 +114,23 @@ actual open class SpringServiceManager<T : Any> actual constructor(serviceClass:
method: RpcHttpMethod
) {
val routeDef = route ?: "route${this::class.simpleName}${counter++}"
- calls[function.toString()] = Pair("/kv/$routeDef", method)
+ 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 bind(
+ function: T.(String) -> List<RemoteSelectOption>
+ ) {
+ val routeDef = "route${this::class.simpleName}${counter++}"
+ calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", RpcHttpMethod.POST)
}
/**
* Returns the map of defined paths.
*/
override fun getCalls(): Map<String, Pair<String, RpcHttpMethod>> = calls
+
}