Addresses code review comments (#2624)

* Addresses code review comments
- Change copyright to 2020
- Fix class parameters, tests

* Fixes this for initilize function
This commit is contained in:
Shefali Joshi 2020-01-16 15:56:58 -08:00 committed by Pegah Sarram
parent 8df549e8d9
commit a554aa20f8
7 changed files with 58 additions and 28 deletions

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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;

View File

@ -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();
});

View File

@ -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.
*

View File

@ -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.
*