@@ -30,9 +30,11 @@ import kotlinx.coroutines.runBlocking
30
30
import kotlinx.coroutines.withContext
31
31
import kotlinx.coroutines.withTimeout
32
32
import org.modelix.model.api.ConceptReference
33
+ import org.modelix.model.api.IConceptReference
33
34
import org.modelix.model.api.INode
34
35
import org.modelix.model.api.INodeReference
35
36
import org.modelix.model.api.INodeReferenceSerializer
37
+ import org.modelix.model.api.IRole
36
38
import org.modelix.model.api.remove
37
39
import org.modelix.model.api.serialize
38
40
import org.modelix.model.server.api.AddNewChildNodeOpData
@@ -54,13 +56,14 @@ import java.time.Duration
54
56
import java.util.*
55
57
import kotlin.time.Duration.Companion.seconds
56
58
57
- class LightModelServer (val port : Int , val rootNode : INode ) {
59
+ class LightModelServer (val port : Int , val rootNode : INode , val ignoredRoles : Set < IRole > = emptySet() ) {
58
60
companion object {
59
61
private val LOG = mu.KotlinLogging .logger { }
60
62
}
61
63
62
64
private var server: NettyApplicationEngine ? = null
63
65
private val sessions: MutableSet <SessionData > = Collections .synchronizedSet(HashSet ())
66
+ private val ignoredRolesCache: MutableMap <IConceptReference , IgnoredRoles > = HashMap ()
64
67
65
68
fun start () {
66
69
LOG .trace { " server starting on port $port ..." }
@@ -280,8 +283,17 @@ class LightModelServer(val port: Int, val rootNode: INode) {
280
283
}
281
284
282
285
private fun INode.toData (): NodeData {
286
+ val conceptRef = concept?.getReference()
287
+ val ignored = if (conceptRef == null ) IgnoredRoles .EMPTY else ignoredRolesCache.getOrPut(conceptRef) {
288
+ val ignoredChildRoles = concept?.getAllChildLinks()?.intersect(ignoredRoles)?.map { it.name }?.toSet() ? : emptySet()
289
+ val ignoredPropertyRoles = concept?.getAllProperties()?.intersect(ignoredRoles)?.map { it.name }?.toSet() ? : emptySet()
290
+ val ignoredReferenceRoles = concept?.getAllReferenceLinks()?.intersect(ignoredRoles)?.map { it.name }?.toSet() ? : emptySet()
291
+ IgnoredRoles (ignoredChildRoles, ignoredPropertyRoles, ignoredReferenceRoles).optimizeEmpty()
292
+ }
293
+
283
294
val childrenMap = LinkedHashMap <String ?, List <NodeId >>()
284
295
for (group in this .allChildren.groupBy { it.roleInParent }) {
296
+ if (ignored.children.contains(group.key)) continue
285
297
try {
286
298
childrenMap[group.key] = group.value.map { it.nodeId() }
287
299
} catch (ex: Exception ) {
@@ -293,14 +305,22 @@ class LightModelServer(val port: Int, val rootNode: INode) {
293
305
concept = this .getConceptReference()?.getUID(),
294
306
parent = this .parent?.reference?.serialize(),
295
307
role = this .roleInParent,
296
- properties = this .getPropertyRoles().associateWithNotNull { this .getPropertyValue(it) },
297
- references = this .getReferenceRoles().associateWithNotNull { this .getReferenceTargetRef(it)?.serialize() },
308
+ properties = this .getPropertyRoles().minus(ignored.properties)
309
+ .associateWithNotNull { this .getPropertyValue(it) },
310
+ references = this .getReferenceRoles().minus(ignored.references)
311
+ .associateWithNotNull { this .getReferenceTargetRef(it)?.serialize() },
298
312
children = childrenMap,
299
313
)
300
314
}
301
315
}
302
316
303
-
317
+ private class IgnoredRoles (val children : Set <String >, val properties : Set <String >, val references : Set <String >) {
318
+ fun isEmpty () = children.isEmpty() && properties.isEmpty() && references.isEmpty()
319
+ fun optimizeEmpty () = if (isEmpty()) EMPTY else this
320
+ companion object {
321
+ val EMPTY = IgnoredRoles (emptySet(), emptySet(), emptySet())
322
+ }
323
+ }
304
324
305
325
private fun INode.nodeId () = reference.serialize()
306
326
private fun INodeReference.nodeId () = serialize()
0 commit comments