Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getElement from NativeDgnDb #719

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
716a8d3
Add ECProperty updating to null test
Mar 14, 2024
65621b3
Adjust the whitespace
Mar 14, 2024
399f53c
Merge branch 'main' into Sarunas/struct-prop-null
Mar 15, 2024
c330139
Handle setting structProp = null
Mar 18, 2024
18623bf
append tests for update to null using ECSqlStatement
Mar 21, 2024
7b1945e
add an additional test for all struct properties becoming null
Mar 21, 2024
40755e7
Merge branch 'main' into Sarunas/struct-prop-null
Mar 21, 2024
457122f
Merge branch 'main' into Sarunas/struct-prop-null
Mar 22, 2024
0ef9dff
Merge branch 'main' into Sarunas/struct-prop-null
Mar 25, 2024
ee636d4
Revert unrelated changes
Mar 28, 2024
f83de61
Merge branch 'main' into Sarunas/select-using-dollar
Mar 29, 2024
942ecd7
Simplify tests, add inline update to null test case
Mar 29, 2024
f28954a
Merge branch 'main' into Sarunas/select-using-dollar
Apr 2, 2024
2b58e66
Initial QueryJsonAdaptor adaptation
Apr 2, 2024
21fb615
JSify prop names
Apr 4, 2024
2869d8f
Merge branch 'main' into Sarunas/select-using-dollar
Apr 4, 2024
0a29f1b
Merge branch 'main' into Sarunas/select-using-dollar
Apr 5, 2024
a461664
Add a new option flag for Jsifying elements
Apr 8, 2024
ee49616
Do not create DgnElement instance for JsInteropGetElement
Apr 11, 2024
140980a
lowercase first char for jsify elements flag handling
Apr 11, 2024
500c136
Merge branch 'main' into Sarunas/select-using-dollar
Apr 15, 2024
60a46d3
Fix ToJson test to portray actual DB state
Apr 15, 2024
f5de0a5
Merge branch 'main' into Sarunas/select-using-dollar
Apr 16, 2024
c0c3474
Add an extra check for Schema for code properties
Apr 16, 2024
4544062
Clean up imports
Apr 16, 2024
3c89fff
Merge branch 'main' into Sarunas/select-using-dollar
Apr 17, 2024
baa9a3c
Merge branch 'main' into Sarunas/select-using-dollar
Apr 17, 2024
f9d66c3
Merge branch 'main' into Sarunas/select-using-dollar
Apr 18, 2024
74a6bfa
Merge branch 'main' into Sarunas/select-using-dollar
Apr 19, 2024
7254c58
Merge branch 'main' into Sarunas/select-using-dollar
Apr 19, 2024
33074c2
More NavId JS exceptions handled
Apr 19, 2024
df2a61a
Merge branch 'main' into Sarunas/select-using-dollar
Apr 23, 2024
2e84927
self-review
Apr 23, 2024
b9c1155
Revert QueryJsonAdaptor hardcoded JSON building
Apr 24, 2024
5263f36
Left out misalignments
Apr 24, 2024
25f74da
Merge branch 'main' into Sarunas/select-using-dollar
Apr 24, 2024
3129670
align docs
Apr 25, 2024
8d99800
Merge branch 'main' into Sarunas/select-using-dollar
6ar8nas Apr 26, 2024
9d838cd
Merge branch 'main' into Sarunas/select-using-dollar
Apr 29, 2024
f7801c2
Merge branch 'main' into Sarunas/select-using-dollar
May 2, 2024
09ad9f2
revert breaking QueryJsonAdaptor changes
May 2, 2024
a9d56a9
fix test json indentation
May 2, 2024
8a49820
fix json indentation
May 2, 2024
1cb4302
remove getElement from DgnDb
May 2, 2024
bea9909
change binding format
May 2, 2024
37d2aff
remove getElement usage from TS tests
May 6, 2024
21c2032
remove getElement leftovers
May 6, 2024
d4536bb
Merge branch 'main' into Sarunas/select-using-dollar
May 8, 2024
1b18f8f
Merge branch 'main' into Sarunas/select-using-dollar
May 10, 2024
bac0cae
Merge branch 'main' into Sarunas/select-using-dollar
May 17, 2024
fc7da4c
Merge branch 'main' into Sarunas/select-using-dollar
May 24, 2024
8dde5c3
remove no longer used json_baseProperties
May 24, 2024
cec6eae
Merge branch 'main' into Sarunas/select-using-dollar
Jun 4, 2024
bd9283c
Merge branch 'main' into Sarunas/select-using-dollar
Jun 13, 2024
2353b08
Merge branch 'main' into Sarunas/select-using-dollar
Jun 14, 2024
4127854
Merge branch 'main' into Sarunas/select-using-dollar
Jul 2, 2024
efa95d1
Merge branch 'main' into Sarunas/select-using-dollar
Jul 5, 2024
1e66f22
Merge conflict slip-up addressed
Jul 5, 2024
11ba7e7
Merge branch 'main' into Sarunas/select-using-dollar
Jul 8, 2024
38e3956
Update mapping functions for node tests
Jul 18, 2024
df08bea
Merge branch 'main' into Sarunas/select-using-dollar
Jul 18, 2024
3a59a06
Merge branch 'main' into Sarunas/select-using-dollar
6ar8nas Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions iModelJsNodeAddon/IModelJsNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,15 +1238,6 @@ struct NativeDgnDb : BeObjectWrap<NativeDgnDb>, SQLiteOps<DgnDb>
return worker->Queue(); // Schema serialization happens in another thread
}

