@itwin/presentation-backend 4.0.0-dev.8 → 4.0.0-dev.80
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 +47 -1
- package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +5 -3
- package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +41 -41
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js +50 -50
- package/lib/cjs/presentation-backend/Constants.d.ts +8 -8
- package/lib/cjs/presentation-backend/Constants.js +40 -36
- package/lib/cjs/presentation-backend/Constants.js.map +1 -1
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +11 -11
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +260 -262
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.d.ts +87 -87
- package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.js +140 -140
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.d.ts +106 -106
- package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Presentation.js +148 -150
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +12 -12
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +41 -41
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +456 -445
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +309 -311
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +61 -61
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js +430 -430
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +62 -62
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +388 -388
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +102 -102
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +284 -279
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
- package/lib/cjs/presentation-backend/RulesetManager.d.ts +53 -53
- package/lib/cjs/presentation-backend/RulesetManager.js +73 -73
- package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +140 -140
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js +129 -129
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +28 -28
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js +210 -213
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +123 -123
- package/lib/cjs/presentation-backend/TemporaryStorage.js +151 -151
- package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +27 -27
- package/lib/cjs/presentation-backend/UpdatesTracker.js +54 -54
- package/lib/cjs/presentation-backend/Utils.d.ts +49 -49
- package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Utils.js +107 -106
- package/lib/cjs/presentation-backend/Utils.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +16 -16
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +55 -51
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -1
- package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +21 -21
- package/lib/cjs/presentation-backend/domain/RulesetElements.js +38 -38
- package/lib/cjs/presentation-backend.d.ts +19 -19
- package/lib/cjs/presentation-backend.js +39 -35
- package/lib/cjs/presentation-backend.js.map +1 -1
- package/package.json +18 -18
|
@@ -1,283 +1,288 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Core
|
|
8
|
-
*/
|
|
9
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
Object.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Core
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.RulesetEmbedder = void 0;
|
|
34
|
+
const path = __importStar(require("path"));
|
|
35
|
+
const semver_1 = require("semver");
|
|
36
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
37
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
38
|
+
const core_common_1 = require("@itwin/core-common");
|
|
39
|
+
const PresentationRulesDomain_1 = require("./domain/PresentationRulesDomain");
|
|
40
|
+
const RulesetElements = __importStar(require("./domain/RulesetElements"));
|
|
41
|
+
const Utils_1 = require("./Utils");
|
|
42
|
+
/**
|
|
43
|
+
* An API for embedding presentation rulesets into iModels.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
class RulesetEmbedder {
|
|
47
|
+
/**
|
|
48
|
+
* Constructs RulesetEmbedder
|
|
49
|
+
*/
|
|
50
|
+
constructor(props) {
|
|
51
|
+
this._schemaPath = path.join(core_backend_1.KnownLocations.nativeAssetsDir, "ECSchemas/Domain/PresentationRules.ecschema.xml");
|
|
52
|
+
this._rulesetModelName = "PresentationRules";
|
|
53
|
+
this._rulesetSubjectName = "PresentationRules";
|
|
54
|
+
PresentationRulesDomain_1.PresentationRules.registerSchema();
|
|
55
|
+
this._imodel = props.imodel;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Inserts a ruleset into iModel.
|
|
59
|
+
* @param ruleset Ruleset to insert.
|
|
60
|
+
* @param options Options for inserting a ruleset.
|
|
61
|
+
* @returns ID of inserted ruleset element or, if insertion was skipped, ID of existing ruleset with the same ID and highest version.
|
|
62
|
+
*/
|
|
63
|
+
async insertRuleset(ruleset, options) {
|
|
64
|
+
const normalizedOptions = normalizeRulesetInsertOptions(options);
|
|
65
|
+
const rulesetVersion = (0, Utils_1.normalizeVersion)(ruleset.version);
|
|
66
|
+
// ensure imodel has PresentationRules schema and required CodeSpecs
|
|
67
|
+
await this.handleElementOperationPrerequisites();
|
|
68
|
+
// find all rulesets with the same ID
|
|
69
|
+
const rulesetsWithSameId = [];
|
|
66
70
|
const query = `
|
|
67
71
|
SELECT ECInstanceId, JsonProperties
|
|
68
72
|
FROM ${RulesetElements.Ruleset.schema.name}.${RulesetElements.Ruleset.className}
|
|
69
|
-
WHERE json_extract(JsonProperties, '$.jsonProperties.id') = :rulesetId`;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
case "all
|
|
99
|
-
return normalizedVersion !== rulesetVersion
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
existingRulesetElement
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
//
|
|
231
|
-
this._imodel.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
73
|
+
WHERE json_extract(JsonProperties, '$.jsonProperties.id') = :rulesetId`;
|
|
74
|
+
const reader = this._imodel.createQueryReader(query, core_common_1.QueryBinder.from({ rulesetId: ruleset.id }), { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames });
|
|
75
|
+
while (await reader.step()) {
|
|
76
|
+
const row = reader.current.toRow();
|
|
77
|
+
const existingRulesetElementId = row.id;
|
|
78
|
+
const existingRuleset = JSON.parse(row.jsonProperties).jsonProperties;
|
|
79
|
+
rulesetsWithSameId.push({
|
|
80
|
+
id: existingRulesetElementId,
|
|
81
|
+
ruleset: existingRuleset,
|
|
82
|
+
normalizedVersion: (0, Utils_1.normalizeVersion)(existingRuleset.version),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// check if we need to do anything at all
|
|
86
|
+
const shouldSkip = normalizedOptions.skip === "same-id" && rulesetsWithSameId.length > 0
|
|
87
|
+
|| normalizedOptions.skip === "same-id-and-version-eq" && rulesetsWithSameId.some((entry) => entry.normalizedVersion === rulesetVersion)
|
|
88
|
+
|| normalizedOptions.skip === "same-id-and-version-gte" && rulesetsWithSameId.some((entry) => (0, semver_1.gte)(entry.normalizedVersion, rulesetVersion));
|
|
89
|
+
if (shouldSkip) {
|
|
90
|
+
// we're not inserting anything - return ID of the ruleset element with the highest version
|
|
91
|
+
const rulesetEntryWithHighestVersion = rulesetsWithSameId.reduce((highest, curr) => {
|
|
92
|
+
if (!highest.ruleset.version || curr.ruleset.version && (0, semver_1.gt)(curr.ruleset.version, highest.ruleset.version))
|
|
93
|
+
return curr;
|
|
94
|
+
return highest;
|
|
95
|
+
}, rulesetsWithSameId[0]);
|
|
96
|
+
return rulesetEntryWithHighestVersion.id;
|
|
97
|
+
}
|
|
98
|
+
// if requested, delete existing rulesets
|
|
99
|
+
const rulesetsToRemove = [];
|
|
100
|
+
const shouldRemove = (_, normalizedVersion) => {
|
|
101
|
+
switch (normalizedOptions.replaceVersions) {
|
|
102
|
+
case "all":
|
|
103
|
+
return normalizedVersion !== rulesetVersion;
|
|
104
|
+
case "all-lower":
|
|
105
|
+
return normalizedVersion !== rulesetVersion && (0, semver_1.lt)(normalizedVersion, rulesetVersion);
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
};
|
|
109
|
+
rulesetsWithSameId.forEach((entry) => {
|
|
110
|
+
if (shouldRemove(entry.ruleset, entry.normalizedVersion))
|
|
111
|
+
rulesetsToRemove.push(entry.id);
|
|
112
|
+
});
|
|
113
|
+
this._imodel.elements.deleteElement(rulesetsToRemove);
|
|
114
|
+
// attempt to update ruleset with same ID and version
|
|
115
|
+
const exactMatch = rulesetsWithSameId.find((curr) => curr.normalizedVersion === rulesetVersion);
|
|
116
|
+
if (exactMatch !== undefined) {
|
|
117
|
+
return this.updateRuleset(exactMatch.id, ruleset, normalizedOptions.onEntityUpdate);
|
|
118
|
+
}
|
|
119
|
+
// no exact match found - insert a new ruleset element
|
|
120
|
+
const model = await this.getOrCreateRulesetModel(normalizedOptions.onEntityInsert);
|
|
121
|
+
const rulesetCode = RulesetElements.Ruleset.createRulesetCode(this._imodel, model.id, ruleset);
|
|
122
|
+
return this.insertNewRuleset(ruleset, model, rulesetCode, normalizedOptions.onEntityInsert);
|
|
123
|
+
}
|
|
124
|
+
async updateRuleset(elementId, ruleset, callbacks) {
|
|
125
|
+
const existingRulesetElement = this._imodel.elements.tryGetElement(elementId);
|
|
126
|
+
(0, core_bentley_1.assert)(existingRulesetElement !== undefined);
|
|
127
|
+
existingRulesetElement.jsonProperties.jsonProperties = ruleset;
|
|
128
|
+
await this.updateElement(existingRulesetElement, callbacks);
|
|
129
|
+
this._imodel.saveChanges();
|
|
130
|
+
return existingRulesetElement.id;
|
|
131
|
+
}
|
|
132
|
+
async insertNewRuleset(ruleset, model, rulesetCode, callbacks) {
|
|
133
|
+
const props = {
|
|
134
|
+
model: model.id,
|
|
135
|
+
code: rulesetCode,
|
|
136
|
+
classFullName: RulesetElements.Ruleset.classFullName,
|
|
137
|
+
jsonProperties: { jsonProperties: ruleset },
|
|
138
|
+
};
|
|
139
|
+
const element = await this.insertElement(props, callbacks);
|
|
140
|
+
this._imodel.saveChanges();
|
|
141
|
+
return element.id;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get all rulesets embedded in the iModel.
|
|
145
|
+
*/
|
|
146
|
+
async getRulesets() {
|
|
147
|
+
if (!this._imodel.containsClass(RulesetElements.Ruleset.classFullName))
|
|
148
|
+
return [];
|
|
149
|
+
const rulesetList = [];
|
|
150
|
+
this._imodel.withPreparedStatement(`SELECT ECInstanceId AS id FROM ${RulesetElements.Ruleset.classFullName}`, (statement) => {
|
|
151
|
+
while (core_bentley_1.DbResult.BE_SQLITE_ROW === statement.step()) {
|
|
152
|
+
const row = statement.getRow();
|
|
153
|
+
const rulesetElement = this._imodel.elements.getElement({ id: row.id });
|
|
154
|
+
const ruleset = rulesetElement.jsonProperties.jsonProperties;
|
|
155
|
+
rulesetList.push(ruleset);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return rulesetList;
|
|
159
|
+
}
|
|
160
|
+
async getOrCreateRulesetModel(callbacks) {
|
|
161
|
+
const rulesetModel = this.queryRulesetModel();
|
|
162
|
+
if (undefined !== rulesetModel)
|
|
163
|
+
return rulesetModel;
|
|
164
|
+
const rulesetSubject = await this.insertSubject(callbacks);
|
|
165
|
+
const definitionPartition = await this.insertDefinitionPartition(rulesetSubject, callbacks);
|
|
166
|
+
return this.insertDefinitionModel(definitionPartition, callbacks);
|
|
167
|
+
}
|
|
168
|
+
queryRulesetModel() {
|
|
169
|
+
const definitionPartition = this.queryDefinitionPartition();
|
|
170
|
+
if (undefined === definitionPartition)
|
|
171
|
+
return undefined;
|
|
172
|
+
return this._imodel.models.getSubModel(definitionPartition.id);
|
|
173
|
+
}
|
|
174
|
+
queryDefinitionPartition() {
|
|
175
|
+
const subject = this.querySubject();
|
|
176
|
+
if (undefined === subject)
|
|
177
|
+
return undefined;
|
|
178
|
+
return this._imodel.elements.tryGetElement(core_backend_1.DefinitionPartition.createCode(this._imodel, subject.id, this._rulesetModelName));
|
|
179
|
+
}
|
|
180
|
+
querySubject() {
|
|
181
|
+
const root = this._imodel.elements.getRootSubject();
|
|
182
|
+
const codeSpec = this._imodel.codeSpecs.getByName(core_common_1.BisCodeSpec.subject);
|
|
183
|
+
const code = new core_common_1.Code({
|
|
184
|
+
spec: codeSpec.id,
|
|
185
|
+
scope: root.id,
|
|
186
|
+
value: this._rulesetSubjectName,
|
|
187
|
+
});
|
|
188
|
+
return this._imodel.elements.tryGetElement(code);
|
|
189
|
+
}
|
|
190
|
+
async insertDefinitionModel(definitionPartition, callbacks) {
|
|
191
|
+
const modelProps = {
|
|
192
|
+
modeledElement: definitionPartition,
|
|
193
|
+
name: this._rulesetModelName,
|
|
194
|
+
classFullName: core_backend_1.DefinitionModel.classFullName,
|
|
195
|
+
isPrivate: true,
|
|
196
|
+
};
|
|
197
|
+
return this.insertModel(modelProps, callbacks);
|
|
198
|
+
}
|
|
199
|
+
async insertDefinitionPartition(rulesetSubject, callbacks) {
|
|
200
|
+
const partitionCode = core_backend_1.DefinitionPartition.createCode(this._imodel, rulesetSubject.id, this._rulesetModelName);
|
|
201
|
+
const definitionPartitionProps = {
|
|
202
|
+
parent: {
|
|
203
|
+
id: rulesetSubject.id,
|
|
204
|
+
relClassName: "BisCore:SubjectOwnsPartitionElements",
|
|
205
|
+
},
|
|
206
|
+
model: rulesetSubject.model,
|
|
207
|
+
code: partitionCode,
|
|
208
|
+
classFullName: core_backend_1.DefinitionPartition.classFullName,
|
|
209
|
+
};
|
|
210
|
+
return this.insertElement(definitionPartitionProps, callbacks);
|
|
211
|
+
}
|
|
212
|
+
async insertSubject(callbacks) {
|
|
213
|
+
const root = this._imodel.elements.getRootSubject();
|
|
214
|
+
const codeSpec = this._imodel.codeSpecs.getByName(core_common_1.BisCodeSpec.subject);
|
|
215
|
+
const subjectCode = new core_common_1.Code({
|
|
216
|
+
spec: codeSpec.id,
|
|
217
|
+
scope: root.id,
|
|
218
|
+
value: this._rulesetSubjectName,
|
|
219
|
+
});
|
|
220
|
+
const subjectProps = {
|
|
221
|
+
classFullName: core_backend_1.Subject.classFullName,
|
|
222
|
+
model: root.model,
|
|
223
|
+
parent: {
|
|
224
|
+
id: root.id,
|
|
225
|
+
relClassName: "BisCore:SubjectOwnsSubjects",
|
|
226
|
+
},
|
|
227
|
+
code: subjectCode,
|
|
228
|
+
};
|
|
229
|
+
return this.insertElement(subjectProps, callbacks);
|
|
230
|
+
}
|
|
231
|
+
async handleElementOperationPrerequisites() {
|
|
232
|
+
if (this._imodel.containsClass(RulesetElements.Ruleset.classFullName))
|
|
233
|
+
return;
|
|
234
|
+
// import PresentationRules ECSchema
|
|
235
|
+
await this._imodel.importSchemas([this._schemaPath]);
|
|
236
|
+
// insert CodeSpec for ruleset elements
|
|
237
|
+
this._imodel.codeSpecs.insert(core_common_1.CodeSpec.create(this._imodel, PresentationRulesDomain_1.PresentationRules.CodeSpec.Ruleset, core_common_1.CodeScopeSpec.Type.Model));
|
|
238
|
+
this._imodel.saveChanges();
|
|
239
|
+
}
|
|
240
|
+
async insertElement(props, callbacks) {
|
|
241
|
+
const element = this._imodel.elements.createElement(props);
|
|
242
|
+
// istanbul ignore next
|
|
243
|
+
await callbacks?.onBeforeInsert(element);
|
|
244
|
+
try {
|
|
245
|
+
return this._imodel.elements.getElement(element.insert());
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
// istanbul ignore next
|
|
249
|
+
await callbacks?.onAfterInsert(element);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async insertModel(props, callbacks) {
|
|
253
|
+
const model = this._imodel.models.createModel(props);
|
|
254
|
+
// istanbul ignore next
|
|
255
|
+
await callbacks?.onBeforeInsert(model);
|
|
256
|
+
try {
|
|
257
|
+
model.id = model.insert();
|
|
258
|
+
return model;
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
// istanbul ignore next
|
|
262
|
+
await callbacks?.onAfterInsert(model);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async updateElement(element, callbacks) {
|
|
266
|
+
// istanbul ignore next
|
|
267
|
+
await callbacks?.onBeforeUpdate(element);
|
|
268
|
+
try {
|
|
269
|
+
element.update();
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
// istanbul ignore next
|
|
273
|
+
await callbacks?.onAfterUpdate(element);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.RulesetEmbedder = RulesetEmbedder;
|
|
278
|
+
function normalizeRulesetInsertOptions(options) {
|
|
279
|
+
if (options === undefined)
|
|
280
|
+
return { skip: "same-id-and-version-eq", replaceVersions: "exact" };
|
|
281
|
+
return {
|
|
282
|
+
skip: options.skip ?? "same-id-and-version-eq",
|
|
283
|
+
replaceVersions: options.replaceVersions ?? "exact",
|
|
284
|
+
onEntityUpdate: options.onEntityUpdate,
|
|
285
|
+
onEntityInsert: options.onEntityInsert,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
283
288
|
//# sourceMappingURL=RulesetEmbedder.js.map
|