diff --git a/src/plugins/condition/ConditionSetCompositionPolicy.js b/src/plugins/condition/ConditionSetCompositionPolicy.js index 4755656b90..d1eb08422f 100644 --- a/src/plugins/condition/ConditionSetCompositionPolicy.js +++ b/src/plugins/condition/ConditionSetCompositionPolicy.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * diff --git a/src/plugins/condition/ConditionSetCompositionPolicySpec.js b/src/plugins/condition/ConditionSetCompositionPolicySpec.js index 9a9424785d..eac168f808 100644 --- a/src/plugins/condition/ConditionSetCompositionPolicySpec.js +++ b/src/plugins/condition/ConditionSetCompositionPolicySpec.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * diff --git a/src/plugins/condition/ConditionSetViewProvider.js b/src/plugins/condition/ConditionSetViewProvider.js index 958c41af5b..267f10718c 100644 --- a/src/plugins/condition/ConditionSetViewProvider.js +++ b/src/plugins/condition/ConditionSetViewProvider.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index bfc38e2877..e8950334e3 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * @@ -24,38 +24,51 @@ import * as EventEmitter from 'eventemitter3'; export default class TelemetryCriterion extends EventEmitter { - constructor(telemetryDomainObjectKey, openmct) { + /** + * Subscribes/Unsubscribes to telemetry and emits the result + * of operations performed on the telemetry data returned and a given input value. + * @constructor + * @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} } + * @param openmct + */ + constructor(telemetryDomainObjectDefinition, openmct) { super(); this.openmct = openmct; - this.telemetryObject = this.openmct.objects.get(this.openmct.objects.makeKeyString(telemetryDomainObjectKey)); + this.objectAPI = this.openmct.objects; this.telemetryAPI = this.openmct.telemetry; + this.id = telemetryDomainObjectDefinition.id; this.subscription = null; this.telemetryMetadata = null; this.telemetryObjectIdAsString = null; - if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) { - this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier); - } + this.objectAPI.get(this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.key)).then((obj) => this.initialize(obj)); + } + + initialize(obj) { + this.telemetryObject = obj; + this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier); + this.telemetryMetadata = this.telemetryAPI.getMetadata(this.telemetryObject.identifier); + this.emitEvent('criterionUpdated', this); } handleSubscription(datum) { - //data is telemetry values, error - //how do I get data here? - this.emitResult(this.normalizeData(datum)); + let data = this.normalizeData(datum); + this.emitEvent('criterionResultUpdated', { + result: data, + error: null + }) } - //TODO: Revisit this logic normalizeData(datum) { return { [datum.key]: datum[datum.source] } } - emitResult(data, error) { - this.emit('criterionUpdated', { - identifier: this.telemetryObjectIdAsString, - data: data, - error: error + emitEvent(eventName, data) { + this.emit(eventName, { + id: this.id, + data: data }); } @@ -77,7 +90,7 @@ export default class TelemetryCriterion extends EventEmitter { this.subscription(); } delete this.subscription; - this.emit('criterion::Remove', this.telemetryObjectIdAsString); + this.emitEvent('criterionRemoved'); delete this.telemetryObjectIdAsString; delete this.telemetryObject; delete this.telemetryMetadata; diff --git a/src/plugins/condition/criterion/TelemetryCriterionSpec.js b/src/plugins/condition/criterion/TelemetryCriterionSpec.js index 7218279e8b..007a0fc0b6 100644 --- a/src/plugins/condition/criterion/TelemetryCriterionSpec.js +++ b/src/plugins/condition/criterion/TelemetryCriterionSpec.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * @@ -24,6 +24,8 @@ import TelemetryCriterion from "./TelemetryCriterion"; let openmct = {}, mockListener, + mockListener2, + testCriterionDefinition, testTelemetryObject, telemetryCriterion; @@ -51,25 +53,40 @@ describe("The telemetry criterion", function () { } }; openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']); - openmct.objects.get.and.returnValue(testTelemetryObject); + openmct.objects.get.and.returnValue(new Promise(function (resolve, reject) { + resolve(testTelemetryObject); + })); openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key); - openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe"]); + openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe", "getMetadata"]); openmct.telemetry.isTelemetryObject.and.returnValue(true); openmct.telemetry.subscribe.and.returnValue(function () {}); + openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values); + + testCriterionDefinition = { + id: 'test-criterion-id', + key: openmct.objects.makeKeyString(testTelemetryObject.identifier) + }; mockListener = jasmine.createSpy('listener'); + mockListener2 = jasmine.createSpy('updatedListener', (data) => { + console.log(data); + }); telemetryCriterion = new TelemetryCriterion( - testTelemetryObject.identifier, + testCriterionDefinition, openmct ); - telemetryCriterion.on('criterionUpdated', mockListener); + telemetryCriterion.on('criterionResultUpdated', mockListener); + telemetryCriterion.on('criterionUpdated', mockListener2); }); it("initializes with a telemetry objectId as string", function () { + telemetryCriterion.initialize(testTelemetryObject); expect(telemetryCriterion.telemetryObjectIdAsString).toEqual(testTelemetryObject.identifier.key); + expect(telemetryCriterion.telemetryMetadata.length).toEqual(2); + expect(mockListener2).toHaveBeenCalled(); }); it("subscribes to telemetry providers", function () { @@ -89,13 +106,13 @@ describe("The telemetry criterion", function () { }); it("emits update event on new data from telemetry providers", function () { - spyOn(telemetryCriterion, 'emitResult').and.callThrough(); + spyOn(telemetryCriterion, 'emitEvent').and.callThrough(); telemetryCriterion.handleSubscription({ key: 'some-key', source: 'testSource', testSource: 'Hello' }); - expect(telemetryCriterion.emitResult).toHaveBeenCalled(); + expect(telemetryCriterion.emitEvent).toHaveBeenCalled(); expect(mockListener).toHaveBeenCalled(); }); diff --git a/src/plugins/condition/plugin.js b/src/plugins/condition/plugin.js index 5bd700f99f..11c4f9a14f 100644 --- a/src/plugins/condition/plugin.js +++ b/src/plugins/condition/plugin.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. * diff --git a/src/plugins/condition/pluginSpec.js b/src/plugins/condition/pluginSpec.js index 5df6d196dd..66bd66485a 100644 --- a/src/plugins/condition/pluginSpec.js +++ b/src/plugins/condition/pluginSpec.js @@ -1,5 +1,5 @@ /***************************************************************************** - * Open MCT, Copyright (c) 2014-2019, United States Government + * Open MCT, Copyright (c) 2014-2020, United States Government * as represented by the Administrator of the National Aeronautics and Space * Administration. All rights reserved. *