Skip to content

Commit e8121db

Browse files
authored
Merge pull request #115 from modelix/issues/MODELIX-435
MODELIX-435 don't throw exception for missing reference links
2 parents 0c860c3 + cf8e269 commit e8121db

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

model-server-lib/src/main/kotlin/org/modelix/model/server/light/QueryImplementation.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
*/
1414
package org.modelix.model.server.light
1515

16-
import org.modelix.model.api.INode
17-
import org.modelix.model.api.INodeReferenceSerializer
18-
import org.modelix.model.api.getAncestors
19-
import org.modelix.model.api.getDescendants
16+
import org.modelix.model.api.*
2017
import org.modelix.model.server.api.AndFilter
2118
import org.modelix.model.server.api.ContainsOperator
2219
import org.modelix.model.server.api.EndsWithOperator
@@ -53,7 +50,18 @@ fun RootOrSubquery.queryNodes(node: INode): Sequence<INode> {
5350
is QueryChildren -> node.getChildren(this.role).asSequence()
5451
is QueryDescendants -> node.getDescendants(false)
5552
is QueryParent -> listOfNotNull(node.parent).asSequence()
56-
is QueryReference -> listOfNotNull(node.getReferenceTarget(this.role)).asSequence()
53+
is QueryReference -> {
54+
val link = try {
55+
node.resolveReferenceLink(this.role)
56+
} catch (ex: Exception) {
57+
null
58+
}
59+
if (link == null) {
60+
emptySequence()
61+
} else {
62+
listOfNotNull(node.getReferenceTarget(link)).asSequence()
63+
}
64+
}
5765
is QueryReferences -> node.getAllReferences()
5866
is QueryReferencesAndChildren -> node.getReferencesAndChildren(recursive)
5967
is QueryById -> {

0 commit comments

Comments
 (0)