-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpropertyDatabaseFunctions.ts
55 lines (42 loc) · 2.1 KB
/
propertyDatabaseFunctions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { QueryResults, UserQueryOptions } from "./output";
import { QueryFactory } from "./src/queryFactory";
import { PropertyDatabase } from "./propertyDatabase";
import { PropertyDatabaseAttributesCollection } from "./src/propertyDatabaseAttributesCollection";
import { PropertyDatabaseQueryableElement } from "./src/propertyDatabaseQueryableElement";
import { findRootNodes } from "./src/rootsNodesFactory";
import { PropertyValuesQueryFactory } from "./src/propertyValuesQueryFactory";
import { createPropertiesExtractor } from "./src/properties/queryPropertiesExtractorsFactory";
export const filterElements = (pdb: PropertyDatabase, tag: UserQueryOptions): QueryResults => {
try {
const dbIds: number[] = [];
const { lmvQuery, lmvQueryOptions, nodes } = tag!;
const filterFactory = new QueryFactory(lmvQueryOptions);
const elementQuery = filterFactory.createQuery(lmvQuery);
const attributesCollection = new PropertyDatabaseAttributesCollection(pdb, lmvQueryOptions.attributesCaseSensitive);
const roots = findRootNodes(pdb, attributesCollection);
const propertyValuesQueryFactory = new PropertyValuesQueryFactory(pdb, attributesCollection, roots, lmvQueryOptions.modelBrowserExcludeRoot, lmvQueryOptions.modelName);
const propertiesExtractor = createPropertiesExtractor(elementQuery, lmvQueryOptions);
for (const dbId of nodes) {
if (lmvQueryOptions.leafNodesOnly && pdb.getNodeNameAndChildren({ dbId }) !== undefined)
continue;
const element = new PropertyDatabaseQueryableElement(dbId, propertyValuesQueryFactory);
if (elementQuery.filter(element)) {
dbIds.push(dbId);
propertiesExtractor.push(dbId, element);
}
}
return {
dbIds,
rows: propertiesExtractor.compile(),
columns: propertiesExtractor.getColumns(),
error: null
}
} catch (error: any) {
return {
dbIds: [],
error: error,
rows: [],
columns: []
}
}
}