Skip to content

Commit

Permalink
Merge pull request #977 from modelix/feat/modelql-concept-ref-mono
Browse files Browse the repository at this point in the history
MODELIX-972 Support creating sets of ConceptReference instances in ModelQl
  • Loading branch information
mhuster23 authored Aug 13, 2024
2 parents 86b62d9 + dbb6118 commit d47e127
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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<ConceptReference>) : ConstantSourceStep<Set<ConceptReference>>(referenceSet, typeOf<Set<ConceptReference>>()) {
override fun createDescriptor(context: QueryGraphDescriptorBuilder): StepDescriptor = Descriptor(referenceSet)

@Serializable
@SerialName("conceptReferenceSetMonoSource")
class Descriptor(val referenceSet: Set<ConceptReference>) : StepDescriptor() {
override fun createStep(context: QueryDeserializationContext): IStep {
return ConceptReferenceSetSourceStep(referenceSet)
}
}

override fun canEvaluateStatically(): Boolean = true
override fun evaluateStatically(): Set<ConceptReference> = referenceSet
}

fun Set<ConceptReference>.asMono() = ConceptReferenceSetSourceStep(this)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d47e127

Please sign in to comment.