Napi::Value GetElement(NapiInfoCR info) {
REQUIRE_ARGUMENT_ANY_OBJ(0, opts);
BeJsNapiObject jsValue(Env());
auto status = JsInterop::GetElement(jsValue, GetOpenedDb(info), opts);
if (DgnDbStatus::Success != status)
BeNapi::ThrowJsException(Env(), "error reading element", (int)status);
return jsValue;
}

Napi::Value GetModel(NapiInfoCR info) {
REQUIRE_ARGUMENT_ANY_OBJ(0, opts);
BeJsNapiObject modelJson(Env());
Expand Down Expand Up @@ -2710,7 +2701,6 @@ struct NativeDgnDb : BeObjectWrap<NativeDgnDb>, SQLiteOps<DgnDb>
InstanceMethod("getCurrentChangeset", &NativeDgnDb::GetCurrentChangeset),
InstanceMethod("getCurrentTxnId", &NativeDgnDb::GetCurrentTxnId),
InstanceMethod("getECClassMetaData", &NativeDgnDb::GetECClassMetaData),
InstanceMethod("getElement", &NativeDgnDb::GetElement),
InstanceMethod("getInstance", &NativeDgnDb::GetInstance),
InstanceMethod("executeSql", &NativeDgnDb::ExecuteSql),
InstanceMethod("getFilePath", &NativeDgnDb::GetFilePath),
Expand Down
1 change: 0 additions & 1 deletion iModelJsNodeAddon/IModelJsNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ struct JsInterop {
static DgnDbPtr CreateIModel(Utf8StringCR filename, BeJsConst props);
static DgnDbStatus GetECClassMetaData(BeJsValue results, DgnDbR db, Utf8CP schema, Utf8CP ecclass);
static DgnDbStatus GetSchemaItem(BeJsValue results, DgnDbR db, Utf8CP schemaName, Utf8CP itemName);
static DgnDbStatus GetElement(BeJsValue results, DgnDbR db, Napi::Object);
static Napi::String InsertElement(DgnDbR db, Napi::Object props, Napi::Value options);
static void UpdateElement(DgnDbR db, Napi::Object);
static void DeleteElement(DgnDbR db, Utf8StringCR eidStr);
Expand Down
34 changes: 0 additions & 34 deletions iModelJsNodeAddon/JsInteropDgnDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ BE_JSON_NAME(minOccurs)
BE_JSON_NAME(minimumLength)
BE_JSON_NAME(minimumValue)
BE_JSON_NAME(modifier)
BE_JSON_NAME(onlyBaseProperties)
BE_JSON_NAME(primitiveType)
BE_JSON_NAME(properties)
BE_JSON_NAME(readOnly)
Expand Down Expand Up @@ -302,39 +301,6 @@ DgnDbStatus JsInterop::GetSchemaItem(BeJsValue mjson, DgnDbR dgndb, Utf8CP schem
return DgnDbStatus::NotFound; // This is not an exception. It just returns an empty result.
}

//---------------------------------------------------------------------------------------
// @bsimethod
//---------------------------------------------------------------------------------------
DgnDbStatus JsInterop::GetElement(BeJsValue elementJson, DgnDbR dgndb, Napi::Object obj) {
BeJsConst inOpts(obj);
DgnElementCPtr elem;
DgnElementId eid = inOpts[json_id()].GetId64<DgnElementId>();

if (!eid.IsValid()) {
auto fedJson = inOpts[json_federationGuid()];
if (fedJson.isString()) {
BeGuid federationGuid;
federationGuid.FromString(fedJson.asCString());
elem = dgndb.Elements().QueryElementByFederationGuid(federationGuid);
} else {
eid = dgndb.Elements().QueryElementIdByCode(DgnCode::FromJson(inOpts[json_code()], dgndb, false));
}
}

if (!elem.IsValid())
elem = dgndb.Elements().GetElement(eid);

if (!elem.IsValid())
return DgnDbStatus::NotFound;

// if they only want base properties, don't bother calling virtual function
if (inOpts[json_onlyBaseProperties()].asBool())
elem->ToBaseJson(elementJson);
else
elem->ToJson(elementJson, inOpts);
return DgnDbStatus::Success;
}

struct SetNapiObjOnElement {
DgnElementR m_element;
SetNapiObjOnElement(DgnElementR element, NapiObjectCP obj) : m_element(element) {BeAssert(nullptr==element.m_napiObj); element.m_napiObj = obj;}
Expand Down
3 changes: 1 addition & 2 deletions iModelJsNodeAddon/api_package/ts/src/NativeLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
StatusCodeWithMessage,
} from "@itwin/core-bentley";
import type {
ChangesetIndexAndId, CodeSpecProperties, CreateEmptyStandaloneIModelProps, DbRequest, DbResponse, ElementAspectProps, ElementGraphicsRequestProps, ElementLoadProps, ElementProps,
ChangesetIndexAndId, CodeSpecProperties, CreateEmptyStandaloneIModelProps, DbRequest, DbResponse, ElementAspectProps, ElementGraphicsRequestProps, ElementProps,
FilePropertyProps, FontId, FontMapProps, GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeographicCRSInterpretRequestProps,
GeographicCRSInterpretResponseProps, GeometryContainmentResponseProps, IModelCoordinatesRequestProps,
IModelCoordinatesResponseProps, IModelProps, LocalDirName, LocalFileName, MassPropertiesResponseProps, ModelLoadProps,
Expand Down Expand Up @@ -587,7 +587,6 @@ export declare namespace IModelJsNative {
public getCurrentChangeset(): ChangesetIndexAndId;
public getCurrentTxnId(): TxnIdString;
public getECClassMetaData(schema: string, className: string): ErrorStatusOrResult<IModelStatus, string>;
public getElement(opts: ElementLoadProps): ElementProps;
public executeSql(sql: string): DbResult;
public getFilePath(): string; // full path of the DgnDb file
public getGeoCoordinatesFromIModelCoordinates(points: GeoCoordinatesRequestProps): GeoCoordinatesResponseProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { assert } from "chai";
import { Guid, GuidString, Id64Array, Id64String } from "@itwin/core-bentley";
import type { ModelGeometryChangesProps, RelatedElementProps, RelationshipProps, SubjectProps } from "@itwin/core-common";
import { IModelJsNative } from "../NativeLibrary";
import { assert, expect } from "chai";
import { DbResult, Guid, GuidString, Id64Array, Id64String } from "@itwin/core-bentley";
import { type ModelGeometryChangesProps, type RelatedElementProps, type RelationshipProps, type SubjectProps, mapNativeElementProps } from "@itwin/core-common";
import { IModelJsNative, InstanceSerializationMethod } from "../NativeLibrary";
import { copyFile, dbFileName } from "./utils";
import { openDgnDb } from "./index";

Expand Down Expand Up @@ -126,8 +126,18 @@ function makeEDE(sourceId: Id64String, targetId: Id64String): ElementDrivesEleme
};
}

function getElement(dgnDb: IModelJsNative.DgnDb, elid: Id64String) {
const statement = new IModelJsNative.ECSqlStatement();
statement.prepare(dgnDb, `SELECT ECClassId FROM Bis.Element WHERE ECInstanceId=?`);
statement.getBinder(1).bindId(elid);
expect(statement.step()).eq(DbResult.BE_SQLITE_ROW);
const classId = statement.getValue(0).getId();
statement.dispose();
return mapNativeElementProps(dgnDb.getInstance({ id: elid, classId, serializationMethod: InstanceSerializationMethod.BeJsNapi, useJsNames: true, classIdsToClassNames: true, abbreviateBlobs: false }));
}

function updateElement(db1: IModelJsNative.DgnDb, elid: Id64String, newLabel: string) {
const ed2 = db1.getElement({ id: elid });
const ed2 = getElement(db, elid);
ed2.userLabel = newLabel;
db1.updateElement(ed2);
}
Expand Down Expand Up @@ -156,7 +166,7 @@ describe("elementDependency", () => {
db.enableTxnTesting();

mockTxn.fmtElem = (_cn: string, id: Id64String) => {
return db.getElement({ id }).code.value!;
return getElement(db, id).code.value!;
};

const p2id = db.insertElement(makeSubject("p2"));
Expand Down Expand Up @@ -215,7 +225,7 @@ describe("elementDependency", () => {
db.enableTxnTesting();

mockTxn.fmtElem = (_cn: string, id: Id64String) => {
return db.getElement({ id }).code.value!;
return getElement(db, id).code.value!;
};

// The full graph:
Expand Down Expand Up @@ -334,7 +344,7 @@ describe("elementDependency", () => {
db.enableTxnTesting();

mockTxn.fmtElem = (_cn: string, id: Id64String) => {
return db.getElement({ id }).code.value!;
return getElement(db, id).code.value!;
};

const e1id = db.insertElement(makeSubject("e1"));
Expand Down Expand Up @@ -382,41 +392,41 @@ describe("elementDependency", () => {
db.enableTxnTesting();

mockTxn.fmtElem = (_cn: string, id: Id64String) => {
return db.getElement({ id }).code.value!;
return getElement(db, id).code.value!;
};

const e1id = db.insertElement(makeSubject("e1"));
const e1 = db.getElement({ id: e1id });
const e1 = getElement(db, e1id);
assert.isTrue(Guid.isGuid(e1.federationGuid!)); // if you don't supply a federationGuid, one is created

const e11props = makeSubject("e11");
e11props.federationGuid = Guid.empty;
const e11id = db.insertElement(e11props);
const e11 = db.getElement({ id: e11id });
const e11 = getElement(db, e11id);
assert.isUndefined(e11.federationGuid); // if you supply empty federationGuid, it is saved as null and returned as undefined

const e2props = makeSubject("e2");
e2props.federationGuid = Guid.createValue();
const e2id = db.insertElement(e2props);
const e2 = db.getElement({ id: e2id });
const e2 = getElement(db, e2id);
assert.strictEqual(e2.federationGuid, e2props.federationGuid); // you may supply your own federationGuid

const e21props = makeSubject("e21");
e21props.federationGuid = "bad guid";
const e21id = db.insertElement(e21props);
const e21 = db.getElement({ id: e21id });
const e21 = getElement(db, e21id);
assert.isUndefined(e21.federationGuid); // if you supply an invalid federationGuid, it is saved as null and returned as undefined

const e3props = makeSubject("e3");
e3props.federationGuid = undefined;
const e3id = db.insertElement(e3props);
const e3 = db.getElement({ id: e3id });
const e3 = getElement(db, e3id);
assert.isTrue(Guid.isGuid(e3.federationGuid!)); // if you supply "undefined" for federationGuid, one is created.

const e4props = makeSubject("e4");
e4props.federationGuid = "";
const e4id = db.insertElement(e4props);
const e4 = db.getElement({ id: e4id });
const e4 = getElement(db, e4id);
assert.isUndefined(e4.federationGuid); // if you supply an blank federationGuid, it is saved as null and returned as undefined

const ede_1_2 = makeEDE(e1id, e2id);
Expand Down
21 changes: 16 additions & 5 deletions iModelJsNodeAddon/api_package/ts/src/test/importSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { assert, expect } from "chai";
import * as fs from "fs";
import * as path from "path";
import { getOutputDir, iModelJsNative } from "./utils";
import { Guid, OpenMode } from "@itwin/core-bentley";
import { Code, ElementProps } from "@itwin/core-common";
import { DbResult, Guid, Id64String, OpenMode } from "@itwin/core-bentley";
import { Code, ElementProps, mapNativeElementProps } from "@itwin/core-common";
import { clearRegistry, loadMetaData } from "./loadMetaData";
import { IModelJsNative, InstanceSerializationMethod } from "../NativeLibrary";

const testSchemaXmlV10 = `<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="Test" alias="test" version="01.00.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
Expand Down Expand Up @@ -69,6 +70,16 @@ const testInformationRecordElementV11: ElementProps & { property1: string, prope
property2: "Prop2",
};

function getElement(db: IModelJsNative.DgnDb, elid: Id64String) {
const statement = new IModelJsNative.ECSqlStatement();
statement.prepare(db, `SELECT ECClassId FROM Bis.Element WHERE ECInstanceId=?`);
statement.getBinder(1).bindId(elid);
expect(statement.step()).eq(DbResult.BE_SQLITE_ROW);
const classId = statement.getValue(0).getId();
statement.dispose();
return mapNativeElementProps(db.getInstance({ id: elid, classId, serializationMethod: InstanceSerializationMethod.BeJsNapi, useJsNames: true, classIdsToClassNames: true, abbreviateBlobs: false }));
}

describe("ImportSchema", () => {

it("should import schema into a locally changed briefcase", () => {
Expand Down Expand Up @@ -98,7 +109,7 @@ describe("ImportSchema", () => {
expect(testInfoClassV10.properties).not.hasOwnProperty("property2");

const el1Id = db.insertElement(testInformationRecordElementV10);
const el1v10 = db.getElement({ id: el1Id });
const el1v10 = getElement(db, el1Id);
expect(el1v10).has.property("property1");
expect(el1v10).not.has.property("property2");
expect((el1v10 as any).property1).eq(testInformationRecordElementV10.property1);
Expand All @@ -121,13 +132,13 @@ describe("ImportSchema", () => {
expect(testInfoClassV11.properties).hasOwnProperty("property1");
expect(testInfoClassV11.properties).hasOwnProperty("property2");

const el1v11 = db.getElement({ id: el1Id });
const el1v11 = getElement(db, el1Id);
expect(el1v11).has.property("property1");
expect(el1v11).not.has.property("property2");
expect((el1v11 as any).property1).eq(testInformationRecordElementV10.property1);

const el2Id = db.insertElement(testInformationRecordElementV11);
const el2v11 = db.getElement({ id: el2Id });
const el2v11 = getElement(db, el2Id);
expect(el2v11).has.property("property1");
expect(el2v11).has.property("property2");
expect((el2v11 as any).property1).eq(testInformationRecordElementV11.property1);
Expand Down