@itwin/imodel-transformer 1.1.4-dev.0 → 1.2.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/lib/cjs/Algo.js +3 -2
- package/lib/cjs/Algo.js.map +1 -1
- package/lib/cjs/BigMap.d.ts +4 -4
- package/lib/cjs/BigMap.d.ts.map +1 -1
- package/lib/cjs/BigMap.js +0 -2
- package/lib/cjs/BigMap.js.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.d.ts.map +1 -1
- package/lib/cjs/BranchProvenanceInitializer.js +7 -6
- package/lib/cjs/BranchProvenanceInitializer.js.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.d.ts.map +1 -1
- package/lib/cjs/ECReferenceTypesCache.js +19 -22
- package/lib/cjs/ECReferenceTypesCache.js.map +1 -1
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js +2 -3
- package/lib/cjs/ECSqlReaderAsyncIterableIteratorAdapter.js.map +1 -1
- package/lib/cjs/ElementCascadingDeleter.js +2 -2
- package/lib/cjs/ElementCascadingDeleter.js.map +1 -1
- package/lib/cjs/EntityMap.d.ts +4 -4
- package/lib/cjs/EntityMap.js +3 -1
- package/lib/cjs/EntityMap.js.map +1 -1
- package/lib/cjs/EntityUnifier.d.ts.map +1 -1
- package/lib/cjs/EntityUnifier.js +2 -2
- package/lib/cjs/EntityUnifier.js.map +1 -1
- package/lib/cjs/ExportElementAspectsStrategy.js +4 -7
- package/lib/cjs/ExportElementAspectsStrategy.js.map +1 -1
- package/lib/cjs/IModelCloneContext.js +5 -2
- package/lib/cjs/IModelCloneContext.js.map +1 -1
- package/lib/cjs/IModelExporter.d.ts.map +1 -1
- package/lib/cjs/IModelExporter.js +55 -69
- package/lib/cjs/IModelExporter.js.map +1 -1
- package/lib/cjs/IModelImporter.js +39 -53
- package/lib/cjs/IModelImporter.js.map +1 -1
- package/lib/cjs/IModelTransformer.d.ts +35 -1
- package/lib/cjs/IModelTransformer.d.ts.map +1 -1
- package/lib/cjs/IModelTransformer.js +159 -73
- package/lib/cjs/IModelTransformer.js.map +1 -1
- package/package.json +19 -19
|
@@ -13,8 +13,8 @@ const Semver = require("semver");
|
|
|
13
13
|
const nodeAssert = require("assert");
|
|
14
14
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
15
|
const core_geometry_1 = require("@itwin/core-geometry");
|
|
16
|
+
const coreBackendPkgJson = require("@itwin/core-backend/package.json");
|
|
16
17
|
const core_backend_1 = require("@itwin/core-backend");
|
|
17
|
-
const Symbols_1 = require("@itwin/core-backend/lib/cjs/internal/Symbols");
|
|
18
18
|
const core_common_1 = require("@itwin/core-common");
|
|
19
19
|
const IModelExporter_1 = require("./IModelExporter");
|
|
20
20
|
const IModelImporter_1 = require("./IModelImporter");
|
|
@@ -66,37 +66,10 @@ function mapId64(idContainer, func) {
|
|
|
66
66
|
* @beta
|
|
67
67
|
*/
|
|
68
68
|
class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
69
|
-
/** The IModelExporter that will export from the source iModel. */
|
|
70
|
-
exporter;
|
|
71
|
-
/** The IModelImporter that will import into the target iModel. */
|
|
72
|
-
importer;
|
|
73
|
-
/** The normally read-only source iModel.
|
|
74
|
-
* @note The source iModel will need to be read/write when provenance is being stored during a reverse synchronization.
|
|
75
|
-
*/
|
|
76
|
-
sourceDb;
|
|
77
|
-
/** The read/write target iModel. */
|
|
78
|
-
targetDb;
|
|
79
|
-
/** The IModelTransformContext for this IModelTransformer. */
|
|
80
|
-
context;
|
|
81
|
-
_syncType;
|
|
82
69
|
/** The Id of the Element in the **target** iModel that represents the **source** repository as a whole and scopes its [ExternalSourceAspect]($backend) instances. */
|
|
83
70
|
get targetScopeElementId() {
|
|
84
71
|
return this._options.targetScopeElementId;
|
|
85
72
|
}
|
|
86
|
-
/** a set of elements for which source provenance will be explicitly tracked by ExternalSourceAspects */
|
|
87
|
-
_elementsWithExplicitlyTrackedProvenance = new Set();
|
|
88
|
-
_partiallyCommittedElementIds = new Set();
|
|
89
|
-
_partiallyCommittedAspectIds = new Set();
|
|
90
|
-
/** the options that were used to initialize this transformer */
|
|
91
|
-
_options;
|
|
92
|
-
/**
|
|
93
|
-
* A private variable meant to be set by tests which have an outdated way of setting up transforms. In all synchronizations today we expect to find an ESA in the branch db which describes the master -> branch relationship.
|
|
94
|
-
* The exception to this is the first transform aka the provenance initializing transform which requires that the master imodel and the branch imodel are identical at the time of provenance initialization.
|
|
95
|
-
* A couple ofoutdated tests run their first transform providing a source and targetdb that are slightly different which is no longer supported. In order to not remove these tests which are still providing value
|
|
96
|
-
* this private property on the IModelTransformer exists.
|
|
97
|
-
*/
|
|
98
|
-
_allowNoScopingESA = false;
|
|
99
|
-
static noEsaSyncDirectionErrorMessage = "Couldn't find an external source aspect to determine sync direction. This often means that the master->branch relationship has not been established. Consider running the transformer with wasSourceIModelCopiedToTarget set to true.";
|
|
100
73
|
/**
|
|
101
74
|
* Queries for an esa which matches the props in the provided aspectProps.
|
|
102
75
|
* @param dbToQuery db to run the query on for scope external source
|
|
@@ -199,12 +172,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
199
172
|
this._syncType = this.determineSyncType();
|
|
200
173
|
return this._syncType === "forward";
|
|
201
174
|
}
|
|
202
|
-
_changesetRanges = undefined;
|
|
203
|
-
/**
|
|
204
|
-
* Set if the transformer is being used to perform the provenance initialization step of a fork initialization.
|
|
205
|
-
* In general don't use the transformer for that, prefer [[BranchProvenanceInitializer.initializeBranchProvenance]]
|
|
206
|
-
*/
|
|
207
|
-
_isProvenanceInitTransform;
|
|
208
175
|
/** The element classes that are considered to define provenance in the iModel */
|
|
209
176
|
static get provenanceElementClasses() {
|
|
210
177
|
return [
|
|
@@ -225,6 +192,47 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
225
192
|
*/
|
|
226
193
|
constructor(source, target, options) {
|
|
227
194
|
super();
|
|
195
|
+
/** a set of elements for which source provenance will be explicitly tracked by ExternalSourceAspects */
|
|
196
|
+
this._elementsWithExplicitlyTrackedProvenance = new Set();
|
|
197
|
+
this._partiallyCommittedElementIds = new Set();
|
|
198
|
+
this._partiallyCommittedAspectIds = new Set();
|
|
199
|
+
/**
|
|
200
|
+
* A private variable meant to be set by tests which have an outdated way of setting up transforms. In all synchronizations today we expect to find an ESA in the branch db which describes the master -> branch relationship.
|
|
201
|
+
* The exception to this is the first transform aka the provenance initializing transform which requires that the master imodel and the branch imodel are identical at the time of provenance initialization.
|
|
202
|
+
* A couple ofoutdated tests run their first transform providing a source and targetdb that are slightly different which is no longer supported. In order to not remove these tests which are still providing value
|
|
203
|
+
* this private property on the IModelTransformer exists.
|
|
204
|
+
*/
|
|
205
|
+
this._allowNoScopingESA = false;
|
|
206
|
+
this._changesetRanges = undefined;
|
|
207
|
+
/**
|
|
208
|
+
* Previously the transformer would insert provenance always pointing to the "target" relationship.
|
|
209
|
+
* It should (and now by default does) instead insert provenance pointing to the provenanceSource
|
|
210
|
+
* SEE: https://github.com/iTwin/imodel-transformer/issues/54
|
|
211
|
+
* This exists only to facilitate testing that the transformer can handle the older, flawed method
|
|
212
|
+
*/
|
|
213
|
+
this._forceOldRelationshipProvenanceMethod = false;
|
|
214
|
+
/** NOTE: the json properties must be converted to string before insertion */
|
|
215
|
+
this._targetScopeProvenanceProps = undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Index of the changeset that the transformer was at when the transformation begins (was constructed).
|
|
218
|
+
* Used to determine at the end which changesets were part of a synchronization.
|
|
219
|
+
*/
|
|
220
|
+
this._startingChangesetIndices = undefined;
|
|
221
|
+
this._cachedSynchronizationVersion = undefined;
|
|
222
|
+
this._targetClassNameToClassIdCache = new Map();
|
|
223
|
+
// if undefined, it can be initialized by calling [[this.processChangesets]]
|
|
224
|
+
this._deletedSourceRelationshipData = undefined;
|
|
225
|
+
this._yieldManager = new core_bentley_1.YieldManager();
|
|
226
|
+
/** The directory where schemas will be exported, a random temporary directory */
|
|
227
|
+
this._schemaExportDir = path.join(core_backend_1.KnownLocations.tmpdir, core_bentley_1.Guid.createValue());
|
|
228
|
+
this._longNamedSchemasMap = new Map();
|
|
229
|
+
/** state to prevent reinitialization, @see [[initialize]] */
|
|
230
|
+
this._initialized = false;
|
|
231
|
+
this._sourceChangeDataState = "uninited";
|
|
232
|
+
/** length === 0 when _changeDataState = "no-change", length > 0 means "has-changes", otherwise undefined */
|
|
233
|
+
this._csFileProps = undefined;
|
|
234
|
+
/** previous provenance, either a federation guid, a `${sourceFedGuid}/${targetFedGuid}` pair, or required aspect props */
|
|
235
|
+
this._lastProvenanceEntityInfo = nullLastProvenanceEntityInfo;
|
|
228
236
|
// initialize IModelTransformOptions
|
|
229
237
|
this._options = {
|
|
230
238
|
...options,
|
|
@@ -235,6 +243,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
235
243
|
danglingReferencesBehavior: options?.danglingReferencesBehavior ?? "reject",
|
|
236
244
|
branchRelationshipDataBehavior: options?.branchRelationshipDataBehavior ?? "reject",
|
|
237
245
|
skipPropagateChangesToRootElements: options?.skipPropagateChangesToRootElements ?? true,
|
|
246
|
+
tryAlignGeolocation: options?.tryAlignGeolocation ?? false,
|
|
238
247
|
};
|
|
239
248
|
// check if authorization client is defined
|
|
240
249
|
if (core_backend_1.IModelHost.authorizationClient === undefined) {
|
|
@@ -290,6 +299,20 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
290
299
|
this.targetDb.codeValueBehavior = "exact";
|
|
291
300
|
}
|
|
292
301
|
/* eslint-enable @itwin/no-internal */
|
|
302
|
+
if (this._options.tryAlignGeolocation) {
|
|
303
|
+
if (this.sourceDb.geographicCoordinateSystem ||
|
|
304
|
+
this.targetDb.geographicCoordinateSystem) {
|
|
305
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Aligning Additional transforms between imodels due to imodels containing GeographicCoordinateSystem data");
|
|
306
|
+
this._linearSpatialTransform =
|
|
307
|
+
this.calculateTransformFromHelmertTransforms();
|
|
308
|
+
}
|
|
309
|
+
else if (this.sourceDb.ecefLocation && this.targetDb.ecefLocation) {
|
|
310
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Aligning ECEF Location's between imodels due to imodels not containing GeographicCoordinateSystem data");
|
|
311
|
+
this._linearSpatialTransform = this.calculateEcefTransform();
|
|
312
|
+
}
|
|
313
|
+
else
|
|
314
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "No Geolcation data to align, both GCS and ECEF are undefined");
|
|
315
|
+
}
|
|
293
316
|
}
|
|
294
317
|
/** validates that the importer set on the transformer has the same values for its shared options as the transformer.
|
|
295
318
|
* @note This expects that the importer is already set on the transformer.
|
|
@@ -394,13 +417,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
394
417
|
};
|
|
395
418
|
return aspectProps;
|
|
396
419
|
}
|
|
397
|
-
/**
|
|
398
|
-
* Previously the transformer would insert provenance always pointing to the "target" relationship.
|
|
399
|
-
* It should (and now by default does) instead insert provenance pointing to the provenanceSource
|
|
400
|
-
* SEE: https://github.com/iTwin/imodel-transformer/issues/54
|
|
401
|
-
* This exists only to facilitate testing that the transformer can handle the older, flawed method
|
|
402
|
-
*/
|
|
403
|
-
_forceOldRelationshipProvenanceMethod = false;
|
|
404
420
|
/** Create an ExternalSourceAspectProps in a standard way for an Element in an iModel --> iModel transformation. */
|
|
405
421
|
initElementProvenance(sourceElementId, targetElementId) {
|
|
406
422
|
return IModelTransformer.initElementProvenanceOptions(sourceElementId, targetElementId, {
|
|
@@ -424,14 +440,16 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
424
440
|
forceOldRelationshipProvenanceMethod: this._forceOldRelationshipProvenanceMethod,
|
|
425
441
|
});
|
|
426
442
|
}
|
|
427
|
-
/** NOTE: the json properties must be converted to string before insertion */
|
|
428
|
-
_targetScopeProvenanceProps = undefined;
|
|
429
443
|
/**
|
|
430
|
-
*
|
|
431
|
-
*
|
|
444
|
+
* As of itwinjs 4.6.0, definitionContainers are now deleted as if they were DefinitionPartitions as opposed to Definitions.
|
|
445
|
+
* This variable being true will be used to special case the deletion of DefinitionContainers the same way DefinitionPartitions are deleted.
|
|
432
446
|
*/
|
|
433
|
-
|
|
434
|
-
|
|
447
|
+
get hasDefinitionContainerDeletionFeature() {
|
|
448
|
+
if (this._hasDefinitionContainerDeletionFeature === undefined) {
|
|
449
|
+
this._hasDefinitionContainerDeletionFeature = Semver.satisfies(coreBackendPkgJson.version, "^4.6.0");
|
|
450
|
+
}
|
|
451
|
+
return this._hasDefinitionContainerDeletionFeature;
|
|
452
|
+
}
|
|
435
453
|
/**
|
|
436
454
|
* We cache the synchronization version to avoid querying the target scoping ESA multiple times.
|
|
437
455
|
* If the target scoping ESA is ever updated we need to clear any potentially cached sync version otherwise we will get stale values.
|
|
@@ -805,7 +823,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
805
823
|
return stmt.getValue(0).getId();
|
|
806
824
|
});
|
|
807
825
|
}
|
|
808
|
-
_targetClassNameToClassIdCache = new Map();
|
|
809
826
|
_targetClassNameToClassId(classFullName) {
|
|
810
827
|
let classId = this._targetClassNameToClassIdCache.get(classFullName);
|
|
811
828
|
if (classId === undefined) {
|
|
@@ -919,10 +936,87 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
919
936
|
targetElementProps.jsonProperties.Subject.Job = undefined;
|
|
920
937
|
}
|
|
921
938
|
}
|
|
939
|
+
if (this._linearSpatialTransform !== undefined &&
|
|
940
|
+
sourceElement instanceof core_backend_1.GeometricElement3d) {
|
|
941
|
+
// can check the sourceElement since this IModelTransformer does not remap classes
|
|
942
|
+
const placement = core_common_1.Placement3d.fromJSON(targetElementProps.placement);
|
|
943
|
+
if (placement.isValid) {
|
|
944
|
+
placement.multiplyTransform(this._linearSpatialTransform);
|
|
945
|
+
targetElementProps.placement = placement;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
922
948
|
return targetElementProps;
|
|
923
949
|
}
|
|
924
|
-
|
|
925
|
-
|
|
950
|
+
/**
|
|
951
|
+
* Calculate the transform between two ECEF locations
|
|
952
|
+
* @param srcDb
|
|
953
|
+
* @param targetDb
|
|
954
|
+
* @returns Transform that converts relative coordinates in the source iModel to relative coordinates in the target iModel.
|
|
955
|
+
* @note This can only be used if both source and target iModels are linearly located
|
|
956
|
+
*/
|
|
957
|
+
calculateEcefTransform() {
|
|
958
|
+
const srcEcefLoc = this.sourceDb.ecefLocation;
|
|
959
|
+
const targetEcefLoc = this.targetDb.ecefLocation;
|
|
960
|
+
if (srcEcefLoc === undefined || targetEcefLoc === undefined) {
|
|
961
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoGeoLocation, "Both source and target ECEF locations must be defined to calculate the transform.");
|
|
962
|
+
}
|
|
963
|
+
if (srcEcefLoc.getTransform().isAlmostEqual(targetEcefLoc.getTransform())) {
|
|
964
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "ECEF data is already aligned. No spatial transforms needed.");
|
|
965
|
+
return undefined;
|
|
966
|
+
}
|
|
967
|
+
const srcSpatialToECEF = srcEcefLoc.getTransform(); // converts relative to ECEF in relation to source
|
|
968
|
+
const targetECEFToSpatial = targetEcefLoc.getTransform().inverse(); // converts ECEF to relative in relation to target
|
|
969
|
+
if (!targetECEFToSpatial) {
|
|
970
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoGeoLocation, "Failed to invert target ECEF transform.");
|
|
971
|
+
}
|
|
972
|
+
const ecefTransform = targetECEFToSpatial.multiplyTransformTransform(srcSpatialToECEF); // chain both transforms
|
|
973
|
+
return ecefTransform;
|
|
974
|
+
}
|
|
975
|
+
static convertHelmertToTransform(helmert) {
|
|
976
|
+
if (!helmert) {
|
|
977
|
+
return core_geometry_1.Transform.createIdentity();
|
|
978
|
+
}
|
|
979
|
+
const rotationXY = core_geometry_1.Matrix3d.createRotationAroundAxisIndex(core_geometry_1.AxisIndex.Z, core_geometry_1.Angle.createDegrees(helmert?.rotDeg));
|
|
980
|
+
rotationXY.scaleColumnsInPlace(helmert.scale, helmert.scale, 1.0);
|
|
981
|
+
const translation = core_geometry_1.Vector3d.create(helmert.translationX, helmert.translationY, helmert.translationZ);
|
|
982
|
+
const helmertTransform = core_geometry_1.Transform.createRefs(translation, rotationXY);
|
|
983
|
+
return helmertTransform;
|
|
984
|
+
}
|
|
985
|
+
calculateTransformFromHelmertTransforms() {
|
|
986
|
+
if (this.sourceDb.geographicCoordinateSystem?.horizontalCRS === undefined ||
|
|
987
|
+
this.sourceDb.geographicCoordinateSystem?.verticalCRS === undefined) {
|
|
988
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, "Source iModel does not have a geographic coordinate system defined.");
|
|
989
|
+
}
|
|
990
|
+
if (this.targetDb.geographicCoordinateSystem?.horizontalCRS === undefined ||
|
|
991
|
+
this.targetDb.geographicCoordinateSystem.verticalCRS === undefined) {
|
|
992
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.BadRequest, "Target iModel does not have a geographic coordinate system defined.");
|
|
993
|
+
}
|
|
994
|
+
if (!this.sourceDb.geographicCoordinateSystem.horizontalCRS.equals(this.targetDb.geographicCoordinateSystem.horizontalCRS) ||
|
|
995
|
+
!this.sourceDb.geographicCoordinateSystem.verticalCRS.equals(this.targetDb.geographicCoordinateSystem.verticalCRS)) {
|
|
996
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.MismatchGcs, "Source and target geographic coordinate systems must match to calculate the spatial transform.");
|
|
997
|
+
}
|
|
998
|
+
if (this.sourceDb.geographicCoordinateSystem.additionalTransform ===
|
|
999
|
+
this.targetDb.geographicCoordinateSystem.additionalTransform) {
|
|
1000
|
+
core_bentley_1.Logger.logTrace(loggerCategory, "Geolocation data is already aligned. No spatial transforms needed.");
|
|
1001
|
+
return undefined;
|
|
1002
|
+
}
|
|
1003
|
+
const srcScale = this.sourceDb.geographicCoordinateSystem.additionalTransform
|
|
1004
|
+
?.helmert2DWithZOffset?.scale ?? 1;
|
|
1005
|
+
const targetScale = this.targetDb.geographicCoordinateSystem.additionalTransform
|
|
1006
|
+
?.helmert2DWithZOffset?.scale ?? 1;
|
|
1007
|
+
if (srcScale !== targetScale) {
|
|
1008
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.MismatchGcs, "Spatial transform is non rigid. Source and target Helmert transforms must have the same scale to calculate a rigid spatial transform.");
|
|
1009
|
+
}
|
|
1010
|
+
const srcTransform = IModelTransformer.convertHelmertToTransform(this.sourceDb.geographicCoordinateSystem.additionalTransform
|
|
1011
|
+
?.helmert2DWithZOffset); // moves elements to where src helmert transform would move them at render time
|
|
1012
|
+
const targetTransformInv = IModelTransformer.convertHelmertToTransform(this.targetDb.geographicCoordinateSystem.additionalTransform
|
|
1013
|
+
?.helmert2DWithZOffset).inverse(); // negates target helmert transform that is applied at render time
|
|
1014
|
+
if (!targetTransformInv) {
|
|
1015
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoGeoLocation, "Failed to invert target Helmert transform.");
|
|
1016
|
+
}
|
|
1017
|
+
const combinedTransform = targetTransformInv.multiplyTransformTransform(srcTransform);
|
|
1018
|
+
return combinedTransform;
|
|
1019
|
+
}
|
|
926
1020
|
/** Returns true if a change within sourceElement is detected.
|
|
927
1021
|
* @param sourceElement The Element from the source iModel
|
|
928
1022
|
* @note A subclass can override this method to provide custom change detection behavior.
|
|
@@ -1224,7 +1318,9 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1224
1318
|
const targetModelId = this.context.findTargetElementId(sourceModelId);
|
|
1225
1319
|
if (!core_bentley_1.Id64.isValidId64(targetModelId))
|
|
1226
1320
|
return;
|
|
1227
|
-
|
|
1321
|
+
let sql;
|
|
1322
|
+
if (this.hasDefinitionContainerDeletionFeature) {
|
|
1323
|
+
sql = `
|
|
1228
1324
|
SELECT 1
|
|
1229
1325
|
FROM bis.DefinitionPartition
|
|
1230
1326
|
WHERE ECInstanceId=:targetModelId
|
|
@@ -1233,6 +1329,14 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1233
1329
|
FROM bis.DefinitionContainer
|
|
1234
1330
|
WHERE ECInstanceId=:targetModelId
|
|
1235
1331
|
`;
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
sql = `
|
|
1335
|
+
SELECT 1
|
|
1336
|
+
FROM bis.DefinitionPartition
|
|
1337
|
+
WHERE ECInstanceId=:targetModelId
|
|
1338
|
+
`;
|
|
1339
|
+
}
|
|
1236
1340
|
if (this.exporter.sourceDbChanges?.element.deleteIds.has(sourceModelId)) {
|
|
1237
1341
|
// eslint-disable-next-line @itwin/no-internal, deprecation/deprecation
|
|
1238
1342
|
const isDefinitionPartition = this.targetDb.withPreparedStatement(sql, (stmt) => {
|
|
@@ -1534,7 +1638,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1534
1638
|
}
|
|
1535
1639
|
}
|
|
1536
1640
|
}
|
|
1537
|
-
_yieldManager = new core_bentley_1.YieldManager();
|
|
1538
1641
|
/** Detect Relationship deletes using ExternalSourceAspects in the target iModel and a *brute force* comparison against relationships in the source iModel.
|
|
1539
1642
|
* @deprecated in 1.x. Don't use this anymore
|
|
1540
1643
|
* @see [[process]] with [[IModelTransformOptions.argsForProcessChanges]] provided.
|
|
@@ -1647,8 +1750,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1647
1750
|
const targetElementAspectProps = this.context.cloneElementAspect(sourceElementAspect);
|
|
1648
1751
|
return targetElementAspectProps;
|
|
1649
1752
|
}
|
|
1650
|
-
/** The directory where schemas will be exported, a random temporary directory */
|
|
1651
|
-
_schemaExportDir = path.join(core_backend_1.KnownLocations.tmpdir, core_bentley_1.Guid.createValue());
|
|
1652
1753
|
/** Override of [IModelExportHandler.shouldExportSchema]($transformer) that is called to determine if a schema should be exported
|
|
1653
1754
|
* @note the default behavior doesn't import schemas older than those already in the target
|
|
1654
1755
|
*/
|
|
@@ -1658,7 +1759,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1658
1759
|
return true;
|
|
1659
1760
|
return Semver.gt(`${schemaKey.version.read}.${schemaKey.version.write}.${schemaKey.version.minor}`, core_backend_1.Schema.toSemverString(versionInTarget));
|
|
1660
1761
|
}
|
|
1661
|
-
_longNamedSchemasMap = new Map();
|
|
1662
1762
|
/** Override of [IModelExportHandler.onExportSchema]($transformer) that serializes a schema to disk for [[processSchemas]] to import into
|
|
1663
1763
|
* the target iModel when it is exported from the source iModel.
|
|
1664
1764
|
* @returns {Promise<ExportSchemaResult>} Although the type is possibly void for backwards compatibility of subclasses,
|
|
@@ -1687,11 +1787,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1687
1787
|
this._longNamedSchemasMap.set(schema.name, schemaFileName);
|
|
1688
1788
|
}
|
|
1689
1789
|
/* eslint-disable-next-line deprecation/deprecation */
|
|
1690
|
-
this.sourceDb.exportSchema(
|
|
1691
|
-
schemaName: schema.name,
|
|
1692
|
-
outputDirectory: this._schemaExportDir,
|
|
1693
|
-
outputFileName: schemaFileName,
|
|
1694
|
-
});
|
|
1790
|
+
this.sourceDb.nativeDb.exportSchema(schema.name, this._schemaExportDir, schemaFileName);
|
|
1695
1791
|
return { schemaPath: path.join(this._schemaExportDir, schemaFileName) };
|
|
1696
1792
|
}
|
|
1697
1793
|
_makeLongNameResolvingSchemaCtx() {
|
|
@@ -1777,11 +1873,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
1777
1873
|
this.completePartiallyCommittedElements();
|
|
1778
1874
|
this.completePartiallyCommittedAspects();
|
|
1779
1875
|
}
|
|
1780
|
-
/** state to prevent reinitialization, @see [[initialize]] */
|
|
1781
|
-
_initialized = false;
|
|
1782
|
-
_sourceChangeDataState = "uninited";
|
|
1783
|
-
/** length === 0 when _changeDataState = "no-change", length > 0 means "has-changes", otherwise undefined */
|
|
1784
|
-
_csFileProps = undefined;
|
|
1785
1876
|
/**
|
|
1786
1877
|
* Initialize prerequisites of processing, you must initialize with an [[InitOptions]] if you
|
|
1787
1878
|
* are intending to process changes. Callers may wish to explicitly call initialize if they need to execute code after initialize but before [[process]] is called.
|
|
@@ -2021,7 +2112,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
2021
2112
|
const endChangesetId = this.sourceDb.changeset.id;
|
|
2022
2113
|
const [startChangesetIndex, endChangesetIndex] = await Promise.all([startChangesetIndexOrId, endChangesetId].map(async (indexOrId) => typeof indexOrId === "number"
|
|
2023
2114
|
? indexOrId
|
|
2024
|
-
: core_backend_1.IModelHost
|
|
2115
|
+
: core_backend_1.IModelHost.hubAccess
|
|
2025
2116
|
.queryChangeset({
|
|
2026
2117
|
iModelId: this.sourceDb.iModelId,
|
|
2027
2118
|
// eslint-disable-next-line deprecation/deprecation
|
|
@@ -2053,7 +2144,7 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
2053
2144
|
const csFileProps = [];
|
|
2054
2145
|
for (const [first, end] of this._changesetRanges) {
|
|
2055
2146
|
// TODO: should the first changeset in a reverse sync really be included even though its 'initialized branch provenance'? The answer is no, its a bug that needs to be fixed.
|
|
2056
|
-
const fileProps = await core_backend_1.IModelHost
|
|
2147
|
+
const fileProps = await core_backend_1.IModelHost.hubAccess.downloadChangesets({
|
|
2057
2148
|
iModelId: this.sourceDb.iModelId,
|
|
2058
2149
|
targetDir: core_backend_1.BriefcaseManager.getChangeSetsPath(this.sourceDb.iModelId),
|
|
2059
2150
|
range: { first, end },
|
|
@@ -2126,8 +2217,6 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
2126
2217
|
this.importer.computeProjectExtents();
|
|
2127
2218
|
this.finalizeTransformation();
|
|
2128
2219
|
}
|
|
2129
|
-
/** previous provenance, either a federation guid, a `${sourceFedGuid}/${targetFedGuid}` pair, or required aspect props */
|
|
2130
|
-
_lastProvenanceEntityInfo = nullLastProvenanceEntityInfo;
|
|
2131
2220
|
markLastProvenance(sourceAspect, { isRelationship = false }) {
|
|
2132
2221
|
this._lastProvenanceEntityInfo =
|
|
2133
2222
|
typeof sourceAspect === "string"
|
|
@@ -2199,14 +2288,11 @@ class IModelTransformer extends IModelExporter_1.IModelExportHandler {
|
|
|
2199
2288
|
}
|
|
2200
2289
|
}
|
|
2201
2290
|
exports.IModelTransformer = IModelTransformer;
|
|
2291
|
+
IModelTransformer.noEsaSyncDirectionErrorMessage = "Couldn't find an external source aspect to determine sync direction. This often means that the master->branch relationship has not been established. Consider running the transformer with wasSourceIModelCopiedToTarget set to true.";
|
|
2202
2292
|
/** IModelTransformer that clones the contents of a template model.
|
|
2203
2293
|
* @beta
|
|
2204
2294
|
*/
|
|
2205
2295
|
class TemplateModelCloner extends IModelTransformer {
|
|
2206
|
-
/** The Placement to apply to the template. */
|
|
2207
|
-
_transform3d;
|
|
2208
|
-
/** Accumulates the mapping of sourceElementIds to targetElementIds from the elements in the template model that were cloned. */
|
|
2209
|
-
_sourceIdToTargetIdMap;
|
|
2210
2296
|
/** Construct a new TemplateModelCloner
|
|
2211
2297
|
* @param sourceDb The source IModelDb that contains the templates to clone
|
|
2212
2298
|
* @param targetDb Optionally specify the target IModelDb where the cloned template will be inserted.
|