--- alias: user-guide-automation-business-scenarios-building-structure-step-script-masterdatadirector tags: - automation - connect iot description: "This documentation details a class for building complex automation objects using a builder pattern" --- # 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 === "Declaration" `setBuilder(type: MasterdataBuilderTypes): void` === "Description" Assigns a specific builder type to the `MasterdataDirector`, used to switch between different builder implementations dynamically. === "Parameters" - `type`: The type of builder (`MasterdataBuilderTypes`) to be set. Example: `MasterdataBuilderTypes.JSON`. === "Returns" Throws an error if an unsupported builder type is provided. ### buildProtocol === "Declaration" `buildProtocol(protocol: AutomationProtocol, protocolParameters?: AutomationProtocolParameter[]): Promise` === "Description" 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. === "Parameters" - `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. === "Returns" A `Promise` that resolves when the operation is complete. === "Example" ```ts const protocol = { name: protocolName, type: protocolType, packageName: packageName, description }; await this.masterdataDirector.buildProtocol(protocol); ``` ### buildDriverDefinition === "Declaration" `buildDriverDefinition(driverDefinition: AutomationDriverDefinition, properties?: AutomationProperty[], events?: AutomationEvent[], eventProperties?: AutomationEventProperty[], commands?: AutomationCommand[], commandParameters?: AutomationCommandParameter[]): void` === "Description" Constructs a driver definition with optional associated properties, events, and commands. === "Parameters" - `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. === "Returns" `void` === "Example" ```ts 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 === "Declaration" `buildController(controller: AutomationController, controllerDriverDefinitions: AutomationControllerDriverDefinition[], controllerWorkflows: AutomationControllerWorkflow[]): Promise` === "Description" Creates an automation controller with driver definitions and workflows. === "Parameters" - `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. === "Returns" A `Promise` that resolves when the operation is complete. === "Example" ```ts await this.masterdataDirector.buildController(controller, [controllerDriverDefinition], workflows); ``` ### resetBuilder === "Declaration" `resetBuilder(): void` === "Description" Resets the current builder instance. === "Returns" `void` ### getMasterdata === "Declaration" `getMasterdata(): Map` === "Description" Returns the internal master data map maintained by the builder. === "Returns" A `Map` containing the constructed master data. === "Example" ```json "(async () => {", " return ([await this.lboUtilities.createMasterdata(this.masterdataDirector.getMasterdata())]);", "})()" ```