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

[fed guid optimization] reverse synchronizing deletes of elements with random ExternalSourceAspects does not work #118

Closed ViliusRuskys closed 1 year ago

ViliusRuskys commented 1 year ago

Transformer does not resolve provenance for deleted elements if that element contains a random ExternalSourceAspect in reverse synchronization workflow.

Pre fedGuid update all elements had to contain an ExternalSourceAspect in order to track provenance, so in order to track provenance for deleted elements the transformer had to query deleted ExternalSourceAspects (in reverse sync workflow). If a deleted element had no ExternalSourceAspect, that meant the element does not exist in original iModel and no delete operation must be performed. That is achieved by these WHERE statements in remapDeletedSourceEntities()

AND (esac.Scope.Id=:targetScopeElement OR esac.Scope.Id IS NULL)
AND (esac.Kind='Element' OR esac.Kind IS NULL)

Post fedGuid update elements' provenance is tracked by federation guids. Now if an element contains a random ExternalSourceAspect (that was not created by the transformer), the above mentioned WHERE statement actually excludes the element from the query results because that random ExternalSourceAspect will not match the Kind and/or Scope.id columns, hence the provenance will be skipped for the given element.

MichaelBelousov commented 1 year ago

The solution should be moving the WHERE condition into the SELECT result, to not exclude those elements, but I am having issues during this with sqlite IIF or CASE statements, I will talk to some ecdb developers.

MichaelBelousov commented 1 year ago

updated the PR with a fix, going to merge and publish probably

MichaelBelousov commented 1 year ago

published, closing