Skip to content

Commit 1c73be5

Browse files
committed
fix(model-sync-lib): fixed move not being applied on new parents
1 parent c418222 commit 1c73be5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

model-sync-lib/src/main/kotlin/org/modelix/model/sync/ModelImporter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class ModelImporter(private val root: INode, val stats: ImportStats? = null) {
2727
val addedNodes = addAllMissingChildren(root, originalIdToExisting, originalIdToSpec)
2828
syncAllProperties(addedNodes, originalIdToSpec)
2929

30-
handleAllMovesAcrossParents(allExistingNodes, originalIdToExisting, originalIdToSpec)
3130

3231
val allNodes = allExistingNodes + addedNodes
32+
handleAllMovesAcrossParents(allNodes, originalIdToExisting, originalIdToSpec)
3333
val originalIdToRef: MutableMap<String, INodeReference> = buildRefIndex(allNodes)
3434
syncAllReferences(allNodes, originalIdToSpec, originalIdToRef)
3535
deleteAllExtraChildren(allNodes, originalIdToSpec)
@@ -217,8 +217,8 @@ class ModelImporter(private val root: INode, val stats: ImportStats? = null) {
217217
toBeMovedHere.forEach {nodeToBeMoved ->
218218
val spec = originalIdToSpec[nodeToBeMoved.originalId()]!!
219219

220-
val baseTargetIndex = spec.getIndexWithinRole(nodeData, existingChildren.size - 1)
221-
val offset = existingChildren.slice(0..baseTargetIndex).count {
220+
val baseTargetIndex = spec.getIndexWithinRole(nodeData, existingChildren.lastIndex)
221+
val offset = existingChildren.slice(0 until baseTargetIndex).count {
222222
!originalIdToSpec.containsKey(it.originalId()) // node will be deleted
223223
}
224224
val targetIndex = baseTargetIndex + offset

model-sync-lib/src/test/kotlin/org/modelix/model/sync/ModelImporterTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ModelImporterTest {
128128
val tree0 = CLTree(ObjectStoreCache(MapBaseStore()))
129129
val branch0 = PBranch(tree0, IdGenerator.getInstance(1))
130130

131-
val seed = 1896439714 //Random.nextInt()
131+
val seed = Random.nextInt()
132132
println("Seed for random change test: $seed")
133133
lateinit var initialState: NodeData
134134
lateinit var specification: NodeData
@@ -158,14 +158,14 @@ class ModelImporterTest {
158158
importer.import(ModelData(root = initialState))
159159
importer.import(ModelData(root = specification))
160160

161-
println("INITIAL")
162-
println(initialState.toJson())
163-
164-
println("SPEC")
165-
println(specification.toJson())
166-
167-
println("ACTUAL")
168-
println(branch1.getRootNode().toJson())
161+
// println("INITIAL")
162+
// println(initialState.toJson())
163+
//
164+
// println("SPEC")
165+
// println(specification.toJson())
166+
//
167+
// println("ACTUAL")
168+
// println(branch1.getRootNode().toJson())
169169

170170
assertAllNodesConformToSpec(specification, branch1.getRootNode())
171171
assert(importer.stats!!.getTotal() <= numChanges)

0 commit comments

Comments
 (0)