Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions common/api/core-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,13 @@ export class ElementMultiAspect extends ElementAspect {
static get className(): string;
}

// @public
export class ElementOwnsChannelRootAspect extends ElementOwnsUniqueAspect {
constructor(elementId: Id64String, relClassName?: string);
// (undocumented)
static classFullName: string;
}

// @public
export class ElementOwnsChildElements extends RelatedElement {
constructor(parentId: Id64String, relClassName?: string);
Expand Down
1 change: 1 addition & 0 deletions common/api/summary/core-backend.exports.csv
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public;class;ElementGroupsMembers
public;interface;ElementGroupsMembersProps
public;class;ElementMultiAspect
preview;class;ElementMultiAspect
public;class;ElementOwnsChannelRootAspect
public;class;ElementOwnsChildElements
public;class;ElementOwnsExternalSourceAspects
public;class;ElementOwnsMultiAspects
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "ChannelRoot gets created with the correct aspect relationship class.",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
16 changes: 14 additions & 2 deletions core/backend/src/NavigationRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class FolderContainsRepositories extends ElementOwnsChildElements {
export class SheetIndexFolderOwnsEntries extends ElementOwnsChildElements {
public static override classFullName = "BisCore:SheetIndexFolderOwnsEntries";
public constructor(parentId: Id64String, relClassName: string = SheetIndexFolderOwnsEntries.classFullName) {
super(parentId, relClassName );
super(parentId, relClassName);
}
}

Expand All @@ -120,7 +120,7 @@ export class SheetIndexFolderOwnsEntries extends ElementOwnsChildElements {
export class SheetIndexOwnsEntries extends ElementOwnsChildElements {
public static override classFullName = "BisCore:SheetIndexOwnsEntries";
public constructor(parentId: Id64String, relClassName: string = SheetIndexOwnsEntries.classFullName) {
super(parentId, relClassName );
super(parentId, relClassName);
}
}

Expand Down Expand Up @@ -287,3 +287,15 @@ export class SheetOwnsSheetInformationAspect extends ElementOwnsUniqueAspect {
super(sheetId, relClassName);
}
}

/** Relates an [[Element]] to the [[ChannelRootAspect]] that identifies it as a channel root.
* @see [[ChannelControl.makeChannelRoot]] to create an instance of this relationship.
* @public
*/
export class ElementOwnsChannelRootAspect extends ElementOwnsUniqueAspect {
public static override classFullName = "BisCore:ElementOwnsChannelRootAspect";

public constructor(elementId: Id64String, relClassName = ElementOwnsChannelRootAspect.classFullName) {
super(elementId, relClassName);
}
}
10 changes: 9 additions & 1 deletion core/backend/src/internal/ChannelAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ChannelControl, ChannelKey } from "../ChannelControl";
import { Subject } from "../Element";
import { IModelDb } from "../IModelDb";
import { IModelHost } from "../IModelHost";
import { ElementOwnsChannelRootAspect } from "../NavigationRelationship";
import { _implementationProhibited, _nativeDb, _verifyChannel } from "./Symbols";

class ChannelAdmin implements ChannelControl {
Expand Down Expand Up @@ -94,7 +95,14 @@ class ChannelAdmin implements ChannelControl {
if (this.queryChannelRoot(args.channelKey) !== undefined)
ChannelControlError.throwError("root-exists", `Channel ${args.channelKey} root already exist`, channelKey);

const props: ChannelRootAspectProps = { classFullName: ChannelAdmin.channelClassName, element: { id: args.elementId }, owner: args.channelKey };
const props: ChannelRootAspectProps = {
classFullName: ChannelAdmin.channelClassName,
element: {
id: args.elementId,
relClassName: ElementOwnsChannelRootAspect.classFullName,
},
owner: args.channelKey,
};
this._iModel.elements.insertAspect(props);
}

Expand Down
35 changes: 35 additions & 0 deletions core/backend/src/test/element/ElementAspect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,39 @@ describe("ElementAspect", () => {
assert.equal(ExternalSourceAspect.findAllBySource(iModelDb, scopeId1, kind, "<notfound>").length, 0);
});

it("should create ChannelRootAspect with correct relationship class", async () => {
const iModelDb = SnapshotDb.createEmpty(IModelTestUtils.prepareOutputFile("ElementAspect", "ChannelRootAspectTest.bim"), { rootSubject: { name: "ChannelRootAspectTest" } });

const testChannelKey = "test-channel";

// Enable the test channel
iModelDb.channels.addAllowedChannel(testChannelKey);

// Create a channel subject using insertChannelSubject
const subjectId = iModelDb.channels.insertChannelSubject({
subjectName: "Test Channel Subject",
channelKey: testChannelKey,
});
iModelDb.saveChanges();
assert.isTrue(Id64.isValidId64(subjectId), "Subject ID should be valid");

// Get the ChannelRootAspect
const aspects = iModelDb.elements.getAspects(subjectId, "BisCore:ChannelRootAspect");
assert.equal(aspects.length, 1, "Should be exactly one as it's a unique aspect");

const aspect = aspects[0];
assert.exists(aspect);
assert.equal(aspect.classFullName, "BisCore:ChannelRootAspect", "Aspect class should be ChannelRootAspect");

// Verify the relationship class
expect(aspect.element.relClassName).to.equal("BisCore.ElementOwnsChannelRootAspect");
assert.equal((aspect as any).owner, testChannelKey, "Channel owner should match the channel key");

// Query the db to confirm the relationship class
const reader = iModelDb.createQueryReader("select ec_classname(Element.RelECClassId) as relClassName from BisCore.ChannelRootAspect");
expect(await reader.step()).to.be.true;
expect(reader.current.relClassName).to.equal("BisCore:ElementOwnsChannelRootAspect");

iModelDb.close();
});
});
Loading