Skip to content

MasterdataDirector#

Note

This is advanced documentation regarding a scope that can be accessed when executing a step of type Script.

The MasterdataDirector class orchestrates the creation of complex objects like automation protocols, driver definitions, and controllers using the Builder Design Pattern. It interacts with builder instances to construct these objects in a flexible and modular way.

Public Methods#

setBuilder#

setBuilder(type: MasterdataBuilderTypes): void

Assigns a specific builder type to the MasterdataDirector, used to switch between different builder implementations dynamically.

  • type: The type of builder (MasterdataBuilderTypes) to be set. Example: MasterdataBuilderTypes.JSON.

Throws an error if an unsupported builder type is provided.

buildProtocol#

buildProtocol(protocol: AutomationProtocol, protocolParameters?: AutomationProtocolParameter[]): Promise<void>

Builds an automation protocol, including optional protocol parameters.

  • If no protocolParameters are provided, a default protocol parameter is added.
  • Uses the builder to add protocol details to the underlying master data.
  • protocol: The AutomationProtocol object containing protocol details such as name, type, package information, etc.
  • protocolParameters (optional): An array of AutomationProtocolParameter objects specifying additional parameters for the protocol.

A Promise that resolves when the operation is complete.

const protocol = {
    name: protocolName,
    type: protocolType,
    packageName: packageName,
    description
};
await this.masterdataDirector.buildProtocol(protocol);

buildDriverDefinition#

buildDriverDefinition(driverDefinition: AutomationDriverDefinition, properties?: AutomationProperty[], events?: AutomationEvent[], eventProperties?: AutomationEventProperty[], commands?: AutomationCommand[], commandParameters?: AutomationCommandParameter[]): void

Constructs a driver definition with optional associated properties, events, and commands.

  • driverDefinition: The AutomationDriverDefinition object containing details of the driver to be created.
  • properties (optional): An array of AutomationProperty objects for the driver.
  • events (optional): An array of AutomationEvent objects.
  • eventProperties (optional): An array of AutomationEventProperty objects.
  • commands (optional): An array of AutomationCommand objects.
  • commandParameters (optional): An array of AutomationCommandParameter objects.

void

const driverDefinition = {
    name: `${this.answers.integrationName} Driver Definition`,
    type: `General`,
    automationProtocol: `${this.answers.integrationName} Protocol`,
    objectType: this.answers.iotEnabledEntity.Name,
    description
};

await this.masterdataDirector.buildDriverDefinition(driverDefinition);

buildController#

buildController(controller: AutomationController, controllerDriverDefinitions: AutomationControllerDriverDefinition[], controllerWorkflows: AutomationControllerWorkflow[]): Promise<void>

Creates an automation controller with driver definitions and workflows.

  • controller: The AutomationController object containing controller details.
  • controllerDriverDefinitions: An array of AutomationControllerDriverDefinition objects specifying drivers associated with the controller.
  • controllerWorkflows: An array of AutomationControllerWorkflow objects specifying workflows for the controller.

A Promise that resolves when the operation is complete.

await this.masterdataDirector.buildController(controller, [controllerDriverDefinition], workflows);

resetBuilder#

resetBuilder(): void

Resets the current builder instance.

void

getMasterdata#

getMasterdata(): Map<string, any>

Returns the internal master data map maintained by the builder.

A Map<string, any> containing the constructed master data.

"(async () => {",
"  return ([await this.lboUtilities.createMasterdata(this.masterdataDirector.getMasterdata())]);",
"})()"