diff --git a/modelql-client/src/jvmTest/kotlin/org/modelix/modelql/client/ModelQLClientTest.kt b/modelql-client/src/jvmTest/kotlin/org/modelix/modelql/client/ModelQLClientTest.kt index 3f2b91cf96..ba5f84b817 100644 --- a/modelql-client/src/jvmTest/kotlin/org/modelix/modelql/client/ModelQLClientTest.kt +++ b/modelql-client/src/jvmTest/kotlin/org/modelix/modelql/client/ModelQLClientTest.kt @@ -17,6 +17,7 @@ import io.ktor.client.HttpClient import io.ktor.server.routing.routing import io.ktor.server.testing.testApplication import kotlinx.coroutines.withTimeout +import org.modelix.model.api.ConceptReference import org.modelix.model.api.IConceptReference import org.modelix.model.api.INode import org.modelix.model.api.PBranch @@ -43,6 +44,7 @@ import org.modelix.modelql.server.ModelQLServer import org.modelix.modelql.untyped.addNewChild import org.modelix.modelql.untyped.allChildren import org.modelix.modelql.untyped.allReferences +import org.modelix.modelql.untyped.asMono import org.modelix.modelql.untyped.children import org.modelix.modelql.untyped.descendants import org.modelix.modelql.untyped.nodeReference @@ -250,4 +252,12 @@ class ModelQLClientTest { assertEquals(null, nullNode) } + + @Test + fun `mono can be created from set of concept references`() = runTest { httpClient -> + val client = ModelQLClient("http://localhost/query", httpClient) + val refSet = setOf(ConceptReference("abc"), ConceptReference("def")) + val result = client.query { refSet.asMono() } + assertEquals(refSet, result) + } } diff --git a/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/ConceptReferenceSetSourceStep.kt b/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/ConceptReferenceSetSourceStep.kt new file mode 100644 index 0000000000..f3a86c4843 --- /dev/null +++ b/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/ConceptReferenceSetSourceStep.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.modelix.modelql.untyped + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.modelix.model.api.ConceptReference +import org.modelix.modelql.core.ConstantSourceStep +import org.modelix.modelql.core.IStep +import org.modelix.modelql.core.QueryDeserializationContext +import org.modelix.modelql.core.QueryGraphDescriptorBuilder +import org.modelix.modelql.core.StepDescriptor +import kotlin.reflect.typeOf + +class ConceptReferenceSetSourceStep(val referenceSet: Set) : ConstantSourceStep>(referenceSet, typeOf>()) { + override fun createDescriptor(context: QueryGraphDescriptorBuilder): StepDescriptor = Descriptor(referenceSet) + + @Serializable + @SerialName("conceptReferenceSetMonoSource") + class Descriptor(val referenceSet: Set) : StepDescriptor() { + override fun createStep(context: QueryDeserializationContext): IStep { + return ConceptReferenceSetSourceStep(referenceSet) + } + } + + override fun canEvaluateStatically(): Boolean = true + override fun evaluateStatically(): Set = referenceSet +} + +fun Set.asMono() = ConceptReferenceSetSourceStep(this) diff --git a/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt b/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt index 586155a732..5d5eec2bdf 100644 --- a/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt +++ b/modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt @@ -37,6 +37,7 @@ object UntypedModelQL { subclass(AllReferencesTraversalStep.Descriptor::class) subclass(ChildrenTraversalStep.ChildrenStepDescriptor::class) subclass(ConceptReferenceTraversalStep.Descriptor::class) + subclass(ConceptReferenceSetSourceStep.Descriptor::class) subclass(ConceptReferenceUIDTraversalStep.Descriptor::class) subclass(DescendantsTraversalStep.WithSelfDescriptor::class) subclass(DescendantsTraversalStep.WithoutSelfDescriptor::class)