@itwin/grouping-mapping-widget 0.8.2 → 0.9.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.
Files changed (47) hide show
  1. package/lib/cjs/test/GroupPropertyUtils.test.d.ts +2 -0
  2. package/lib/cjs/test/GroupPropertyUtils.test.js +590 -0
  3. package/lib/cjs/test/GroupPropertyUtils.test.js.map +1 -0
  4. package/lib/cjs/test/MockFactory.d.ts +9 -0
  5. package/lib/cjs/test/MockFactory.js +42 -0
  6. package/lib/cjs/test/MockFactory.js.map +1 -0
  7. package/lib/cjs/test/PropertyFieldsHelpers.d.ts +86 -0
  8. package/lib/cjs/test/PropertyFieldsHelpers.js +80 -0
  9. package/lib/cjs/test/PropertyFieldsHelpers.js.map +1 -0
  10. package/lib/cjs/test/QueryBuilder.test.d.ts +2 -0
  11. package/lib/cjs/test/QueryBuilder.test.js +53 -0
  12. package/lib/cjs/test/QueryBuilder.test.js.map +1 -0
  13. package/lib/cjs/test/QueryBuilder.testdata.d.ts +3 -0
  14. package/lib/cjs/test/QueryBuilder.testdata.js +843 -0
  15. package/lib/cjs/test/QueryBuilder.testdata.js.map +1 -0
  16. package/lib/cjs/test/QueryBuilderTestData.d.ts +50 -0
  17. package/lib/cjs/test/QueryBuilderTestData.js +3 -0
  18. package/lib/cjs/test/QueryBuilderTestData.js.map +1 -0
  19. package/lib/cjs/widget/components/GroupPropertyUtils.js +7 -3
  20. package/lib/cjs/widget/components/GroupPropertyUtils.js.map +1 -1
  21. package/lib/cjs/widget/components/QueryBuilder.d.ts +11 -9
  22. package/lib/cjs/widget/components/QueryBuilder.js +91 -216
  23. package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
  24. package/lib/esm/test/GroupPropertyUtils.test.d.ts +2 -0
  25. package/lib/esm/test/GroupPropertyUtils.test.js +588 -0
  26. package/lib/esm/test/GroupPropertyUtils.test.js.map +1 -0
  27. package/lib/esm/test/MockFactory.d.ts +9 -0
  28. package/lib/esm/test/MockFactory.js +19 -0
  29. package/lib/esm/test/MockFactory.js.map +1 -0
  30. package/lib/esm/test/PropertyFieldsHelpers.d.ts +86 -0
  31. package/lib/esm/test/PropertyFieldsHelpers.js +69 -0
  32. package/lib/esm/test/PropertyFieldsHelpers.js.map +1 -0
  33. package/lib/esm/test/QueryBuilder.test.d.ts +2 -0
  34. package/lib/esm/test/QueryBuilder.test.js +51 -0
  35. package/lib/esm/test/QueryBuilder.test.js.map +1 -0
  36. package/lib/esm/test/QueryBuilder.testdata.d.ts +3 -0
  37. package/lib/esm/test/QueryBuilder.testdata.js +840 -0
  38. package/lib/esm/test/QueryBuilder.testdata.js.map +1 -0
  39. package/lib/esm/test/QueryBuilderTestData.d.ts +50 -0
  40. package/lib/esm/test/QueryBuilderTestData.js +2 -0
  41. package/lib/esm/test/QueryBuilderTestData.js.map +1 -0
  42. package/lib/esm/widget/components/GroupPropertyUtils.js +7 -3
  43. package/lib/esm/widget/components/GroupPropertyUtils.js.map +1 -1
  44. package/lib/esm/widget/components/QueryBuilder.d.ts +11 -9
  45. package/lib/esm/widget/components/QueryBuilder.js +91 -216
  46. package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
  47. package/package.json +32 -28
@@ -6,6 +6,16 @@ export class QueryBuilder {
6
6
  *
7
7
  */
8
8
  constructor(provider) {
9
+ this.addRelatedPropertyToQuery = (unionIndex, isAspect) => (className, propertyName, propertyValue, needsQuote) => this.addPropertyToQuery(unionIndex, className, propertyName, propertyValue, isAspect, needsQuote, false, true);
10
+ this.whereSegment = (baseClass, baseClassName) => {
11
+ const segments = [];
12
+ const properties = baseClass.properties;
13
+ for (let i = 0; i < properties.length; i++) {
14
+ const prefix = i === 0 ? "WHERE" : "AND";
15
+ segments.push(this.propertySegment(baseClassName, properties[i], prefix));
16
+ }
17
+ return segments.join("");
18
+ };
9
19
  this.dataProvider = provider;
10
20
  }
11
21
  isCategory(propertyField) {
@@ -66,12 +76,12 @@ export class QueryBuilder {
66
76
  this.addRelatedProperty(i, propertyField, propertyName, propertyValue, isAspect);
67
77
  }
68
78
  else {
69
- this.addPropertyToQuery(i, className, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), isCategory, false);
79
+ this.addPropertyToQuery(i, className, propertyName, propertyValue, isAspect, this.needsQuote(propertyField), isCategory, false);
70
80
  }
71
81
  }
72
82
  return true;
73
83
  }
