Skip to content

Commit 9866c24

Browse files
committed
fix(bulk-model-sync): do not delete newly created nodes
If nodes are exported from the model-server, they will the model-server node id as originalId. This caused a mismatch with the mps id, which led to them being deleted.
1 parent 9824aea commit 9866c24

File tree

1 file changed

+7
-1
lines changed
  • bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class ModelImporter(
203203

204204
val isOrdered = existingParent.isChildRoleOrdered(role)
205205

206+
val newlyCreatedIds = mutableSetOf<String>()
207+
206208
expectedNodes.forEachIndexed { indexInImport, expected ->
207209
val existingChildren = existingParent.getChildren(role).toList()
208210
val expectedId = checkNotNull(expected.originalId()) { "Specified node '$expected' has no id" }
@@ -229,6 +231,7 @@ class ModelImporter(
229231
if (newChild.originalId() == null) {
230232
newChild.setPropertyValue(NodeData.idPropertyKey, expectedId)
231233
}
234+
newChild.originalId()?.let { newlyCreatedIds.add(it) }
232235
originalIdToExisting[expectedId] = newChild.reference
233236
newChild
234237
} else {
@@ -257,7 +260,10 @@ class ModelImporter(
257260
val expectedNodesIds = expectedNodes.map(NodeData::originalId).toSet()
258261
// Do not use existingNodes, but call node.getChildren(role) because
259262
// the recursive synchronization in the meantime already removed some nodes from node.getChildren(role).
260-
nodesToRemove += existingParent.getChildren(role).filterNot { existingNode -> expectedNodesIds.contains(existingNode.originalId()) }
263+
nodesToRemove += existingParent.getChildren(role).filterNot { existingNode ->
264+
val id = existingNode.originalId()
265+
expectedNodesIds.contains(id) || newlyCreatedIds.contains(id)
266+
}
261267
}
262268
}
263269

0 commit comments

Comments
 (0)