@p2olab/pimad-core
Version:
PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.
171 lines (170 loc) • 7.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModuleAutomation = exports.BasicDataAssembly = void 0;
const Utils_1 = require("../Utils");
const Backbone_1 = require("../Backbone");
var PiMAdResponseVendor = Backbone_1.Backbone.PiMAdResponseVendor;
var PiMAdResponseHandler = Backbone_1.Backbone.PiMAdResponseHandler;
var PiMAdResponseTypes = Backbone_1.Backbone.PiMAdResponseTypes;
class ADataAssembly {
constructor() {
this.dataItems = [];
this.dataSourceIdentifier = 'dataSourceIdentifier: undefined';
this.description = 'description: undefined';
this.name = 'name: undefined';
this.initialized = false;
this.metaModelRef = 'metaModelRef: undefined';
this.pimadIdentifier = 'pimadIdentifier: undefined';
this.responseVendor = new PiMAdResponseVendor();
this.responseHandler = new PiMAdResponseHandler();
}
getAllDataItems(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.dataItems);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.dataItems);
}
}
getDataSourceIdentifier(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.dataSourceIdentifier);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.dataSourceIdentifier);
}
}
getDataItem(name, callback) {
if (this.initialized) {
const localDataItem = this.dataItems.find(dataItem => {
let testCondition = false;
dataItem.getName((response, dataItemName) => {
testCondition = dataItemName === name;
});
return testCondition;
});
if (localDataItem === undefined) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'This DataAssembly has no DataItemModel called <' + name + '>', {}), {});
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), localDataItem);
}
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'This instance is not initialized', {}), {});
}
}
getInterfaceClass(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'Not implemented yet!', {}), '');
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), '');
}
}
getHumanReadableDescription(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.description);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.description);
}
}
getName(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.name);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.name);
}
}
getMetaModelRef(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.metaModelRef);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.metaModelRef);
}
}
/*getCommunication(): PiMAdResponse {
return this.responseVendor.buyErrorResponse();
} */
getPiMAdIdentifier(callback) {
if (this.initialized) {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.SUCCESS, 'Success', {}), this.pimadIdentifier);
}
else {
callback(this.responseHandler.handleResponse(PiMAdResponseTypes.ERROR, 'The instance is not initialized', {}), this.pimadIdentifier);
}
}
}
class BasicDataAssembly extends ADataAssembly {
initialize(instructions) {
if (!this.initialized) {
this.name = instructions.tag;
this.dataSourceIdentifier = instructions.dataSourceIdentifier;
this.description = instructions.description;
this.dataItems = instructions.dataItems;
this.pimadIdentifier = instructions.pimadIdentifier;
this.metaModelRef = instructions.metaModelRef;
this.initialized = (
// make sure every property is defined
Object.values(instructions).every(el => el !== undefined) &&
//TODO: is this really necessary?
this.name === instructions.tag &&
this.description == instructions.description &&
JSON.stringify(this.dataItems) === JSON.stringify(instructions.dataItems) &&
this.pimadIdentifier === instructions.pimadIdentifier &&
this.metaModelRef === instructions.metaModelRef);
return this.initialized;
}
else {
return false;
}
}
}
exports.BasicDataAssembly = BasicDataAssembly;
class ADataAssemblyFactory {
}
class BasicDataAssemblyFactory extends ADataAssemblyFactory {
create() {
const dataAssembly = new BasicDataAssembly();
Utils_1.logger.debug(this.constructor.name + ' creates a ' + dataAssembly.constructor.name);
return dataAssembly;
}
}
var ModuleAutomation;
(function (ModuleAutomation) {
/**
* This enum referencing to all implementations of {@link DataAssembly}.
*/
let DataAssemblyType;
(function (DataAssemblyType) {
/**
* Referencing a {@link BasicDataAssembly}.
*/
DataAssemblyType[DataAssemblyType["BASIC"] = 0] = "BASIC";
})(DataAssemblyType = ModuleAutomation.DataAssemblyType || (ModuleAutomation.DataAssemblyType = {}));
/**
* This vendor sells various {@link DataAssembly}-Instances.
*/
class DataAssemblyVendor {
/**
* This one initialize various {@link DataAssemblyFactory}.
*/
constructor() {
this.basicDataAssemblyFactory = new BasicDataAssemblyFactory();
}
/**
* Buy an uninitialized {@link DataAssembly}.
* @param type - The type of the {@link DataAssembly} as {@link DataAssemblyType}.
*/
buy(type) {
switch (type) {
case DataAssemblyType.BASIC:
return this.basicDataAssemblyFactory.create();
}
}
}
ModuleAutomation.DataAssemblyVendor = DataAssemblyVendor;
})(ModuleAutomation = exports.ModuleAutomation || (exports.ModuleAutomation = {}));