-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MODELIX-971 allProperties missing in ModelQl on INode #895
Closed
+98
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...l-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/AllPropertiesTraversalStep.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.flatMapConcat | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import org.modelix.model.api.INode | ||
import org.modelix.model.api.IProperty | ||
import org.modelix.modelql.core.FluxTransformingStep | ||
import org.modelix.modelql.core.IFlowInstantiationContext | ||
import org.modelix.modelql.core.IFluxStep | ||
import org.modelix.modelql.core.IProducingStep | ||
import org.modelix.modelql.core.IStep | ||
import org.modelix.modelql.core.IStepOutput | ||
import org.modelix.modelql.core.QueryDeserializationContext | ||
import org.modelix.modelql.core.QueryGraphDescriptorBuilder | ||
import org.modelix.modelql.core.SerializationContext | ||
import org.modelix.modelql.core.StepDescriptor | ||
import org.modelix.modelql.core.StepFlow | ||
import org.modelix.modelql.core.asStepFlow | ||
import org.modelix.modelql.core.connect | ||
import org.modelix.modelql.core.stepOutputSerializer | ||
|
||
class AllPropertiesTraversalStep : FluxTransformingStep<INode, Pair<IProperty, String?>>() { | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
override fun createFlow( | ||
input: StepFlow<INode>, | ||
context: IFlowInstantiationContext, | ||
): StepFlow<Pair<IProperty, String?>> { | ||
return input.flatMapConcat { it.value.getAllPropertiesAsFlow() }.asStepFlow(this) | ||
} | ||
|
||
override fun getOutputSerializer(serializationContext: SerializationContext): KSerializer<out IStepOutput<Pair<IProperty, String?>>> { | ||
return serializationContext.serializer<Pair<IProperty, String?>>().stepOutputSerializer(this) | ||
} | ||
|
||
override fun createDescriptor(context: QueryGraphDescriptorBuilder): StepDescriptor = AllPropertiesStepDescriptor() | ||
|
||
@Serializable | ||
@SerialName("untyped.allProperties") | ||
class AllPropertiesStepDescriptor : StepDescriptor() { | ||
override fun createStep(context: QueryDeserializationContext): IStep { | ||
return AllPropertiesTraversalStep() | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return """${getProducer()}.allProperties()""" | ||
} | ||
} | ||
|
||
fun IProducingStep<INode>.allProperties(): IFluxStep<Pair<IProperty, String?>> = | ||
AllPropertiesTraversalStep().also { connect(it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works, because the test case uses a
CLTree
with named based roles. Not all implementations ofIProperty
are serializable. I think we need https://issues.modelix.org/issue/MODELIX-976/Cleanup-relation-between-model-and-meta-model first and then return anIPropertyReference
(orIPropertyId
, not sure yet) instead, that can be resolved on the client side to an IPropertyDefinition if needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it with a CLTree that uses
useRoleIds = true
and it works for that case as well.But your proposed solution would definitely be cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the role is always wrapped by a
PropertyFromName
, even if it is an ID. This really needs to be cleaned up.