74
- _needsQuote(propertyField) {
84
+ needsQuote(propertyField) {
75
85
  // list of property types that need quote around property value
76
86
  if (propertyField.type.typeName.toLowerCase() === "string") {
77
87
  return true;
@@ -83,77 +93,49 @@ export class QueryBuilder {
83
93
  }
84
94
  addRelatedProperty(unionIndex, propertyField, propertyName, propertyValue, isAspect) {
85
95
  var _a, _b;
96
+ const addProperty = this.addRelatedPropertyToQuery(unionIndex, isAspect);
86
97
  const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
87
98
  paths.reverse().forEach((path) => {
88
- var _a, _b, _c, _d, _e, _f, _g;
99
+ var _a, _b, _c, _d, _e;
89
100
  const sourceClassName = (_a = path.sourceClassInfo) === null || _a === void 0 ? void 0 : _a.name.replace(":", ".");
90
101
  const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
91
102
  const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
92
- if (!path.isForwardRelationship) {
93
- this.addPropertyToQuery(unionIndex, targetClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, false, true);
94
- this.addPropertyToQuery(unionIndex, relClassName, `TargetECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, false, true);
95
- if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
96
- ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
97
- this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), false, true);
98
- }
99
- else {
100
- this.addPropertyToQuery(unionIndex, sourceClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, false, true);
101
- }
102
- }
103
- else {
104
- this.addPropertyToQuery(unionIndex, targetClassName, `ECInstanceId`, `${relClassName}.TargetECInstanceId`, isAspect, false, false, true);
105
- this.addPropertyToQuery(unionIndex, relClassName, `SourceECInstanceId`, `${sourceClassName}.ECInstanceId`, isAspect, false, false, true);
106
- if (((_f = path.sourceClassInfo) === null || _f === void 0 ? void 0 : _f.name) ===
107
- ((_g = propertyField.parent) === null || _g === void 0 ? void 0 : _g.contentClassInfo.name)) {
108
- this.addPropertyToQuery(unionIndex, sourceClassName, propertyName, propertyValue, isAspect, this._needsQuote(propertyField), false, true);
109
- }
110
- else {
111
- this.addPropertyToQuery(unionIndex, sourceClassName, `ECInstanceId`, `${relClassName}.SourceECInstanceId`, isAspect, false, false, true);
112
- }
103
+ const relPropertyName = path.isForwardRelationship
104
+ ? `SourceECInstanceId`
105
+ : `TargetECInstanceId`;
106
+ const relPropertyValue = path.isForwardRelationship
107
+ ? `${relClassName}.TargetECInstanceId`
108
+ : `${relClassName}.SourceECInstanceId`;
109
+ addProperty(targetClassName, `ECInstanceId`, relPropertyValue, false);
110
+ addProperty(relClassName, relPropertyName, `${sourceClassName}.ECInstanceId`, false);
111
+ if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name)
112
+ === ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
113
+ addProperty(sourceClassName, propertyName, propertyValue, this.needsQuote(propertyField));
113
114
  }
114
115
  });
115
116
  }
116
117
  addPropertyToQuery(unionIndex, className, propertyName, propertyValue, isAspect, needsQuote, isCategory, isRelational) {
117
118
  if (this.query === undefined || this.query.unions.length === 0) {
118
- this.query = {
119
- unions: [
120
- {
121
- classes: [
122
- {
123
- className,
124
- isAspect,
125
- isRelational,
126
- properties: [
127
- {
128
- name: propertyName,
129
- value: propertyValue,
130
- needsQuote,
131
- isCategory,
132
- },
133
- ],
134
- },
135
- ],
136
- },
137
- ],
138
- };
139
- return;
119
+ this.query = { unions: [] };
140
120
  }
121
+ const queryProperty = {
122
+ name: propertyName,
123
+ value: propertyValue,
124
+ needsQuote,
125
+ isCategory,
126
+ };
127
+ const queryClass = {
128
+ className,
129
+ isAspect,
130
+ isRelational,
131
+ properties: [
132
+ queryProperty,
133
+ ],
134
+ };
141
135
  if (this.query.unions.length <= unionIndex) {
142
136
  this.query.unions.push({
143
137
  classes: [
144
- {
145
- className,
146
- isAspect,
147
- isRelational,
148
- properties: [
149
- {
150
- name: propertyName,
151
- value: propertyValue,
152
- needsQuote,
153
- isCategory,
154
- },
155
- ],
156
- },
138
+ queryClass,
157
139
  ],
158
140
  });
159
141
  return;
@@ -162,28 +144,11 @@ export class QueryBuilder {
162
144
  if (foundClass) {
163
145
  foundClass.isRelational = isRelational;
164
146
  if (!foundClass.properties.find((x) => x.name === propertyName)) {
165
- foundClass.properties.push({
166
- name: propertyName,
167
- value: propertyValue,
168
- needsQuote,
169
- isCategory,
170
- });
147
+ foundClass.properties.push(queryProperty);
171
148
  }
172
149
  }
173
150
  else {
174
- this.query.unions[unionIndex].classes.push({
175
- className,
176
- isRelational,
177
- properties: [
178
- {
179
- name: propertyName,
180
- value: propertyValue,
181
- needsQuote,
182
- isCategory,
183
- },
184
- ],
185
- isAspect,
186
- });
151
+ this.query.unions[unionIndex].classes.push(queryClass);
187
152
  }
188
153
  }
189
154
  async removeProperty(prop) {
@@ -229,31 +194,16 @@ export class QueryBuilder {
229
194
  var _a, _b;
230
195
  const paths = [...((_b = (_a = propertyField.parent) === null || _a === void 0 ? void 0 : _a.pathToPrimaryClass) !== null && _b !== void 0 ? _b : [])];
231
196
  paths.reverse().forEach((path) => {
232
- var _a, _b, _c, _d, _e, _f, _g;
197
+ var _a, _b, _c, _d, _e;
233
198
  const sourceClassName = (_a = path.sourceClassInfo) === null || _a === void 0 ? void 0 : _a.name.replace(":", ".");
234
199
  const targetClassName = (_b = path.targetClassInfo) === null || _b === void 0 ? void 0 : _b.name.replace(":", ".");
235
200
  const relClassName = (_c = path.relationshipInfo) === null || _c === void 0 ? void 0 : _c.name.replace(":", ".");
236
- if (!path.isForwardRelationship) {
237
- this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
238
- this.removePropertyFromQuery(unionIndex, relClassName, `TargetECInstanceId`);
239
- if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
240
- ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
241
- this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
242
- }
243
- else {
244
- this.removePropertyFromQuery(unionIndex, sourceClassName, `ECInstanceId`);
245
- }
246
- }
247
- else {
248
- this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
249
- this.removePropertyFromQuery(unionIndex, relClassName, `SourceECInstanceId`);
250
- if (((_f = path.sourceClassInfo) === null || _f === void 0 ? void 0 : _f.name) ===
251
- ((_g = propertyField.parent) === null || _g === void 0 ? void 0 : _g.contentClassInfo.name)) {
252
- this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
253
- }
254
- else {
255
- this.removePropertyFromQuery(unionIndex, sourceClassName, `ECInstanceId`);
256
- }
201
+ this.removePropertyFromQuery(unionIndex, targetClassName, `ECInstanceId`);
202
+ const relPropertyName = path.isForwardRelationship ? `SourceECInstanceId` : `TargetECInstanceId`;
203
+ this.removePropertyFromQuery(unionIndex, relClassName, relPropertyName);
204
+ if (((_d = path.sourceClassInfo) === null || _d === void 0 ? void 0 : _d.name) ===
205
+ ((_e = propertyField.parent) === null || _e === void 0 ? void 0 : _e.contentClassInfo.name)) {
206
+ this.removePropertyFromQuery(unionIndex, sourceClassName, propertyName);
257
207
  }
258
208
  });
259
209
  }
@@ -274,23 +224,22 @@ export class QueryBuilder {
274
224
  }
275
225
  }
276
226
  }
277
- categoryQuery(codeValue) {
278
- return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;
279
- }
280
227
  buildQueryString() {
281
228
  if (this.query === undefined ||
282
229
  this.query.unions.length === 0 ||
283
230
  this.query.unions[0].classes.length === 0) {
284
231
  return "";
285
232
  }
286
- let unionQuery = "";
233
+ const unionSegments = [];
287
234
  for (const union of this.query.unions) {
235
+ const querySegments = [];
288
236
  const baseClass = union.classes[0];
289
237
  const baseClassName = baseClass.className;
290
238
  const baseIdName = baseClass.isAspect
291
239
  ? `${baseClassName}.Element.id`
292
240
  : `${baseClassName}.ECInstanceId`;
293
- let queryString = `SELECT ${baseIdName}${baseClass.isAspect ? " ECInstanceId" : ""} FROM ${baseClassName}`;
241
+ const selectSegment = `SELECT ${baseIdName}${baseClass.isAspect ? " ECInstanceId" : ""} FROM ${baseClassName}`;
242
+ querySegments.push(selectSegment);
294
243
  if (union.classes.length > 1) {
295
244
  for (let i = 1; i < union.classes.length; i++) {
296
245
  const joinClass = union.classes[i];
@@ -298,127 +247,53 @@ export class QueryBuilder {
298
247
  const joinIdName = joinClass.isAspect
299
248
  ? `${joinClassName}.Element.id`
300
249
  : `${joinClassName}.ECInstanceId`;
301
- if (joinClass.isRelational) {
302
- queryString += ` JOIN ${joinClassName}`;
303
- if (joinClass.properties.length > 0) {
304
- if (joinClass.properties[0].isCategory) {
305
- queryString += this.categoryQuery(joinClass.properties[0].value.toString());
306
- }
307
- else {
308
- if (joinClass.properties[0].needsQuote) {
309
- queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;
310
- }
311
- else {
312
- if (this._isFloat(joinClass.properties[0].value)) {
313
- queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;
314
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
315
- queryString += `${Number(joinClass.properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
316
- }
317
- else {
318
- queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;
319
- }
320
- }
321
- }
322
- }
323
- // when base is regular property, link base to first joined relational property
324
- if (!baseClass.isRelational && i === 1) {
325
- queryString += ` AND ${joinIdName} = ${baseIdName}`;
326
- }
327
- for (const property of joinClass.properties) {
328
- if (property.isCategory) {
329
- queryString += this.categoryQuery(property.value.toString());
330
- }
331
- else {
332
- if (property.needsQuote) {
333
- queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
334
- }
335
- else {
336
- if (this._isFloat(property.value)) {
337
- queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
338
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
339
- queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
340
- }
341
- else {
342
- queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
343
- }
344
- }
345
- }
346
- }
250
+ const joinSegment = joinClass.isRelational
251
+ ? ` JOIN ${joinClassName}`
252
+ : ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
253
+ querySegments.push(joinSegment);
254
+ for (let j = 0; j < joinClass.properties.length; j++) {
255
+ const prefix = j === 0 && joinClass.isRelational ? "ON" : "AND";
256
+ const propertySegment = this.propertySegment(joinClassName, joinClass.properties[j], prefix);
257
+ querySegments.push(propertySegment);
347
258
  }
348
- else {
349
- queryString += ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;
350
- for (const property of joinClass.properties) {
351
- if (property.isCategory) {
352
- queryString += this.categoryQuery(property.value.toString());
353
- }
354
- else {
355
- if (property.needsQuote) {
356
- queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;
357
- }
358
- else {
359
- if (this._isFloat(property.value)) {
360
- queryString += ` AND ROUND(${joinClassName}.${property.name}, `;
361
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
362
- queryString += `${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
363
- }
364
- else {
365
- queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;
366
- }
367
- }
368
- }
369
- }
259
+ // when base is regular property, link base to first joined relational property
260
+ if (joinClass.isRelational && !baseClass.isRelational && i === 1) {
261
+ querySegments.push(` AND ${joinIdName} = ${baseIdName}`);
370
262
  }
371
263
  }
372
264
  }
373
- const properties = baseClass.properties;
374
- if (properties.length > 0) {
375
- if (properties[0].isCategory) {
376
- queryString += this.categoryQuery(properties[0].value.toString());
265
+ const whereSegment = this.whereSegment(baseClass, baseClassName);
266
+ querySegments.push(whereSegment);
267
+ unionSegments.push(querySegments.join(""));
268
+ }
269
+ return unionSegments.join(" UNION ");
270
+ }
271
+ propertySegment(className, property, prefix) {
272
+ const segments = [];
273
+ if (property.isCategory) {
274
+ segments.push(this.categoryQuery(property.value.toString()));
275
+ }
276
+ else {
277
+ if (property.needsQuote) {
278
+ segments.push(` ${prefix} ${className}.${property.name}='${property.value}'`);
279
+ }
280
+ else {
281
+ if (this.isFloat(property.value)) {
282
+ segments.push(` ${prefix} ROUND(${className}.${property.name}, `);
283
+ segments.push(`${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`);
284
+ segments.push(`${Number(property.value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`);
377
285
  }
378
286
  else {
379
- if (properties[0].needsQuote) {
380
- queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;
381
- }
382
- else {
383
- if (this._isFloat(properties[0].value)) {
384
- queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;
385
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
386
- queryString += `${Number(properties[0].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
387
- }
388
- else {
389
- queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;
390
- }
391
- }
392
- }
393
- if (properties.length > 1) {
394
- for (let i = 1; i < properties.length; i++) {
395
- if (properties[i].isCategory) {
396
- queryString += this.categoryQuery(properties[i].value.toString());
397
- }
398
- else {
399
- if (properties[i].needsQuote) {
400
- queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;
401
- }
402
- else {
403
- if (this._isFloat(properties[i].value)) {
404
- queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;
405
- queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;
406
- queryString += `${Number(properties[i].value).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;
407
- }
408
- else {
409
- queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;
410
- }
411
- }
412
- }
413
- }
287
+ segments.push(` ${prefix} ${className}.${property.name}=${property.value}`);
414
288
  }
415
289
  }
416
- unionQuery += `${queryString} UNION `;
417
290
  }
418
- unionQuery = unionQuery.slice(0, unionQuery.length - 7);
419
- return unionQuery;
291
+ return segments.join("");
292
+ }
293
+ categoryQuery(codeValue) {
294
+ return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;
420
295
  }
421
- _isFloat(n) {
296
+ isFloat(n) {
422
297
  return Number(n) === n && n % 1 !== 0;
423
298
  }
424
299
  }
@@ -1 +1 @@
1
- {"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../src/widget/components/QueryBuilder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAyB/C,4FAA4F;AAC5F,MAAM,OAAO,YAAY;IAUvB;;OAEG;IACH,YAAY,QAAsD;QAChE,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAEM,UAAU,CAAC,aAA8B;;QAC9C,M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AAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AA5mBsB,uCAA0B,GAC/C,iCAAiC,CAAC;AACb,wCAA2B,GAChD,iCAAiC,CAAC;AACb,qCAAwB,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type {\n InstanceKey,\n PropertiesField,\n} from \"@itwin/presentation-common\";\nimport type { Primitives, PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { toaster } from \"@itwin/itwinui-react\";\n\nexport interface Query {\n unions: QueryUnion[];\n}\n\nexport interface QueryUnion {\n classes: QueryClass[];\n}\n\nexport interface QueryClass {\n // schemaName.className\n className: string;\n properties: QueryProperty[];\n isAspect: boolean;\n isRelational?: boolean;\n}\n\nexport interface QueryProperty {\n name: string;\n value: Primitives.Value;\n needsQuote: boolean;\n isCategory: boolean;\n}\n\n/* This class is to build adaptive and dynamic query for find similar property selections */\nexport class QueryBuilder {\n public static readonly MULTI_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsMultiAspects\";\n public static readonly UNIQUE_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsUniqueAspect\";\n public static readonly DEFAULT_DOUBLE_PRECISION = 4;\n\n public dataProvider: PresentationPropertyDataProvider | undefined;\n public query: Query | undefined;\n\n /**\n *\n */\n constructor(provider: PresentationPropertyDataProvider | undefined) {\n this.dataProvider = provider;\n }\n\n public isCategory(propertyField: PropertiesField): boolean {\n const classInfo =\n propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n public async addProperty(prop: PropertyRecord): Promise<boolean> {\n // TODO: only handle primitive properties now\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive) {\n toaster.warning(\"Only primitive types are supported for now.\");\n return false;\n }\n if (prop.value.value === undefined) {\n return false;\n }\n\n function replaceAll(str: string, match: string, replacement: string) {\n return str.split(match).join(replacement);\n }\n // if property value has single quote, escape\n if (\n (typeof prop.value.value === \"string\" ||\n prop.value.value instanceof String) &&\n String(prop.value.value).indexOf(\"'\") >= 0\n ) {\n prop.value.value = replaceAll(prop.value.value.toString(), \"'\", \"''\");\n }\n\n // get descriptor\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n\n if (!descriptor || !propertyField) {\n toaster.negative(\n \"Error. Failed to fetch field for this property record.\",\n );\n return false;\n }\n\n // get the special cases\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const className = propertyField.properties[\n i\n ].property.classInfo.name.replace(\":\", \".\");\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const propertyValue = isNavigation\n ? isCategory\n ? prop.value.displayValue ?? \"\"\n : (prop.value.value as InstanceKey).id\n : prop.value.value;\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.addRelatedProperty(\n i,\n propertyField,\n propertyName,\n propertyValue,\n isAspect,\n );\n } else {\n this.addPropertyToQuery(\n i,\n className,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n isCategory,\n false,\n );\n }\n }\n return true;\n }\n\n private _needsQuote(propertyField: PropertiesField): boolean {\n // list of property types that need quote around property value\n if (propertyField.type.typeName.toLowerCase() === \"string\") {\n return true;\n }\n if (propertyField.type.typeName.toLowerCase() === \"uri\") {\n return true;\n }\n return false;\n }\n\n public addRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n ) {\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n if (!path.isForwardRelationship) {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n } else {\n this.addPropertyToQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n `${relClassName}.TargetECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n this.addPropertyToQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n `${sourceClassName}.ECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n propertyValue,\n isAspect,\n this._needsQuote(propertyField),\n false,\n true,\n );\n } else {\n this.addPropertyToQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n `${relClassName}.SourceECInstanceId`,\n isAspect,\n false,\n false,\n true,\n );\n }\n }\n });\n }\n\n public addPropertyToQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n needsQuote: boolean,\n isCategory: boolean,\n isRelational?: boolean,\n ) {\n if (this.query === undefined || this.query.unions.length === 0) {\n this.query = {\n unions: [\n {\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\n ],\n },\n ],\n };\n return;\n }\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [\n {\n className,\n isAspect,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n },\n ],\n });\n return;\n }\n\n const foundClass = this.query.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n foundClass.isRelational = isRelational;\n if (!foundClass.properties.find((x) => x.name === propertyName)) {\n foundClass.properties.push({\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n });\n }\n } else {\n this.query.unions[unionIndex].classes.push({\n className,\n isRelational,\n properties: [\n {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n },\n ],\n isAspect,\n });\n }\n }\n\n public async removeProperty(prop: PropertyRecord) {\n if (this.query === undefined || this.query.unions.length === 0) {\n return;\n }\n if (\n this.query.unions.length === 1 &&\n this.query.unions[0].classes.length === 0\n ) {\n return;\n }\n\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n if (!descriptor || !propertyField) {\n return;\n }\n\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const className = propertyField.properties[\n i\n ].property.classInfo.name.replace(\":\", \".\");\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.removeRelatedProperty(i, propertyField, propertyName);\n } else {\n this.removePropertyFromQuery(i, className, propertyName);\n }\n }\n }\n\n public removeRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n ) {\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n if (!path.isForwardRelationship) {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `TargetECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n `SourceECInstanceId`,\n );\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n } else {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n `ECInstanceId`,\n );\n }\n }\n });\n }\n\n public removePropertyFromQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n ) {\n const foundClass = this.query?.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n const foundPropertyIndex = foundClass.properties.findIndex(\n (p) => p.name === propertyName,\n );\n if (foundPropertyIndex > -1) {\n foundClass.properties.splice(foundPropertyIndex, 1);\n }\n if (foundClass.properties.length === 0) {\n // remove the entire class if all properties are removed\n const foundClassIndex =\n this.query?.unions[unionIndex].classes.findIndex(\n (c) => c.className === className,\n ) ?? -1;\n if (foundClassIndex > -1) {\n this.query?.unions[unionIndex].classes.splice(foundClassIndex, 1);\n }\n }\n }\n }\n\n public categoryQuery(codeValue: string): string {\n return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;\n }\n\n public buildQueryString() {\n if (\n this.query === undefined ||\n this.query.unions.length === 0 ||\n this.query.unions[0].classes.length === 0\n ) {\n return \"\";\n }\n\n let unionQuery = \"\";\n for (const union of this.query.unions) {\n const baseClass = union.classes[0];\n const baseClassName = baseClass.className;\n const baseIdName = baseClass.isAspect\n ? `${baseClassName}.Element.id`\n : `${baseClassName}.ECInstanceId`;\n\n let queryString = `SELECT ${baseIdName}${\n baseClass.isAspect ? \" ECInstanceId\" : \"\"\n } FROM ${baseClassName}`;\n\n if (union.classes.length > 1) {\n for (let i = 1; i < union.classes.length; i++) {\n const joinClass = union.classes[i];\n const joinClassName = joinClass.className;\n const joinIdName = joinClass.isAspect\n ? `${joinClassName}.Element.id`\n : `${joinClassName}.ECInstanceId`;\n\n if (joinClass.isRelational) {\n queryString += ` JOIN ${joinClassName}`;\n if (joinClass.properties.length > 0) {\n if (joinClass.properties[0].isCategory) {\n queryString += this.categoryQuery(\n joinClass.properties[0].value.toString(),\n );\n } else {\n if (joinClass.properties[0].needsQuote) {\n queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}='${joinClass.properties[0].value}'`;\n } else {\n if (this._isFloat(joinClass.properties[0].value)) {\n queryString += ` ON ROUND(${joinClassName}.${joinClass.properties[0].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(\n joinClass.properties[0].value,\n ).toFixed(QueryBuilder.DEFAULT_DOUBLE_PRECISION)}`;\n } else {\n queryString += ` ON ${joinClassName}.${joinClass.properties[0].name}=${joinClass.properties[0].value}`;\n }\n }\n }\n }\n // when base is regular property, link base to first joined relational property\n if (!baseClass.isRelational && i === 1) {\n queryString += ` AND ${joinIdName} = ${baseIdName}`;\n }\n for (const property of joinClass.properties) {\n if (property.isCategory) {\n queryString += this.categoryQuery(property.value.toString());\n } else {\n if (property.needsQuote) {\n queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;\n } else {\n if (this._isFloat(property.value)) {\n queryString += ` AND ROUND(${joinClassName}.${property.name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;\n }\n }\n }\n }\n } else {\n queryString += ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;\n for (const property of joinClass.properties) {\n if (property.isCategory) {\n queryString += this.categoryQuery(property.value.toString());\n } else {\n if (property.needsQuote) {\n queryString += ` AND ${joinClassName}.${property.name}='${property.value}'`;\n } else {\n if (this._isFloat(property.value)) {\n queryString += ` AND ROUND(${joinClassName}.${property.name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${joinClassName}.${property.name}=${property.value}`;\n }\n }\n }\n }\n }\n }\n }\n\n const properties = baseClass.properties;\n if (properties.length > 0) {\n if (properties[0].isCategory) {\n queryString += this.categoryQuery(properties[0].value.toString());\n } else {\n if (properties[0].needsQuote) {\n queryString += ` WHERE ${baseClassName}.${properties[0].name}='${properties[0].value}'`;\n } else {\n if (this._isFloat(properties[0].value)) {\n queryString += ` WHERE ROUND(${baseClassName}.${properties[0].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(properties[0].value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` WHERE ${baseClassName}.${properties[0].name}=${properties[0].value}`;\n }\n }\n }\n if (properties.length > 1) {\n for (let i = 1; i < properties.length; i++) {\n if (properties[i].isCategory) {\n queryString += this.categoryQuery(properties[i].value.toString());\n } else {\n if (properties[i].needsQuote) {\n queryString += ` AND ${baseClassName}.${properties[i].name}='${properties[i].value}'`;\n } else {\n if (this._isFloat(properties[i].value)) {\n queryString += ` AND ROUND(${baseClassName}.${properties[i].name}, `;\n queryString += `${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`;\n queryString += `${Number(properties[i].value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION,\n )}`;\n } else {\n queryString += ` AND ${baseClassName}.${properties[i].name}=${properties[i].value}`;\n }\n }\n }\n }\n }\n }\n unionQuery += `${queryString} UNION `;\n }\n unionQuery = unionQuery.slice(0, unionQuery.length - 7);\n return unionQuery;\n }\n\n private _isFloat(n: unknown): boolean {\n return Number(n) === n && n % 1 !== 0;\n }\n}\n"]}
1
+ {"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../src/widget/components/QueryBuilder.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,mBA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AAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AApcsB,uCAA0B,GAC/C,iCAAiC,CAAC;AACb,wCAA2B,GAChD,iCAAiC,CAAC;AACb,qCAAwB,GAAG,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { PresentationPropertyDataProvider } from \"@itwin/presentation-components\";\nimport type {\n InstanceKey,\n PropertiesField,\n} from \"@itwin/presentation-common\";\nimport type { Primitives, PropertyRecord } from \"@itwin/appui-abstract\";\nimport { PropertyValueFormat } from \"@itwin/appui-abstract\";\nimport { toaster } from \"@itwin/itwinui-react\";\n\nexport interface Query {\n unions: QueryUnion[];\n}\n\nexport interface QueryUnion {\n classes: QueryClass[];\n}\n\nexport interface QueryClass {\n // schemaName.className\n className: string;\n properties: QueryProperty[];\n isAspect: boolean;\n isRelational?: boolean;\n}\n\nexport interface QueryProperty {\n name: string;\n value: Primitives.Value;\n needsQuote: boolean;\n isCategory: boolean;\n}\n\n/* This class is to build adaptive and dynamic query for find similar property selections */\nexport class QueryBuilder {\n public static readonly MULTI_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsMultiAspects\";\n public static readonly UNIQUE_ASPECT_PRIMARY_CLASS =\n \"BisCore:ElementOwnsUniqueAspect\";\n public static readonly DEFAULT_DOUBLE_PRECISION = 4;\n\n public dataProvider: PresentationPropertyDataProvider | undefined;\n public query: Query | undefined;\n\n /**\n *\n */\n constructor(provider: PresentationPropertyDataProvider | undefined) {\n this.dataProvider = provider;\n }\n\n private isCategory(propertyField: PropertiesField): boolean {\n const classInfo =\n propertyField.properties[0].property.navigationPropertyInfo?.classInfo;\n return classInfo?.name === \"BisCore:GeometricElement3dIsInCategory\";\n }\n\n public async addProperty(prop: PropertyRecord): Promise<boolean> {\n // TODO: only handle primitive properties now\n if (prop.value?.valueFormat !== PropertyValueFormat.Primitive) {\n toaster.warning(\"Only primitive types are supported for now.\");\n return false;\n }\n if (prop.value.value === undefined) {\n return false;\n }\n\n function replaceAll(str: string, match: string, replacement: string) {\n return str.split(match).join(replacement);\n }\n // if property value has single quote, escape\n if (\n (typeof prop.value.value === \"string\" ||\n prop.value.value instanceof String) &&\n String(prop.value.value).indexOf(\"'\") >= 0\n ) {\n prop.value.value = replaceAll(prop.value.value.toString(), \"'\", \"''\");\n }\n\n // get descriptor\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n\n if (!descriptor || !propertyField) {\n toaster.negative(\n \"Error. Failed to fetch field for this property record.\",\n );\n return false;\n }\n\n // get the special cases\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const className = propertyField.properties[i].property.classInfo.name.replace(\":\", \".\");\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const propertyValue = isNavigation\n ? isCategory\n ? prop.value.displayValue ?? \"\"\n : (prop.value.value as InstanceKey).id\n : prop.value.value;\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.addRelatedProperty(\n i,\n propertyField,\n propertyName,\n propertyValue,\n isAspect,\n );\n } else {\n this.addPropertyToQuery(\n i,\n className,\n propertyName,\n propertyValue,\n isAspect,\n this.needsQuote(propertyField),\n isCategory,\n false,\n );\n }\n }\n return true;\n }\n\n private needsQuote(propertyField: PropertiesField): boolean {\n // list of property types that need quote around property value\n if (propertyField.type.typeName.toLowerCase() === \"string\") {\n return true;\n }\n if (propertyField.type.typeName.toLowerCase() === \"uri\") {\n return true;\n }\n return false;\n }\n\n private addRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n ) {\n const addProperty = this.addRelatedPropertyToQuery(unionIndex, isAspect);\n\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n\n const relPropertyName = path.isForwardRelationship\n ? `SourceECInstanceId`\n : `TargetECInstanceId`;\n\n const relPropertyValue = path.isForwardRelationship\n ? `${relClassName}.TargetECInstanceId`\n : `${relClassName}.SourceECInstanceId`;\n\n addProperty(\n targetClassName,\n `ECInstanceId`,\n relPropertyValue,\n false\n );\n\n addProperty(\n relClassName,\n relPropertyName,\n `${sourceClassName}.ECInstanceId`,\n false\n );\n\n if (path.sourceClassInfo?.name\n === propertyField.parent?.contentClassInfo.name) {\n addProperty(\n sourceClassName,\n propertyName,\n propertyValue,\n this.needsQuote(propertyField)\n );\n }\n });\n }\n\n private addRelatedPropertyToQuery = (\n unionIndex: number,\n isAspect: boolean,\n ) => (\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n needsQuote: boolean,\n ) => this.addPropertyToQuery(unionIndex, className, propertyName, propertyValue, isAspect, needsQuote, false, true);\n\n private addPropertyToQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n propertyValue: Primitives.Value,\n isAspect: boolean,\n needsQuote: boolean,\n isCategory: boolean,\n isRelational?: boolean,\n ) {\n if (this.query === undefined || this.query.unions.length === 0) {\n this.query = { unions: [] };\n }\n\n const queryProperty: QueryProperty = {\n name: propertyName,\n value: propertyValue,\n needsQuote,\n isCategory,\n };\n\n const queryClass: QueryClass = {\n className,\n isAspect,\n isRelational,\n properties: [\n queryProperty,\n ],\n };\n\n if (this.query.unions.length <= unionIndex) {\n this.query.unions.push({\n classes: [\n queryClass,\n ],\n });\n return;\n }\n\n const foundClass = this.query.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n foundClass.isRelational = isRelational;\n if (!foundClass.properties.find((x) => x.name === propertyName)) {\n foundClass.properties.push(queryProperty);\n }\n } else {\n this.query.unions[unionIndex].classes.push(queryClass);\n }\n }\n\n public async removeProperty(prop: PropertyRecord) {\n if (this.query === undefined || this.query.unions.length === 0) {\n return;\n }\n if (\n this.query.unions.length === 1 &&\n this.query.unions[0].classes.length === 0\n ) {\n return;\n }\n\n const descriptor = await this.dataProvider?.getContentDescriptor();\n const propertyField = (await this.dataProvider?.getFieldByPropertyRecord(\n prop,\n )) as PropertiesField;\n if (!descriptor || !propertyField) {\n return;\n }\n\n const isAspect: boolean =\n propertyField.parent?.pathToPrimaryClass.find(\n (a) =>\n a.relationshipInfo?.name ===\n QueryBuilder.UNIQUE_ASPECT_PRIMARY_CLASS ||\n a.relationshipInfo?.name === QueryBuilder.MULTI_ASPECT_PRIMARY_CLASS,\n ) !== undefined;\n const isNavigation: boolean =\n prop.property.typename.toLowerCase() === \"navigation\";\n const isCategory: boolean = isNavigation && this.isCategory(propertyField);\n\n for (let i = 0; i < propertyField.properties.length; i++) {\n const propertyName = isNavigation\n ? isCategory\n ? `${propertyField.properties[i].property.name}.CodeValue`\n : `${propertyField.properties[i].property.name}.id`\n : propertyField.properties[i].property.name;\n const className = propertyField.properties[i].property.classInfo.name.replace(\":\", \".\");\n\n if (\n !isAspect &&\n propertyField.parent?.pathToPrimaryClass &&\n propertyField.parent?.pathToPrimaryClass.length > 0\n ) {\n this.removeRelatedProperty(i, propertyField, propertyName);\n } else {\n this.removePropertyFromQuery(i, className, propertyName);\n }\n }\n }\n\n private removeRelatedProperty(\n unionIndex: number,\n propertyField: PropertiesField,\n propertyName: string,\n ) {\n const paths = [...(propertyField.parent?.pathToPrimaryClass ?? [])];\n paths.reverse().forEach((path) => {\n const sourceClassName = path.sourceClassInfo?.name.replace(\":\", \".\");\n const targetClassName = path.targetClassInfo?.name.replace(\":\", \".\");\n const relClassName = path.relationshipInfo?.name.replace(\":\", \".\");\n\n this.removePropertyFromQuery(\n unionIndex,\n targetClassName,\n `ECInstanceId`,\n );\n\n const relPropertyName = path.isForwardRelationship ? `SourceECInstanceId` : `TargetECInstanceId`;\n this.removePropertyFromQuery(\n unionIndex,\n relClassName,\n relPropertyName,\n );\n\n if (\n path.sourceClassInfo?.name ===\n propertyField.parent?.contentClassInfo.name\n ) {\n this.removePropertyFromQuery(\n unionIndex,\n sourceClassName,\n propertyName,\n );\n }\n });\n }\n\n private removePropertyFromQuery(\n unionIndex: number,\n className: string,\n propertyName: string,\n ) {\n const foundClass = this.query?.unions[unionIndex].classes.find(\n (c) => c.className === className,\n );\n if (foundClass) {\n const foundPropertyIndex = foundClass.properties.findIndex(\n (p) => p.name === propertyName,\n );\n if (foundPropertyIndex > -1) {\n foundClass.properties.splice(foundPropertyIndex, 1);\n }\n if (foundClass.properties.length === 0) {\n // remove the entire class if all properties are removed\n const foundClassIndex =\n this.query?.unions[unionIndex].classes.findIndex(\n (c) => c.className === className,\n ) ?? -1;\n if (foundClassIndex > -1) {\n this.query?.unions[unionIndex].classes.splice(foundClassIndex, 1);\n }\n }\n }\n }\n\n public buildQueryString() {\n if (\n this.query === undefined ||\n this.query.unions.length === 0 ||\n this.query.unions[0].classes.length === 0\n ) {\n return \"\";\n }\n\n const unionSegments: string[] = [];\n for (const union of this.query.unions) {\n const querySegments: string[] = [];\n\n const baseClass = union.classes[0];\n const baseClassName = baseClass.className;\n const baseIdName = baseClass.isAspect\n ? `${baseClassName}.Element.id`\n : `${baseClassName}.ECInstanceId`;\n\n const selectSegment = `SELECT ${baseIdName}${baseClass.isAspect ? \" ECInstanceId\" : \"\"} FROM ${baseClassName}`;\n querySegments.push(selectSegment);\n\n if (union.classes.length > 1) {\n for (let i = 1; i < union.classes.length; i++) {\n const joinClass = union.classes[i];\n const joinClassName = joinClass.className;\n const joinIdName = joinClass.isAspect\n ? `${joinClassName}.Element.id`\n : `${joinClassName}.ECInstanceId`;\n\n const joinSegment = joinClass.isRelational\n ? ` JOIN ${joinClassName}`\n : ` JOIN ${joinClassName} ON ${joinIdName} = ${baseIdName}`;\n querySegments.push(joinSegment);\n\n for (let j = 0; j < joinClass.properties.length; j++) {\n const prefix = j === 0 && joinClass.isRelational ? \"ON\" : \"AND\";\n const propertySegment = this.propertySegment(joinClassName, joinClass.properties[j], prefix);\n querySegments.push(propertySegment);\n }\n // when base is regular property, link base to first joined relational property\n if (joinClass.isRelational && !baseClass.isRelational && i === 1) {\n querySegments.push(` AND ${joinIdName} = ${baseIdName}`);\n }\n }\n }\n\n const whereSegment = this.whereSegment(baseClass, baseClassName);\n querySegments.push(whereSegment);\n\n unionSegments.push(querySegments.join(\"\"));\n }\n\n return unionSegments.join(\" UNION \");\n }\n\n private whereSegment = (\n baseClass: QueryClass,\n baseClassName: string\n ): string => {\n const segments: string[] = [];\n\n const properties = baseClass.properties;\n for (let i = 0; i < properties.length; i++) {\n const prefix = i === 0 ? \"WHERE\" : \"AND\";\n segments.push(this.propertySegment(baseClassName, properties[i], prefix));\n }\n\n return segments.join(\"\");\n }\n\n private propertySegment(\n className: string,\n property: QueryProperty,\n prefix: string\n ): string {\n const segments: string[] = [];\n\n if (property.isCategory) {\n segments.push(this.categoryQuery(property.value.toString()));\n } else {\n if (property.needsQuote) {\n segments.push(` ${prefix} ${className}.${property.name}='${property.value}'`);\n } else {\n if (this.isFloat(property.value)) {\n segments.push(` ${prefix} ROUND(${className}.${property.name}, `);\n segments.push(`${QueryBuilder.DEFAULT_DOUBLE_PRECISION})=`);\n segments.push(`${Number(property.value).toFixed(\n QueryBuilder.DEFAULT_DOUBLE_PRECISION\n )}`);\n } else {\n segments.push(` ${prefix} ${className}.${property.name}=${property.value}`);\n }\n }\n }\n\n return segments.join(\"\");\n }\n\n private categoryQuery(codeValue: string): string {\n return ` JOIN bis.Category ON bis.Category.ECInstanceId = bis.GeometricElement3d.category.id AND ((bis.Category.CodeValue='${codeValue}') OR (bis.Category.UserLabel='${codeValue}'))`;\n }\n\n private isFloat(n: unknown): boolean {\n return Number(n) === n && n % 1 !== 0;\n }\n}\n"]}