@@ -59,12 +59,14 @@ import org.modelix.modelql.core.flatMap
59
59
import org.modelix.modelql.core.inSet
60
60
import org.modelix.modelql.core.map
61
61
import org.modelix.modelql.core.mapIfNotNull
62
+ import org.modelix.modelql.core.nullMono
62
63
import org.modelix.modelql.core.orNull
63
64
import org.modelix.modelql.core.stepOutputSerializer
64
65
import org.modelix.modelql.core.toBoolean
65
66
import org.modelix.modelql.core.toInt
66
67
import org.modelix.modelql.core.upcast
67
68
import org.modelix.modelql.untyped.UntypedModelQL
69
+ import org.modelix.modelql.untyped.addNewChild
68
70
import org.modelix.modelql.untyped.children
69
71
import org.modelix.modelql.untyped.conceptReference
70
72
import org.modelix.modelql.untyped.descendants
@@ -75,7 +77,9 @@ import org.modelix.modelql.untyped.ofConcept
75
77
import org.modelix.modelql.untyped.property
76
78
import org.modelix.modelql.untyped.query
77
79
import org.modelix.modelql.untyped.reference
80
+ import org.modelix.modelql.untyped.remove
78
81
import org.modelix.modelql.untyped.setProperty
82
+ import org.modelix.modelql.untyped.setReference
79
83
import kotlin.jvm.JvmName
80
84
import kotlin.reflect.KClass
81
85
@@ -140,6 +144,17 @@ object TypedModelQL {
140
144
return input.untyped().flatMap { it.children(link.untyped().key()) }.typedUnsafe(link.getTypedChildConcept().getInstanceInterface())
141
145
}
142
146
147
+ fun <ParentT : ITypedNode , ChildT : ITypedNode > addNewChild (input : IMonoStep <ParentT >, link : ITypedChildListLink <ChildT >, index : Int = -1, concept : ITypedConcept ): IMonoStep <ChildT > {
148
+ val conceptRef = ConceptReference (concept.untyped().getUID())
149
+ return input.untyped().addNewChild(link.untyped(), index, conceptRef).typedUnsafe(link.getTypedChildConcept().getInstanceInterface())
150
+ }
151
+
152
+ fun <ParentT : ITypedNode , ChildT : ITypedNode > setChild (input : IMonoStep <ParentT >, link : ITypedSingleChildLink <ChildT >, concept : ITypedConcept ): IMonoStep <ChildT > {
153
+ val conceptRef = ConceptReference (concept.untyped().getUID())
154
+ input.untyped().children(link.untyped().key()).firstOrNull().mapIfNotNull { it.remove() }
155
+ return input.untyped().addNewChild(link.untyped(), conceptRef).typedUnsafe(link.getTypedChildConcept().getInstanceInterface())
156
+ }
157
+
143
158
fun <SourceT : ITypedNode , TargetT : ITypedNode > reference (input : IMonoStep <SourceT >, link : ITypedReferenceLink <TargetT >): IMonoStep <TargetT > {
144
159
return input.untyped().reference(link.untyped().key()).typedUnsafe<TargetT >(link.getTypedTargetConcept().getInstanceInterface())
145
160
}
@@ -152,6 +167,12 @@ object TypedModelQL {
152
167
fun <SourceT : ITypedNode , TargetT : ITypedNode > referenceOrNull (input : IFluxStep <SourceT >, link : ITypedReferenceLink <TargetT >): IFluxStep <TargetT ?> {
153
168
return input.map { referenceOrNull(it, link) }
154
169
}
170
+
171
+ fun <SourceT : ITypedNode , TargetT : ITypedNode > setReference (input : IMonoStep <SourceT >, link : ITypedReferenceLink <TargetT >, target : IMonoStep <TargetT ?>? ): IMonoStep <SourceT > {
172
+ val targetOrNull = target?.untyped() ? : nullMono<INode >()
173
+ input.untyped().setReference(link.untyped(), targetOrNull)
174
+ return input
175
+ }
155
176
}
156
177
157
178
/* * Doesn't check the concept when executed remotely. Use .ofConcept() to convert a node in a type safe way. */
0 commit comments