Skip to content

Commit dbb6118

Browse files
committed
feat(modelql): add mono source step for set of ConceptReference
1 parent 7df96c5 commit dbb6118

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

modelql-client/src/jvmTest/kotlin/org/modelix/modelql/client/ModelQLClientTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import io.ktor.client.HttpClient
1717
import io.ktor.server.routing.routing
1818
import io.ktor.server.testing.testApplication
1919
import kotlinx.coroutines.withTimeout
20+
import org.modelix.model.api.ConceptReference
2021
import org.modelix.model.api.IConceptReference
2122
import org.modelix.model.api.INode
2223
import org.modelix.model.api.PBranch
@@ -43,6 +44,7 @@ import org.modelix.modelql.server.ModelQLServer
4344
import org.modelix.modelql.untyped.addNewChild
4445
import org.modelix.modelql.untyped.allChildren
4546
import org.modelix.modelql.untyped.allReferences
47+
import org.modelix.modelql.untyped.asMono
4648
import org.modelix.modelql.untyped.children
4749
import org.modelix.modelql.untyped.descendants
4850
import org.modelix.modelql.untyped.nodeReference
@@ -250,4 +252,12 @@ class ModelQLClientTest {
250252

251253
assertEquals(null, nullNode)
252254
}
255+
256+
@Test
257+
fun `mono can be created from set of concept references`() = runTest { httpClient ->
258+
val client = ModelQLClient("http://localhost/query", httpClient)
259+
val refSet = setOf(ConceptReference("abc"), ConceptReference("def"))
260+
val result = client.query { refSet.asMono() }
261+
assertEquals(refSet, result)
262+
}
253263
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.modelql.untyped
18+
19+
import kotlinx.serialization.SerialName
20+
import kotlinx.serialization.Serializable
21+
import org.modelix.model.api.ConceptReference
22+
import org.modelix.modelql.core.ConstantSourceStep
23+
import org.modelix.modelql.core.IStep
24+
import org.modelix.modelql.core.QueryDeserializationContext
25+
import org.modelix.modelql.core.QueryGraphDescriptorBuilder
26+
import org.modelix.modelql.core.StepDescriptor
27+
import kotlin.reflect.typeOf
28+
29+
class ConceptReferenceSetSourceStep(val referenceSet: Set<ConceptReference>) : ConstantSourceStep<Set<ConceptReference>>(referenceSet, typeOf<Set<ConceptReference>>()) {
30+
override fun createDescriptor(context: QueryGraphDescriptorBuilder): StepDescriptor = Descriptor(referenceSet)
31+
32+
@Serializable
33+
@SerialName("conceptReferenceSetMonoSource")
34+
class Descriptor(val referenceSet: Set<ConceptReference>) : StepDescriptor() {
35+
override fun createStep(context: QueryDeserializationContext): IStep {
36+
return ConceptReferenceSetSourceStep(referenceSet)
37+
}
38+
}
39+
40+
override fun canEvaluateStatically(): Boolean = true
41+
override fun evaluateStatically(): Set<ConceptReference> = referenceSet
42+
}
43+
44+
fun Set<ConceptReference>.asMono() = ConceptReferenceSetSourceStep(this)

modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object UntypedModelQL {
3737
subclass(AllReferencesTraversalStep.Descriptor::class)
3838
subclass(ChildrenTraversalStep.ChildrenStepDescriptor::class)
3939
subclass(ConceptReferenceTraversalStep.Descriptor::class)
40+
subclass(ConceptReferenceSetSourceStep.Descriptor::class)
4041
subclass(ConceptReferenceUIDTraversalStep.Descriptor::class)
4142
subclass(DescendantsTraversalStep.WithSelfDescriptor::class)
4243
subclass(DescendantsTraversalStep.WithoutSelfDescriptor::class)

0 commit comments

Comments
 (0)