-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bulk-model-sync): deduplication of sync algorithm in ModelImporte…
…r and ModelSynchronizer
- Loading branch information
Showing
8 changed files
with
279 additions
and
274 deletions.
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
307 changes: 44 additions & 263 deletions
307
bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/ModelImporter.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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
171 changes: 171 additions & 0 deletions
171
model-api/src/commonMain/kotlin/org/modelix/model/data/NodeDataAsNode.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,171 @@ | ||
package org.modelix.model.data | ||
|
||
import org.modelix.model.api.ConceptReference | ||
import org.modelix.model.api.IChildLinkReference | ||
import org.modelix.model.api.IConcept | ||
import org.modelix.model.api.IMutableModel | ||
import org.modelix.model.api.INode | ||
import org.modelix.model.api.INodeReference | ||
import org.modelix.model.api.IPropertyReference | ||
import org.modelix.model.api.IReferenceLinkReference | ||
import org.modelix.model.api.IWritableNode | ||
import org.modelix.model.api.NodeReference | ||
import org.modelix.model.api.WritableNodeAsLegacyNode | ||
import org.modelix.model.api.getDescendants | ||
import org.modelix.model.api.meta.NullConcept | ||
import org.modelix.model.api.resolve | ||
|
||
class NodeDataAsNode(val data: NodeData, val parent: NodeDataAsNode?) : IWritableNode { | ||
private val index: Map<String, NodeDataAsNode>? = if (parent != null) { | ||
null | ||
} else { | ||
asLegacyNode().getDescendants(true) | ||
.map { it.asWritableNode() as NodeDataAsNode } | ||
.filter { it.data.id != null } | ||
.associateBy { it.data.id!! } | ||
} | ||
|
||
private fun getIndex(): Map<String, NodeDataAsNode> = (parent?.getIndex() ?: index)!! | ||
|
||
private fun resolveNode(ref: INodeReference): IWritableNode { | ||
return checkNotNull(getIndex()[ref.serialize()]) { "Node not found: ${ref.serialize()}\n" + getIndex().keys } | ||
} | ||
|
||
override fun asLegacyNode(): INode { | ||
return WritableNodeAsLegacyNode(this) | ||
} | ||
|
||
override fun getModel(): IMutableModel { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun isValid(): Boolean { | ||
return true | ||
} | ||
|
||
override fun getNodeReference(): INodeReference { | ||
return NodeReference(checkNotNull(data.id) { "No ID specified" }) | ||
} | ||
|
||
override fun getConcept(): IConcept { | ||
return data.concept?.let { ConceptReference(it).resolve() } ?: NullConcept | ||
} | ||
|
||
override fun getConceptReference(): ConceptReference { | ||
return data.concept?.let { ConceptReference(it) } ?: NullConcept.getReference() | ||
} | ||
|
||
override fun getParent(): IWritableNode? { | ||
return parent | ||
} | ||
|
||
override fun getContainmentLink(): IChildLinkReference { | ||
return IChildLinkReference.fromUnclassifiedString(data.role) | ||
} | ||
|
||
override fun getAllChildren(): List<IWritableNode> { | ||
return data.children.map { NodeDataAsNode(it, this) } | ||
} | ||
|
||
override fun getChildren(role: IChildLinkReference): List<IWritableNode> { | ||
return getAllChildren().filter { it.getContainmentLink().matches(role) } | ||
} | ||
|
||
override fun getPropertyValue(property: IPropertyReference): String? { | ||
return data.properties.entries | ||
.find { IPropertyReference.fromUnclassifiedString(it.key).matches(property) } | ||
?.value | ||
} | ||
|
||
override fun getPropertyLinks(): List<IPropertyReference> { | ||
return data.properties.keys.map { IPropertyReference.fromUnclassifiedString(it) } | ||
} | ||
|
||
override fun getAllProperties(): List<Pair<IPropertyReference, String>> { | ||
return data.properties.map { IPropertyReference.fromUnclassifiedString(it.key) to it.value } | ||
} | ||
|
||
override fun getReferenceTarget(role: IReferenceLinkReference): IWritableNode? { | ||
return getReferenceTargetRef(role)?.let { resolveNode(it) } | ||
} | ||
|
||
override fun getReferenceTargetRef(role: IReferenceLinkReference): INodeReference? { | ||
return data.references.entries | ||
.find { IReferenceLinkReference.fromUnclassifiedString(it.key).matches(role) } | ||
?.value | ||
?.let { NodeReference(it) } | ||
} | ||
|
||
override fun getReferenceLinks(): List<IReferenceLinkReference> { | ||
return data.references.keys.map { IReferenceLinkReference.fromUnclassifiedString(it) } | ||
} | ||
|
||
override fun getAllReferenceTargets(): List<Pair<IReferenceLinkReference, IWritableNode>> { | ||
return getAllReferenceTargetRefs().map { it.first to resolveNode(it.second) } | ||
} | ||
|
||
override fun getAllReferenceTargetRefs(): List<Pair<IReferenceLinkReference, INodeReference>> { | ||
return data.references.map { IReferenceLinkReference.fromUnclassifiedString(it.key) to NodeReference(it.value) } | ||
} | ||
|
||
override fun changeConcept(newConcept: ConceptReference): IWritableNode { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun setPropertyValue(property: IPropertyReference, value: String?) { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun moveChild( | ||
role: IChildLinkReference, | ||
index: Int, | ||
child: IWritableNode, | ||
) { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun removeChild(child: IWritableNode) { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun addNewChild( | ||
role: IChildLinkReference, | ||
index: Int, | ||
concept: ConceptReference, | ||
): IWritableNode { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun addNewChildren( | ||
role: IChildLinkReference, | ||
index: Int, | ||
concepts: List<ConceptReference>, | ||
): List<IWritableNode> { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun setReferenceTarget( | ||
role: IReferenceLinkReference, | ||
target: IWritableNode?, | ||
) { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun setReferenceTargetRef( | ||
role: IReferenceLinkReference, | ||
target: INodeReference?, | ||
) { | ||
throw UnsupportedOperationException("Immutable") | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is NodeDataAsNode) return false | ||
if (data.id == null) return false | ||
return other.data.id == data.id && parent == other.parent | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return data.id.hashCode() + parent.hashCode() | ||
} | ||
} |
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