You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by jo...@apache.org on 2021/10/21 16:22:44 UTC
[isis] branch master updated: ISIS-2348 ReplayCommand refactored,
multiple sessions prepared, tests fixed, minor cleanups
This is an automated email from the ASF dual-hosted git repository.
joergrade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 099d11b ISIS-2348 ReplayCommand refactored, multiple sessions prepared, tests fixed, minor cleanups
new d1bf3be Merge remote-tracking branch 'origin/master'
099d11b is described below
commit 099d11b8edc2ffc20f8f36d1fb35b7b0a3a18689
Author: Jörg Rade <jo...@kuehne-nagel.com>
AuthorDate: Thu Oct 21 18:22:12 2021 +0200
ISIS-2348 ReplayCommand refactored, multiple sessions prepared, tests fixed, minor cleanups
---
.../isis/client/kroviz/core/event/LogEntry.kt | 18 +++------
.../isis/client/kroviz/core/event/ReplayCommand.kt | 43 +++++++++++++---------
.../apache/isis/client/kroviz/ui/core/Constants.kt | 2 +-
.../apache/isis/client/kroviz/ui/core/UiManager.kt | 18 ++++++---
.../apache/isis/client/kroviz/utils/StringUtils.kt | 2 +-
.../kroviz/core/aggregator/ObjectAggregatorTest.kt | 2 +
.../isis/client/kroviz/util/StringUtilsTest.kt | 7 +++-
7 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntry.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntry.kt
index e589375..09e57ac 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntry.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/LogEntry.kt
@@ -23,8 +23,6 @@ import io.kvision.panel.SimplePanel
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import org.apache.isis.client.kroviz.core.aggregator.BaseAggregator
-import org.apache.isis.client.kroviz.core.aggregator.CollectionAggregator
-import org.apache.isis.client.kroviz.core.aggregator.ObjectAggregator
import org.apache.isis.client.kroviz.to.HasLinks
import org.apache.isis.client.kroviz.to.Link
import org.apache.isis.client.kroviz.to.Relation
@@ -53,10 +51,11 @@ enum class EventState(val id: String, val iconName: String, val style: ButtonSty
@Serializable
data class LogEntry(
- @Contextual val rs: ResourceSpecification,
- val method: String? = "",
- val request: String = "",
- @Contextual val createdAt: Date = Date()) {
+ @Contextual val rs: ResourceSpecification,
+ val method: String? = "",
+ val request: String = "",
+ @Contextual val createdAt: Date = Date()
+) {
val url: String = rs.url
// val referrer = rs.referrerUrl
@@ -234,11 +233,6 @@ data class LogEntry(
fun addAggregator(aggregator: BaseAggregator) {
aggregators.add(aggregator)
- if ((aggregators.size > 1) && ((aggregator is ObjectAggregator) || (aggregator is CollectionAggregator))) {
- console.log("[LE.addAggregator] 2nd/3rd/etc. Object/Collection")
- console.log(aggregator)
- // throw Throwable("[LE.addAggregator] not implemented yet")
- }
nOfAggregators = aggregators.size
}
@@ -258,8 +252,6 @@ data class LogEntry(
}
fun getLinks(): List<Link> {
-// console.log("[LE.getLinks]")
-// console.log(obj)
return if (obj is HasLinks) {
(obj as HasLinks).getLinks()
} else {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
index c598162..d7b7ce6 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/core/event/ReplayCommand.kt
@@ -27,47 +27,47 @@ import org.apache.isis.client.kroviz.main
import org.apache.isis.client.kroviz.to.Link
import org.apache.isis.client.kroviz.to.Represention
import org.apache.isis.client.kroviz.to.TObject
-import kotlin.js.Date
val AppScope = CoroutineScope(window.asCoroutineDispatcher())
class ReplayCommand {
fun execute() {
- val events = copyEvents(EventStore.log)
+ val expectedEvents = copyEvents(EventStore.log)
EventStore.reset()
main() // re-creates the UI, but keeps the UiManager(singleton/object) and the session
- val userActions = filterUserActions(events)
- replay(userActions)
+ val replayEvents = filterReplayEvents(expectedEvents)
+ replay(replayEvents)
}
private fun replay(userActions: List<LogEntry>) {
- var previous: Date? = null
+ var previous: LogEntry? = null
userActions.forEach {
- if (it.state == EventState.USER_ACTION) {
- var offset: Double = 0.toDouble()
- if (previous != null) {
- offset = it.createdAt.getTime().minus(previous!!.getTime())
- }
- val obj = it.obj as TObject
+ if (it.isUserAction() && previous != null) {
AppScope.launch {
- delay(offset.toLong()) // non-blocking delay for 1 second (default time unit is ms)
+ val ms = calculateDelay(previous!!, it)
+ delay(ms) // non-blocking delay
+ val obj = it.obj as TObject
ResourceProxy().load(obj)
}
} else {
val link = Link(href = it.url)
ResourceProxy().fetch(link, null, it.subType)
}
- previous = it.createdAt
+ previous = it
}
}
- private fun filterUserActions(events: List<LogEntry>): List<LogEntry> {
+ private fun calculateDelay(previous: LogEntry, current: LogEntry): Long {
+ val currentMillis = current.createdAt.getTime().toLong()
+ val previousMillis = previous.createdAt.getTime().toLong()
+ return currentMillis - previousMillis
+ }
+
+ private fun filterReplayEvents(events: List<LogEntry>): List<LogEntry> {
return events.filter {
- (it.type == Represention.HOMEPAGE.type) ||
- it.type == Represention.OBJECT_ACTION.type ||
- it.state == EventState.USER_ACTION
+ (it.hasRelevantType()) || it.isUserAction()
}
}
@@ -94,4 +94,13 @@ class ReplayCommand {
return output
}
+ private fun LogEntry.isUserAction(): Boolean {
+ return this.state == EventState.USER_ACTION
+ }
+
+ private fun LogEntry.hasRelevantType(): Boolean {
+ return this.type == Represention.HOMEPAGE.type ||
+ this.type == Represention.OBJECT_ACTION.type
+ }
+
}
\ No newline at end of file
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/Constants.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/Constants.kt
index b15121e..c01a0d9 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/Constants.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/Constants.kt
@@ -32,7 +32,7 @@ object Constants {
//const val krokiUrl = "https://kroki.io/" //see: https://github.com/yuzutech/kroki
const val krokiUrl = "http://localhost:8000/"
- //host:port depend on how docker is started
+ //host:port depends on how docker is started
// docker run -d --name kroki -p 8080:8000 yuzutech/kroki
const val demoUrl = "http://localhost:8080/"
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
index a6f9a77..16fa92f 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/ui/core/UiManager.kt
@@ -48,7 +48,7 @@ import org.w3c.dom.events.KeyboardEvent
object UiManager {
var app: App? = null
- private var session: Session? = null
+ private val sessions = mutableListOf<Session>()
private val popups = mutableListOf<Widget>()
private val settings = mutableMapOf<String, Any>()
var position: Point? = null
@@ -177,10 +177,15 @@ object UiManager {
pop()
}
+ fun getSession(): Session {
+ return sessions.first()
+ }
+
fun getUrl(): String {
- return when (session) {
+ val s = getSession()
+ return when (s) {
null -> ""
- else -> session!!.url
+ else -> s.url
}
}
@@ -193,12 +198,13 @@ object UiManager {
}
fun login(url: String, username: String, password: String) {
- session = Session()
- session!!.login(url, username, password)
+ val s = Session()
+ s.login(url, username, password)
+ sessions.add(s)
}
fun getCredentials(): String {
- return session!!.getCredentials()
+ return getSession().getCredentials()
}
private fun push(widget: Widget) {
diff --git a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/StringUtils.kt b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/StringUtils.kt
index a042665..99e63a7 100644
--- a/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/StringUtils.kt
+++ b/incubator/clients/kroviz/src/main/kotlin/org/apache/isis/client/kroviz/utils/StringUtils.kt
@@ -69,7 +69,7 @@ object StringUtils {
if (title.contains(signature)) {
// strip off protocol, host, port
title = title.replace(protocolHostPort + signature, "")
- title = StringUtils.removeHexCode(title)
+ title = removeHexCode(title)
}
return title
}
diff --git a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/aggregator/ObjectAggregatorTest.kt b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/aggregator/ObjectAggregatorTest.kt
index 0e6b4cb..98ba731 100644
--- a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/aggregator/ObjectAggregatorTest.kt
+++ b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/core/aggregator/ObjectAggregatorTest.kt
@@ -18,6 +18,7 @@
*/
package org.apache.isis.client.kroviz.core.aggregator
+import org.apache.isis.client.kroviz.App
import org.apache.isis.client.kroviz.IntegrationTest
import org.apache.isis.client.kroviz.snapshots.simpleapp1_16_0.ACTION_SO_CREATE
import org.apache.isis.client.kroviz.to.ResultObject
@@ -30,6 +31,7 @@ class ObjectAggregatorTest : IntegrationTest() {
@Test
fun testRestfulServices() {
// given
+ App()
val aggregator = ObjectAggregator("object test")
// when
val logEntry = mockResponse(ACTION_SO_CREATE, aggregator)
diff --git a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/util/StringUtilsTest.kt b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/util/StringUtilsTest.kt
index ba15e96..dd37408 100644
--- a/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/util/StringUtilsTest.kt
+++ b/incubator/clients/kroviz/src/test/kotlin/org/apache/isis/client/kroviz/util/StringUtilsTest.kt
@@ -5,6 +5,7 @@ import org.apache.isis.client.kroviz.ui.core.UiManager
import org.apache.isis.client.kroviz.utils.StringUtils
import kotlin.test.Test
import kotlin.test.assertEquals
+import kotlin.test.assertTrue
class StringUtilsTest {
@Test
@@ -14,8 +15,12 @@ class StringUtilsTest {
val url = "http://localhost:8080/restful/domain-types/demo.JavaLangStrings/collections/entities"
// when
- val actual = StringUtils.shortTitle(url, UiManager.getUrl())
+ val protocolHostPort = UiManager.getUrl()
+ // then
+ assertTrue(protocolHostPort.startsWith("http://"))
+ // when
+ val actual = StringUtils.shortTitle(url, protocolHostPort)
// then
val expected = "/domain-types/demo.JavaLangStrings/collections/entities"
assertEquals(expected, actual)