Skip to content

Commit 41326f3

Browse files
committed
fix(model-server): fix display of node references
Fixed the handling of unresolvable references and now shows target references if possible.
1 parent 8e82ab7 commit 41326f3

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

model-server/src/main/kotlin/org/modelix/model/server/handlers/ContentExplorer.kt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import kotlinx.html.small
2929
import kotlinx.html.stream.appendHTML
3030
import kotlinx.html.style
3131
import kotlinx.html.table
32+
import kotlinx.html.tbody
3233
import kotlinx.html.td
3334
import kotlinx.html.th
3435
import kotlinx.html.thead
@@ -250,10 +251,12 @@ class ContentExplorer(private val client: IModelClient, private val repoManager:
250251
th { +"Value" }
251252
}
252253
}
253-
for (propertyRole in node.getPropertyRoles()) {
254-
tr {
255-
td { +propertyRole }
256-
td { +"${node.getPropertyValue(propertyRole)}" }
254+
tbody {
255+
for (propertyRole in node.getPropertyRoles()) {
256+
tr {
257+
td { +propertyRole }
258+
td { +"${node.getPropertyValue(propertyRole)}" }
259+
}
257260
}
258261
}
259262
}
@@ -265,19 +268,21 @@ class ContentExplorer(private val client: IModelClient, private val repoManager:
265268
thead {
266269
tr {
267270
th { +"ReferenceRole" }
268-
th { +"NodeId" }
269-
th { +"Value" }
271+
th { +"Target NodeId" }
272+
th { +"Target Reference" }
270273
}
271274
}
272-
INodeResolutionScope.runWithAdditionalScope(node.getArea()) {
273-
for (referenceRole in node.getReferenceRoles()) {
274-
tr {
275-
td { +referenceRole }
276-
td {
277-
+"${(node.getReferenceTarget(referenceRole) as PNodeAdapter).nodeId}"
278-
}
279-
td {
280-
+"${node.getReferenceTarget(referenceRole)}"
275+
tbody {
276+
INodeResolutionScope.runWithAdditionalScope(node.getArea()) {
277+
for (referenceRole in node.getReferenceRoles()) {
278+
tr {
279+
td { +referenceRole }
280+
td {
281+
+"${(node.getReferenceTarget(referenceRole) as? PNodeAdapter)?.nodeId}"
282+
}
283+
td {
284+
+"${node.getReferenceTargetRef(referenceRole)?.serialize()}"
285+
}
281286
}
282287
}
283288
}

model-server/src/test/kotlin/org/modelix/model/server/handlers/ContentExplorerTest.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ import io.ktor.server.websocket.WebSockets
3333
import org.jsoup.Jsoup
3434
import org.jsoup.nodes.Element
3535
import org.jsoup.select.Evaluator
36+
import org.modelix.model.api.IReferenceLink
37+
import org.modelix.model.api.ITree
38+
import org.modelix.model.api.NodeReferenceById
3639
import org.modelix.model.client.successful
40+
import org.modelix.model.client2.ModelClientV2
41+
import org.modelix.model.client2.runWrite
3742
import org.modelix.model.lazy.CLVersion
43+
import org.modelix.model.lazy.RepositoryId
3844
import org.modelix.model.server.api.v2.VersionDelta
3945
import org.modelix.model.server.store.InMemoryStoreClient
4046
import org.modelix.model.server.store.LocalModelClient
4147
import kotlin.test.Test
48+
import kotlin.test.assertEquals
4249
import kotlin.test.assertNotNull
4350
import kotlin.test.assertTrue
4451
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ClientContentNegotiation
@@ -63,6 +70,12 @@ class ContentExplorerTest {
6370
}
6471
}
6572

73+
private suspend fun ApplicationTestBuilder.createModelClient(): ModelClientV2 {
74+
val url = "http://localhost/v2"
75+
val modelClient = ModelClientV2.builder().url(url).client(client).build().also { it.init() }
76+
return modelClient
77+
}
78+
6679
@Test
6780
fun `node inspector finds root node`() = runTest {
6881
val client = createClient {
@@ -79,6 +92,34 @@ class ContentExplorerTest {
7992
assertTrue(response.successful)
8093
}
8194

95+
@Test
96+
fun `node inspector can handle unresolvable references`() = runTest {
97+
val modelClient = createModelClient()
98+
val repoId = RepositoryId("node-inspector-null-ref")
99+
val branchRef = repoId.getBranchReference("master")
100+
val refLinkName = "myUnresolvableRef"
101+
val refLinkTargetRef = NodeReferenceById("notAResolvableId")
102+
103+
modelClient.initRepository(repoId)
104+
105+
modelClient.runWrite(branchRef) { root ->
106+
root.setReferenceTarget(IReferenceLink.fromName(refLinkName), refLinkTargetRef)
107+
}
108+
109+
val versionHash = modelClient.pullHash(branchRef)
110+
111+
val response = client.get("/content/$versionHash/${ITree.ROOT_ID}/")
112+
val html = Jsoup.parse(response.bodyAsText())
113+
val nameCell = html.selectXpath("""//td[text()="$refLinkName"]""").first() ?: error("table cell not found")
114+
val row = checkNotNull(nameCell.parent()) { "table row not found" }
115+
val targetNodeIdCell = row.allElements[2] // index 0 is the row itself and 1 the nameCell
116+
val targetRefCell = row.allElements[3]
117+
118+
assertTrue(response.successful)
119+
assertEquals("null", targetNodeIdCell.text())
120+
assertEquals(refLinkTargetRef.serialize(), targetRefCell.text())
121+
}
122+
82123
@Test
83124
fun `nodes can be expanded`() = runTest {
84125
val client = createClient {

0 commit comments

Comments
 (0)