@itwin/grouping-mapping-widget 0.5.0 → 0.5.1
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/lib/cjs/widget/components/QueryBuilder.d.ts +0 -1
- package/lib/cjs/widget/components/QueryBuilder.js +0 -1
- package/lib/cjs/widget/components/QueryBuilder.js.map +1 -1
- package/lib/esm/widget/components/QueryBuilder.d.ts +0 -1
- package/lib/esm/widget/components/QueryBuilder.js +0 -1
- package/lib/esm/widget/components/QueryBuilder.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PresentationPropertyDataProvider } from "@itwin/presentation-components";
|
|
2
2
|
import type { PropertiesField } from "@itwin/presentation-common";
|
|
3
3
|
import type { Primitives, PropertyRecord } from "@itwin/appui-abstract";
|
|
4
|
-
import "core-js/features/string/virtual";
|
|
5
4
|
export interface Query {
|
|
6
5
|
unions: QueryUnion[];
|
|
7
6
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryBuilder = void 0;
|
|
4
4
|
const appui_abstract_1 = require("@itwin/appui-abstract");
|
|
5
|
-
require("core-js/features/string/virtual");
|
|
6
5
|
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
7
6
|
/* This class is to build adaptive and dynamic query for find similar property selections */
|
|
8
7
|
class QueryBuilder {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.js","sourceRoot":"","sources":["../../../../src/widget/components/QueryBuilder.ts"],"names":[],"mappings":";;;AAUA,0DAA4D;AAC5D,2CAAyC;AACzC,wDAA+C;AAyB/C,4FAA4F;AAC5F,MAAa,YAAY;IAUvB;;OAEG;IACH,YAAY,QAAsD;QAChE,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAEM,UAAU,CAAC,aAA8B;;QAC9C,MAAM,SAAS,GACb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AAC,CAAC;IACxC,CAAC;;AA7mBH,oCA8mBC;AA7mBwB,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 \"core-js/features/string/virtual\";\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"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G,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxD,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,QAAQ,CAAC,CAAU;QACzB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;;AA7mBH,oCA8mBC;AA7mBwB,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,7 +1,6 @@
|
|
|
1
1
|
import type { PresentationPropertyDataProvider } from "@itwin/presentation-components";
|
|
2
2
|
import type { PropertiesField } from "@itwin/presentation-common";
|
|
3
3
|
import type { Primitives, PropertyRecord } from "@itwin/appui-abstract";
|
|
4
|
-
import "core-js/features/string/virtual";
|
|
5
4
|
export interface Query {
|
|
6
5
|
unions: QueryUnion[];
|
|
7
6
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PropertyValueFormat } from "@itwin/appui-abstract";
|
|
2
|
-
import "core-js/features/string/virtual";
|
|
3
2
|
import { toaster } from "@itwin/itwinui-react";
|
|
4
3
|
/* This class is to build adaptive and dynamic query for find similar property selections */
|
|
5
4
|
export class QueryBuilder {
|
|
@@ -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,iCAAiC,CAAC;AACzC,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,MAAM,SAAS,GACb,MAAA,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,0CAAE,SAAS,CAAC;QACzE,OAAO,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,wCAAwC,CAAC;IACtE,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,IAAoB;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U,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE;gCAC5B,WAAW,IAAI,QAAQ,aAAa,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;6BACvF;iCAAM;gCACL,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;oCACtC,WAAW,IAAI,cAAc,aAAa,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;oCACrE,WAAW,IAAI,GAAG,YAAY,CAAC,wBAAwB,IAAI,CAAC;oCAC5D,WAAW,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CACnD,YAAY,CAAC,wBAAwB,CACtC,EAAE,CAAC;iCACL;qCAAM;oCACL,WAAW,IAAI,QAAQ,aAAa,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;iCACrF;6BACF;yBACF;qBACF;iBACF;aACF;YACD,UAAU,IAAI,GAAG,WAAW,SAAS,CAAC;SACvC;QACD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxD,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,QAAQ,CAAC,CAAU;QACzB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,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 \"core-js/features/string/virtual\";\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,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/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CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,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"]}
|