@p2olab/pimad-core
Version:
PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.
95 lines (94 loc) • 3.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseProcedureFactory = exports.AProcedure = void 0;
const Utils_1 = require("../Utils");
const ModuleAutomationObject_1 = require("./ModuleAutomationObject");
class AProcedure extends ModuleAutomationObject_1.AModuleAutomationObject {
constructor() {
super();
this.attributes = [];
this.dataAssembly = {};
this.metaModelRef = 'metaModelRef: not initialized';
this.name = 'name: not initialized';
this.parameters = [];
this.initialized = false;
}
/**
* @inheritDoc {@link Parameter.getAttribute}
*/
getAttribute(name, callback) {
const localAttribute = this.attributes.find(attribute => attribute.getName().getContent().data === name);
if (localAttribute === undefined) {
this.genericPiMAdGetter({}, callback);
}
else {
this.genericPiMAdGetter(localAttribute, callback);
}
}
/**
* @inheritDoc {@link Parameter.getAllAttributes}
*/
getAllAttributes(callback) {
this.genericPiMAdGetter(this.attributes, callback);
}
/**
* @inheritDoc {@link Parameter.getAllParameters}
*/
getAllParameters(callback) {
this.genericPiMAdGetter(this.parameters, callback);
}
/**
* @inheritDoc {@link Parameter.getDataAssembly}
*/
getDataAssembly(callback) {
this.genericPiMAdGetter(this.dataAssembly, callback);
}
/**
* @inheritDoc {@link Parameter.getParameter}
*/
getParameter(name, callback) {
const localParameter = this.parameters.find(parameter => name === parameter.getName());
if (localParameter === undefined) {
this.genericPiMAdGetter({}, callback);
}
else {
this.genericPiMAdGetter(localParameter, callback);
}
}
/**
* @inheritDoc {@link Parameter.initialize}
*/
initialize(instructions) {
if (!this.initialized) {
this.attributes = instructions.attributes;
this.dataAssembly = instructions.dataAssembly;
this.parameters = instructions.parameter;
this.initialized = (JSON.stringify(this.attributes) === JSON.stringify(instructions.attributes)
&& JSON.stringify(this.dataAssembly) === JSON.stringify(instructions.dataAssembly)
&& JSON.stringify(this.parameters) === JSON.stringify(instructions.parameter)
&& this.moduleAutomationObjectInitialize({
dataSourceIdentifier: instructions.dataSourceIdentifier,
metaModelRef: instructions.metaModelRef,
name: instructions.name,
pimadIdentifier: instructions.pimadIdentifier
}));
return this.initialized;
}
else {
return false;
}
}
}
exports.AProcedure = AProcedure;
class BaseProcedure extends AProcedure {
}
class AProcedureFactory {
}
class BaseProcedureFactory extends AProcedureFactory {
create() {
const procedure = new BaseProcedure();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + procedure.constructor.name);
return procedure;
}
}
exports.BaseProcedureFactory = BaseProcedureFactory;