iTwin / imodel-transformer

API for exporting an iModel's parts and also importing them into another iModel
MIT License
3 stars 2 forks source link

When calling NativeImportContext::CloneElement, the rootSubject should be special cased in the event of a remapping rule from rootSubject to some other subjectId #149

Closed nick4598 closed 2 weeks ago

nick4598 commented 4 months ago

In the test "should sync Team iModels into Shared" in IModelTransformer.test.ts:

A subject is created within the shared iModel for each Team iModel. The team iModel's rootSubject is then remapped to the subject created for that team iModel with the following code: transformerA2S.context.remapElement(IModel.rootSubjectId, subjectId). This is so all of the content of the team iModel, "A", finds its way under the subject "A" in the shared iModel.

Additionally, at the moment the subjectId is also added to the importer's set of doNotUpdateElementIds: transformerA2S.importer.doNotUpdateElementIds.add(subjectId);

Without the change to add the subjectId to the set of doNotUpdateElementIds we run into an issue where after the processAll (with team iModel as source, and shared iModel as target). The scope on the code on the subject "A" in the shared iModel changes to the id of the subject "A" itself when it should remain the same id as subject "A"s parent which is the rootSubject.

The reason this is happening is that the rootSubject is special in that the scope of its code is the id of the rootsubject itself. This is because the rootsubject has no parent.

When we remap the rootsubject: transformerA2S.context.remapElement(IModel.rootSubjectId, subjectId), NativeImportContext::CloneElement mistakenly updates the scope on the code of subjectId to be subjectId. This is normal and expected behavior for all other subjects, but incorrect when the rootSubject is involved.

A change will have to be made somewhere in NativeImportContext::CloneElement.

What does success look like?