Skip to content

Commit c8e40ba

Browse files
committed
fix(model-server): fix node inspector not finding nodes in some cases
1 parent c374e54 commit c8e40ba

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,24 @@ class ContentExplorer(private val client: IModelClient, private val repoManager:
112112
)
113113
}
114114
get<Paths.getNodeIdForVersionHash> {
115-
val id = call.parameters["nodeId"]!!.toLong()
116-
var found: PNodeAdapter? = null
117-
for (node in rootNodes) {
118-
val candidate = PNodeAdapter(id, node.branch).takeIf { it.isValid }
119-
if (candidate != null) {
120-
found = candidate
121-
break
122-
}
115+
val id = call.parameters["nodeId"]?.toLongOrNull()
116+
?: return@get call.respondText("node id not found", status = HttpStatusCode.NotFound)
117+
118+
val versionHash = call.parameters["versionHash"]
119+
?: return@get call.respondText("version hash not found", status = HttpStatusCode.NotFound)
120+
121+
val version = try {
122+
CLVersion.loadFromHash(versionHash, client.storeCache)
123+
} catch (ex: RuntimeException) {
124+
return@get call.respondText("version not found", status = HttpStatusCode.NotFound)
123125
}
124-
if (found == null) {
125-
call.respondText("node id not found", status = HttpStatusCode.NotFound)
126+
127+
val node = PNodeAdapter(id, TreePointer(version.getTree())).takeIf { it.isValid }
128+
129+
if (node != null) {
130+
call.respondHtml { body { nodeInspector(node) } }
126131
} else {
127-
call.respondHtml { body { nodeInspector(found) } }
132+
call.respondText("node id not found", status = HttpStatusCode.NotFound)
128133
}
129134
}
130135
}

0 commit comments

Comments
 (0)