@p2olab/pimad-core
Version:
PiMAd (Process-industry-Modular-Automation-description) High level access to automation of modular plants.
141 lines (140 loc) • 5.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasePEAFactory = void 0;
const Backbone_1 = require("../Backbone");
var PiMAdResponseVendor = Backbone_1.Backbone.PiMAdResponseVendor;
var PiMAdResponseHandler = Backbone_1.Backbone.PiMAdResponseHandler;
var PiMAdResponseTypes = Backbone_1.Backbone.PiMAdResponseTypes;
class APEA {
constructor() {
this.dataAssemblies = [];
this.dataModel = '';
this.dataModelVersion = new Backbone_1.BasicSemanticVersion();
this.feas = [];
this.name = 'name: undefined';
this.endpoint = [];
this.pimadIdentifier = 'identifier: undefined';
this.responseHandler = new PiMAdResponseHandler();
this.responseVendor = new PiMAdResponseVendor();
this.services = [];
this.initialized = false;
}
getActuator(tag, callback) {
const response = this.responseVendor.buyErrorResponse();
callback(response);
}
getAllActuators(callback) {
const response = this.responseVendor.buyErrorResponse();
callback(response);
}
getAllDataAssemblies() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.dataAssemblies });
return response;
}
getAllFEAs() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.feas });
return response;
}
getAllSensors(callback) {
const response = this.responseVendor.buyErrorResponse();
callback(response);
}
getAllServices() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.services });
return response;
}
getDataAssembly(tag, callback) {
this.dataAssemblies.forEach((dataAssembly) => {
dataAssembly.getName((response, name) => {
if (name === tag) {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.SUCCESS, 'Success!', dataAssembly, callback);
}
if (dataAssembly === this.dataAssemblies[this.dataAssemblies.length - 1]) {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.ERROR, 'Could not find dataAssembly <' + tag + '> in PEAModel <' + this.name + '>', {}, callback);
}
});
});
}
getDataModel() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.dataModel });
return response;
}
getDataModelVersion() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.dataModelVersion });
return response;
}
getEndpoint() {
const response = this.responseVendor.buySuccessResponse();
response.initialize('Success!', { data: this.endpoint });
return response;
}
getFEA(tag, callback) {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.ERROR, '', {}, callback);
}
getPiMAdIdentifier() {
return this.pimadIdentifier;
}
getName() {
return this.name;
}
getSensor(tag, callback) {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.ERROR, '', {}, callback);
}
getService(identifier, callback) {
const localService = this.services.find(service => {
let testCondition = false;
service.getPiMAdIdentifier((response, pimadIdentifier) => {
testCondition = (pimadIdentifier === identifier);
});
return testCondition;
});
/*const localService: ServiceModel | undefined = this.services.find(service =>
service.getName() === name
);*/
if (localService == undefined) {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.ERROR, 'Could not find service <' + identifier + '> in PEAModel <' + this.name + '>', {}, callback);
}
else {
this.responseHandler.handleCallbackWithResponse(PiMAdResponseTypes.SUCCESS, 'Success!', localService, callback);
}
}
initialize(data) {
if (!this.initialized) {
this.dataAssemblies = data.DataAssemblies;
this.dataModel = data.DataModel;
this.dataModelVersion = data.DataModelVersion;
this.feas = data.FEAs;
this.pimadIdentifier = data.PiMAdIdentifier;
this.name = data.Name;
this.services = data.Services;
this.endpoint = data.Endpoint;
this.initialized = (JSON.stringify(this.dataAssemblies) === JSON.stringify(data.DataAssemblies) &&
this.dataModel === data.DataModel &&
this.dataModelVersion === data.DataModelVersion &&
this.feas === data.FEAs &&
this.name === data.Name &&
this.pimadIdentifier != undefined &&
JSON.stringify(this.services) === JSON.stringify(data.Services));
return this.initialized;
}
else {
return false;
}
}
}
class BasePEA extends APEA {
}
/* Factories */
class APEAFactory {
}
class BasePEAFactory extends APEAFactory {
create() {
return new BasePEA();
}
}
exports.BasePEAFactory = BasePEAFactory;