mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 09:58:52 +00:00
Merge pull request #2784 from nasa/fix-conditionals
Fixes error while getting metadata when telemetry is not yet available for a criterion
This commit is contained in:
commit
311ff003c0
@ -92,6 +92,7 @@ export default class ConditionClass extends EventEmitter {
|
||||
return {
|
||||
id: uuid(),
|
||||
telemetry: criterionConfiguration.telemetry || '',
|
||||
telemetryObject: this.conditionManager.telemetryObjects[this.openmct.objects.makeKeyString(criterionConfiguration.telemetry)],
|
||||
operation: criterionConfiguration.operation || '',
|
||||
input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input,
|
||||
metadata: criterionConfiguration.metadata || ''
|
||||
@ -109,6 +110,12 @@ export default class ConditionClass extends EventEmitter {
|
||||
this.createCriteria(criterionConfigurations);
|
||||
}
|
||||
|
||||
updateTelemetry() {
|
||||
this.criteria.forEach((criterion) => {
|
||||
criterion.updateTelemetry(this.conditionManager.telemetryObjects);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* adds criterion to the condition.
|
||||
*/
|
||||
@ -209,7 +216,7 @@ export default class ConditionClass extends EventEmitter {
|
||||
|
||||
requestLADConditionResult() {
|
||||
const criteriaResults = this.criteria
|
||||
.map(criterion => criterion.requestLAD());
|
||||
.map(criterion => criterion.requestLAD({telemetryObjects: this.conditionManager.telemetryObjects}));
|
||||
|
||||
return Promise.all(criteriaResults)
|
||||
.then(results => {
|
||||
|
@ -36,6 +36,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
this.composition.on('remove', this.unsubscribeFromTelemetry, this);
|
||||
this.compositionLoad = this.composition.load();
|
||||
this.subscriptions = {};
|
||||
this.telemetryObjects = {};
|
||||
this.initialize();
|
||||
|
||||
this.stopObservingForChanges = this.openmct.objects.observe(this.conditionSetDomainObject, '*', (newDomainObject) => {
|
||||
@ -49,11 +50,12 @@ export default class ConditionManager extends EventEmitter {
|
||||
console.log('subscription already exists');
|
||||
return;
|
||||
}
|
||||
|
||||
this.telemetryObjects[id] = Object.assign({}, endpoint, {telemetryMetaData: this.openmct.telemetry.getMetadata(endpoint).valueMetadatas});
|
||||
this.subscriptions[id] = this.openmct.telemetry.subscribe(
|
||||
endpoint,
|
||||
this.broadcastTelemetry.bind(this, id)
|
||||
);
|
||||
this.updateConditionTelemetry();
|
||||
}
|
||||
|
||||
unsubscribeFromTelemetry(endpointIdentifier) {
|
||||
@ -65,6 +67,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
|
||||
this.subscriptions[id]();
|
||||
delete this.subscriptions[id];
|
||||
delete this.telemetryObjects[id];
|
||||
}
|
||||
|
||||
initialize() {
|
||||
@ -77,6 +80,10 @@ export default class ConditionManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
updateConditionTelemetry() {
|
||||
this.conditionClassCollection.forEach((condition) => condition.updateTelemetry());
|
||||
}
|
||||
|
||||
updateCondition(conditionConfiguration, index) {
|
||||
let condition = this.conditionClassCollection[index];
|
||||
condition.update(conditionConfiguration);
|
||||
@ -255,7 +262,15 @@ export default class ConditionManager extends EventEmitter {
|
||||
}
|
||||
|
||||
broadcastTelemetry(id, datum) {
|
||||
this.emit(`broadcastTelemetry`, Object.assign({}, datum, {id: id}));
|
||||
this.emit(`broadcastTelemetry`, Object.assign({}, this.createNormalizedDatum(datum, id), {id: id}));
|
||||
}
|
||||
|
||||
createNormalizedDatum(telemetryDatum, id) {
|
||||
return Object.values(this.telemetryObjects[id].telemetryMetaData).reduce((normalizedDatum, metadatum) => {
|
||||
const formatter = this.openmct.telemetry.getValueFormatter(metadatum);
|
||||
normalizedDatum[metadatum.key] = formatter.parse(telemetryDatum[metadatum.source]);
|
||||
return normalizedDatum;
|
||||
}, {});
|
||||
}
|
||||
|
||||
persistConditions() {
|
||||
|
@ -62,6 +62,9 @@ describe("The condition", function () {
|
||||
}]
|
||||
}
|
||||
};
|
||||
conditionManager.telemetryObjects = {
|
||||
"test-object": testTelemetryObject
|
||||
};
|
||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
||||
openmct.objects.get.and.returnValue(new Promise(function (resolve, reject) {
|
||||
resolve(testTelemetryObject);
|
||||
|
@ -44,28 +44,25 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
this.operation = telemetryDomainObjectDefinition.operation;
|
||||
this.input = telemetryDomainObjectDefinition.input;
|
||||
this.metadata = telemetryDomainObjectDefinition.metadata;
|
||||
this.telemetryObjectIdAsString = undefined;
|
||||
this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj));
|
||||
}
|
||||
|
||||
initialize(obj) {
|
||||
this.telemetryObject = obj;
|
||||
this.telemetryMetaData = this.openmct.telemetry.getMetadata(obj).valueMetadatas;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetry);
|
||||
this.telemetryObject = telemetryDomainObjectDefinition.telemetryObject;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.telemetry);
|
||||
this.on(`subscription:${this.telemetryObjectIdAsString}`, this.handleSubscription);
|
||||
this.emitEvent('criterionUpdated', this);
|
||||
}
|
||||
|
||||
formatData(data) {
|
||||
const normalizedDatum = this.createNormalizedDatum(data);
|
||||
const datum = {
|
||||
result: this.computeResult(normalizedDatum)
|
||||
}
|
||||
updateTelemetry(telemetryObjects) {
|
||||
this.telemetryObject = telemetryObjects[this.telemetryObjectIdAsString];
|
||||
}
|
||||
|
||||
if (normalizedDatum) {
|
||||
formatData(data) {
|
||||
const datum = {
|
||||
result: this.computeResult(data)
|
||||
};
|
||||
|
||||
if (data) {
|
||||
// TODO check back to see if we should format times here
|
||||
this.timeAPI.getAllTimeSystems().forEach(timeSystem => {
|
||||
datum[timeSystem.key] = normalizedDatum[timeSystem.key]
|
||||
datum[timeSystem.key] = data[timeSystem.key]
|
||||
});
|
||||
}
|
||||
return datum;
|
||||
@ -77,13 +74,6 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
createNormalizedDatum(telemetryDatum) {
|
||||
return Object.values(this.telemetryMetaData).reduce((normalizedDatum, metadatum) => {
|
||||
normalizedDatum[metadatum.key] = telemetryDatum[metadatum.source];
|
||||
return normalizedDatum;
|
||||
}, {});
|
||||
}
|
||||
|
||||
findOperation(operation) {
|
||||
for (let i=0, ii=OPERATIONS.length; i < ii; i++) {
|
||||
if (operation === OPERATIONS[i].name) {
|
||||
|
@ -24,7 +24,6 @@ import TelemetryCriterion from "./TelemetryCriterion";
|
||||
|
||||
let openmct = {},
|
||||
mockListener,
|
||||
mockListener2,
|
||||
testCriterionDefinition,
|
||||
testTelemetryObject,
|
||||
telemetryCriterion;
|
||||
@ -60,9 +59,6 @@ describe("The telemetry criterion", function () {
|
||||
}
|
||||
};
|
||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
||||
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", "getMetadata"]);
|
||||
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||
@ -80,13 +76,11 @@ describe("The telemetry criterion", function () {
|
||||
id: 'test-criterion-id',
|
||||
telemetry: openmct.objects.makeKeyString(testTelemetryObject.identifier),
|
||||
operation: 'lessThan',
|
||||
metadata: 'sin'
|
||||
metadata: 'sin',
|
||||
telemetryObject: testTelemetryObject
|
||||
};
|
||||
|
||||
mockListener = jasmine.createSpy('listener');
|
||||
mockListener2 = jasmine.createSpy('updatedListener', (data) => {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
telemetryCriterion = new TelemetryCriterion(
|
||||
testCriterionDefinition,
|
||||
@ -94,18 +88,14 @@ describe("The telemetry criterion", function () {
|
||||
);
|
||||
|
||||
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(mockListener2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates and emits event on new data from telemetry providers", function () {
|
||||
telemetryCriterion.initialize(testTelemetryObject);
|
||||
spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
|
||||
telemetryCriterion.handleSubscription({
|
||||
value: 'Hello',
|
||||
|
@ -268,15 +268,17 @@ export default {
|
||||
this.openmct.contextMenu._showContextMenuForObjectPath(this.currentObjectPath, event.x, event.y, CONTEXT_MENU_ACTIONS);
|
||||
},
|
||||
initObjectStyles() {
|
||||
this.styleRuleManager = new StyleRuleManager(this.domainObject.configuration.objectStyles, this.openmct, this.updateStyle.bind(this));
|
||||
if (this.domainObject.configuration) {
|
||||
this.styleRuleManager = new StyleRuleManager(this.domainObject.configuration.objectStyles, this.openmct, this.updateStyle.bind(this));
|
||||
|
||||
if (this.unlistenStyles) {
|
||||
this.unlistenStyles();
|
||||
if (this.unlistenStyles) {
|
||||
this.unlistenStyles();
|
||||
}
|
||||
this.unlistenStyles = this.openmct.objects.observe(this.domainObject, 'configuration.objectStyles', (newObjectStyle) => {
|
||||
//Updating object styles in the inspector view will trigger this so that the changes are reflected immediately
|
||||
this.styleRuleManager.updateObjectStyleConfig(newObjectStyle);
|
||||
});
|
||||
}
|
||||
this.unlistenStyles = this.openmct.objects.observe(this.domainObject, 'configuration.objectStyles', (newObjectStyle) => {
|
||||
//Updating object styles in the inspector view will trigger this so that the changes are reflected immediately
|
||||
this.styleRuleManager.updateObjectStyleConfig(newObjectStyle);
|
||||
});
|
||||
},
|
||||
updateStyle(styleObj) {
|
||||
let keys = Object.keys(styleObj);
|
||||
|
Loading…
Reference in New Issue
Block a user