@@ -159,9 +159,10 @@ class ModelImporter(
159
159
currentNodeProgress + = 1
160
160
progressReporter.step(currentNodeProgress.toULong())
161
161
doAndPotentiallyContinueOnErrors {
162
- syncProperties(node, data)
163
- syncChildren(node, data, progressReporter)
164
- syncReferences(node, data)
162
+ val conceptCorrectedNode = checkAndHandleConceptChange(node, data)
163
+ syncProperties(conceptCorrectedNode, data)
164
+ syncChildren(conceptCorrectedNode, data, progressReporter)
165
+ syncReferences(conceptCorrectedNode, data)
165
166
}
166
167
}
167
168
@@ -197,7 +198,9 @@ class ModelImporter(
197
198
// optimization for when there is no change in the child list
198
199
// size check first to avoid querying the original ID
199
200
if (expectedNodes.size == existingNodes.size && expectedNodes.map { it.originalId() } == existingNodes.map { it.originalId() }) {
200
- existingNodes.zip(expectedNodes).forEach { syncNode(it.first, it.second, progressReporter) }
201
+ existingNodes.zip(expectedNodes).forEach {
202
+ syncNode(it.first, it.second, progressReporter)
203
+ }
201
204
continue
202
205
}
203
206
@@ -252,8 +255,6 @@ class ModelImporter(
252
255
} else {
253
256
nodeAtIndex
254
257
}
255
- check(childNode.getConceptReference() == expectedConcept) { " Unexpected concept change from $expectedConcept to ${childNode.getConceptReference()} " }
256
-
257
258
syncNode(childNode, expected, progressReporter)
258
259
}
259
260
@@ -267,6 +268,15 @@ class ModelImporter(
267
268
}
268
269
}
269
270
271
+ private fun checkAndHandleConceptChange (existingNode : INode , expectedNode : NodeData ): INode {
272
+ val newConcept = expectedNode.concept?.let { ConceptReference (it) }
273
+ if (existingNode.getConceptReference() == newConcept) {
274
+ return existingNode
275
+ }
276
+ requireNotNull(newConcept) { " Unexpected null concept" }
277
+ return existingNode.replaceNode(newConcept)
278
+ }
279
+
270
280
private fun buildExistingIndex (): MutableMap <String , INodeReference > {
271
281
val localOriginalIdToExisting = createMemoryEfficientMap<String , INodeReference >()
272
282
root.getDescendants(true ).forEach { node ->
0 commit comments