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

Root elements should not be updated when 'skipPropagateChangesToRootElements' is set to true #174

Closed JulijaRamoskiene closed 4 months ago

JulijaRamoskiene commented 5 months ago

Describe the bug

If root elements are marked as having dangling references, they will be updated in makePartialEntityCompleter() even when skipPropagateChangesToRootElements is set to true:

https://github.com/JulijaRamoskiene/imodel-transformer/blob/8ea8f69b994321215a2eea9df89ee11045948961/packages/transformer/src/IModelTransformer.ts#L734

To Reproduce

  1. Remap root subject into newly created subject.
  2. Set skipPropagateChangesToRootElements to true.
  3. Call processAll().
  4. Verify root element parent ids. They should still be set to 0x1.

    it("should not update root elements when skipPropagateChangesToRootElements is set to true", async () => {
    const iModelShared: SnapshotDb = IModelTransformerTestUtils.createSharedIModel(outputDir, ["A", "B"]);
    const iModelA: SnapshotDb = IModelTransformerTestUtils.createTeamIModel(
      outputDir,
      "A",
      Point3d.create(0, 0, 0),
      ColorDef.green
    );
    IModelTransformerTestUtils.assertTeamIModelContents(iModelA, "A");
    const iModelExporterA = new IModelExporter(iModelA);
    
    const subjectId: Id64String = IModelTransformerTestUtils.querySubjectId(
      iModelShared,
      "A"
    );
    const transformerA2S = new IModelTransformer(
      iModelExporterA,
      iModelShared,
      { targetScopeElementId: subjectId, danglingReferencesBehavior: "ignore", skipPropagateChangesToRootElements: true }
    );
    transformerA2S.context.remapElement(IModel.rootSubjectId, subjectId);
    
    // Act
    await transformerA2S.processAll();
    
    // Assert
    const rootElements = ["0x10", "0xe"];
    rootElements.forEach(rootElementId => {
      const dictionary = iModelShared.elements.getElement(rootElementId);
      assert.equal(dictionary.parent?.id, "0x1", `Root element '${rootElementId}' parent should not be remapped to '${dictionary.parent?.id}'.`);
    });
    
    transformerA2S.dispose();
    iModelA.close();
    iModelShared.close();
    });

    Expected behavior Root elements should not be updated.

Desktop (please complete the applicable information):

Additional context

Elements in target imodel after running transformation with 0.4.18-fedguidopt.6 @itwin/imodel-transformer package version image

Elements in target imodel after running transformation with 1.0.0-dev.6 @itwin/imodel-transformer package version image

JulijaRamoskiene commented 5 months ago

Related issue: https://github.com/iTwin/imodel-transformer/issues/167

nick4598 commented 5 months ago

Thanks for the test: https://github.com/iTwin/imodel-transformer/pull/176