Skip to content

Commit

Permalink
add individual custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nick4598 committed Dec 18, 2024
1 parent 3c34ea6 commit 0ec65c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 56 deletions.
77 changes: 42 additions & 35 deletions packages/transformer/src/IModelExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,55 +1227,63 @@ export class ChangedInstanceIds {
this.handleChange(this.element, changeType, change.ECInstanceId);
}

/**
* Adds the provided change to the element changes maintained by this instance of ChangedInstanceIds
* If the same ECInstanceId is seen multiple times, the changedInstanceIds will be modified accordingly, i.e. if an id 'x' was updated but now we see 'x' was deleted, we will remove 'x'
* from the set of updatedIds and add it to the set of deletedIds for the appropriate class type.
* @note element changes will also cause the element's model to be marked as updated in [[ChangedInstanceIds.model]], so that the element does not get skipped by the transformer.
* @note It is the responsibility of the caller to ensure that the provided id is, in fact an element.
* @note In most cases, this method does not need to be called. Its only for consumers to mimic changes as if they were found in a changeset, which should only be useful in certain cases such as the changing of filter criteria for a preexisting master branch relationship.
*/
public addCustomElementChange(
changeType: SqliteChangeOp,
id: Id64String
id: Id64String // TODO: Support bulk adds
): void {
// if delete unnecessary?
this.addModelToUpdated(id);
this.handleChange(this.element, changeType, id);
}

/**
* Adds the provided change to the appropriate set of changes by class type (codeSpec, model, element, aspect) maintained by this instance of ChangedInstanceIds.
* Adds the provided change to the codespec changes maintained by this instance of ChangedInstanceIds
* If the same ECInstanceId is seen multiple times, the changedInstanceIds will be modified accordingly, i.e. if an id 'x' was updated but now we see 'x' was deleted, we will remove 'x'
* from the set of updatedIds and add it to the set of deletedIds for the appropriate class type.
* @note This method will not accept changes to relationship classes. Use 'addCustomRelationshipChange' instead.
* @note It is the responsibility of the caller to ensure that the provided id is, in fact a codespec.
* @note In most cases, this method does not need to be called. Its only for consumers to mimic changes as if they were found in a changeset, which should only be useful in certain cases such as the changing of filter criteria for a preexisting master branch relationship.
* @throws if the ecClassId is a relationship classId
* @param ecClassId class id of the custom change
* @param changeType insert, update or delete
* @param id ECInstanceID of the custom change
* @param federationGuid federationGuid defined on the element
*/
public async addCustomChange(
entityType: ChangedInstanceType,
public addCustomCodeSpecChange(
changeType: SqliteChangeOp,
id: Id64String // TODO: SUPPORT BULK ADDS (per entity type okay?)
): Promise<void> {
if (!this._ecClassIdsInitialized) await this.setupECClassIds();
if (entityType === "relationship") {
throw new Error(
`Misuse. id: ${id} is a relationship. Use 'addCustomRelationshipChange' instead.`
);
}
this._hasCustomChanges = true;
id: Id64String
): void {
this.handleChange(this.codeSpec, changeType, id);
}

switch (entityType) {
case "codeSpec":
this.handleChange(this.codeSpec, changeType, id);
break;
case "model":
this.handleChange(this.model, changeType, id);
break;
case "element": // When element we need to mark the element's model as updated otherwise this fails.
this.addModelToUpdated(id);
this.handleChange(this.element, changeType, id);
break;
case "aspect":
this.handleChange(this.aspect, changeType, id);
break;
}
/**
* Adds the provided change to the model changes maintained by this instance of ChangedInstanceIds
* If the same ECInstanceId is seen multiple times, the changedInstanceIds will be modified accordingly, i.e. if an id 'x' was updated but now we see 'x' was deleted, we will remove 'x'
* from the set of updatedIds and add it to the set of deletedIds for the appropriate class type.
* @note It is the responsibility of the caller to ensure that the provided id is, in fact a model.
* @note In most cases, this method does not need to be called. Its only for consumers to mimic changes as if they were found in a changeset, which should only be useful in certain cases such as the changing of filter criteria for a preexisting master branch relationship.
*/
public addCustomModelChange(
changeType: SqliteChangeOp,
id: Id64String
): void {
this.handleChange(this.model, changeType, id);
}

/**
* Adds the provided change to the aspect changes maintained by this instance of ChangedInstanceIds
* If the same ECInstanceId is seen multiple times, the changedInstanceIds will be modified accordingly, i.e. if an id 'x' was updated but now we see 'x' was deleted, we will remove 'x'
* from the set of updatedIds and add it to the set of deletedIds for the appropriate class type.
* @note It is the responsibility of the caller to ensure that the provided id is, in fact an aspect.
* @note In most cases, this method does not need to be called. Its only for consumers to mimic changes as if they were found in a changeset, which should only be useful in certain cases such as the changing of filter criteria for a preexisting master branch relationship.
*/
public addCustomAspectChange(
changeType: SqliteChangeOp,
id: Id64String
): void {
this.handleChange(this.aspect, changeType, id);
}

/**
Expand Down Expand Up @@ -1311,7 +1319,6 @@ export class ChangedInstanceIds {
* Adds the provided change to the set of relationship changes maintained by this instance of ChangedInstanceIds.
* If the same ECInstanceId is seen multiple times, the changedInstanceIds will be modified accordingly, i.e. if an id 'x' was updated but now we see 'x' was deleted, we will remove 'x'
* from the set of updatedIds and add it to the set of deletedIds for the appropriate class type.
* @note This method will ONLY accept changes to relationship classes. Use 'addCustomChange' instead if your change is not pertaining to a relationship class.
* @note In most cases, this method does not need to be called. Its only for consumers to mimic changes as if they were found in a changeset, which should only be useful in certain cases such as the changing of filter criteria for a preexisting master branch relationship.
* @throws if the ecClassId is NOT a relationship classId
* @param ecClassId class id of the custom change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,6 @@ describe("IModelTransformerHub", () => {

it("should propagate custom inserts and custom deletes", async () => {
let ecClassIdOfRel: Id64String | undefined;
let ecClassIdOfElement: Id64String | undefined;
const masterIModelName = "Master";
const masterSeedFileName = path.join(outputDir, `${masterIModelName}.bim`);
if (IModelJsFs.existsSync(masterSeedFileName))
Expand Down Expand Up @@ -1956,28 +1955,23 @@ describe("IModelTransformerHub", () => {
sourceIdOfRel!,
targetIdOfRel!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Inserted",
elementIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Inserted",
physicalModelIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"model",
exporter.sourceDbChanges?.addCustomModelChange(
"Inserted",
physicalModelIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"model",
exporter.sourceDbChanges?.addCustomModelChange(
"Inserted",
modelUnderRepositoryModel!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Inserted",
modelUnderRepositoryModel!
);
Expand Down Expand Up @@ -2046,28 +2040,23 @@ describe("IModelTransformerHub", () => {
sourceIdOfRel!,
targetIdOfRel!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Deleted",
elementIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Deleted",
physicalModelIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"model",
exporter.sourceDbChanges?.addCustomModelChange(
"Deleted",
physicalModelIdInSource!
);
await exporter.sourceDbChanges?.addCustomChange(
"model",
exporter.sourceDbChanges?.addCustomModelChange(
"Deleted",
modelUnderRepositoryModel!
);
await exporter.sourceDbChanges?.addCustomChange(
"element",
exporter.sourceDbChanges?.addCustomElementChange(
"Deleted",
modelUnderRepositoryModel!
);
Expand Down

0 comments on commit 0ec65c8

Please sign in to comment.