From 59c5430579159dd6f7859a3d4f01c790096a78b3 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Sat, 16 Sep 2017 09:37:48 -0700 Subject: [PATCH 1/2] [Generator] API Compatibility The telemetry API does not pass request options for subscriptions, updated generator provider to match this API. fixes https://github.com/nasa/openmct/issues/1705 --- example/generator/GeneratorProvider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/generator/GeneratorProvider.js b/example/generator/GeneratorProvider.js index 5b3bea87e2..ee1b7ded24 100644 --- a/example/generator/GeneratorProvider.js +++ b/example/generator/GeneratorProvider.js @@ -78,8 +78,8 @@ define([ return this.workerInterface.request(workerRequest); }; - GeneratorProvider.prototype.subscribe = function (domainObject, callback, request) { - var workerRequest = this.makeWorkerRequest(domainObject, request); + GeneratorProvider.prototype.subscribe = function (domainObject, callback) { + var workerRequest = this.makeWorkerRequest(domainObject, {}); return this.workerInterface.subscribe(workerRequest, callback); }; From ae5ef334878dd9eded27ad86fe3b113914470032 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Sat, 16 Sep 2017 09:54:53 -0700 Subject: [PATCH 2/2] [Plot] Update policy to detect any range Update policy to detect any range. As a simple way to prevent detecting messages, it will not apply when every range is a string format. fixes https://github.com/nasa/openmct/issues/1713 --- platform/features/plot/bundle.js | 5 +- .../plot/src/policies/PlotViewPolicy.js | 33 ++++----- .../plot/test/policies/PlotViewPolicySpec.js | 72 ++++++++++++------- 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/platform/features/plot/bundle.js b/platform/features/plot/bundle.js index 13aeb29129..7309197c0a 100644 --- a/platform/features/plot/bundle.js +++ b/platform/features/plot/bundle.js @@ -118,7 +118,10 @@ define([ "policies": [ { "category": "view", - "implementation": PlotViewPolicy + "implementation": PlotViewPolicy, + "depends": [ + "openmct" + ] } ], "representations": [ diff --git a/platform/features/plot/src/policies/PlotViewPolicy.js b/platform/features/plot/src/policies/PlotViewPolicy.js index b6f86d32f2..ed9c221d7e 100644 --- a/platform/features/plot/src/policies/PlotViewPolicy.js +++ b/platform/features/plot/src/policies/PlotViewPolicy.js @@ -30,30 +30,25 @@ define( * @constructor * @memberof platform/features/plot */ - function PlotViewPolicy() { + function PlotViewPolicy(openmct) { + this.openmct = openmct; } - function hasNumericTelemetry(domainObject) { - var telemetry = domainObject && - domainObject.getCapability('telemetry'), - metadata = telemetry ? telemetry.getMetadata() : {}, - ranges = metadata.ranges || []; - - // Generally, we want to allow Plot for telemetry-providing - // objects (most telemetry is plottable.) We only want to - // suppress this for telemetry which only has explicitly - // non-numeric values. - return ranges.length === 0 || ranges.some(function (range) { - // Assume format is numeric if it is undefined - // (numeric telemetry is the common case) - return range.format === undefined || - range.format === 'number'; - }); - } + PlotViewPolicy.prototype.hasNumericTelemetry = function (domainObject) { + var adaptedObject = domainObject.useCapability('adapter'); + var metadata = this.openmct.telemetry.getMetadata(adaptedObject); + var rangeValues = metadata.valuesForHints(['range']); + if (rangeValues.length === 0) { + return false; + } + return !rangeValues.every(function (value) { + return value.format === 'string'; + }); + }; PlotViewPolicy.prototype.allow = function (view, domainObject) { if (view.key === 'plot') { - return hasNumericTelemetry(domainObject); + return this.hasNumericTelemetry(domainObject); } return true; diff --git a/platform/features/plot/test/policies/PlotViewPolicySpec.js b/platform/features/plot/test/policies/PlotViewPolicySpec.js index 83b24104b8..194b49cb66 100644 --- a/platform/features/plot/test/policies/PlotViewPolicySpec.js +++ b/platform/features/plot/test/policies/PlotViewPolicySpec.js @@ -27,51 +27,71 @@ define( describe("Plot view policy", function () { var testView, mockDomainObject, - mockTelemetry, - testMetadata, + openmct, + telemetryMetadata, policy; beforeEach(function () { testView = { key: "plot" }; - testMetadata = {}; mockDomainObject = jasmine.createSpyObj( 'domainObject', - ['getId', 'getModel', 'getCapability'] + ['useCapability'] ); - mockTelemetry = jasmine.createSpyObj( - 'telemetry', - ['getMetadata'] - ); - mockDomainObject.getCapability.andCallFake(function (c) { - return c === 'telemetry' ? mockTelemetry : undefined; - }); - mockTelemetry.getMetadata.andReturn(testMetadata); - - policy = new PlotViewPolicy(); + mockDomainObject.useCapability.andReturn('adaptedObject'); + openmct = { + telemetry: jasmine.createSpyObj('telemetryAPI', [ + 'getMetadata' + ]) + }; + telemetryMetadata = jasmine.createSpyObj('telemetryMetadata', [ + 'valuesForHints' + ]); + telemetryMetadata.valuesForHints.andReturn([]); + openmct.telemetry.getMetadata.andReturn(telemetryMetadata); + policy = new PlotViewPolicy(openmct); }); - it("allows the imagery view for domain objects with numeric telemetry", function () { - testMetadata.ranges = [{ key: "foo", format: "number" }]; - expect(policy.allow(testView, mockDomainObject)).toBeTruthy(); + it('fetches metadata from telem api', function () { + policy.allow(testView, mockDomainObject); + expect(mockDomainObject.useCapability) + .toHaveBeenCalledWith('adapter'); + expect(openmct.telemetry.getMetadata) + .toHaveBeenCalledWith('adaptedObject'); + expect(telemetryMetadata.valuesForHints) + .toHaveBeenCalledWith(['range']); }); - it("allows the imagery view for domain objects with unspecified telemetry", function () { - testMetadata.ranges = [{ key: "foo" }]; - expect(policy.allow(testView, mockDomainObject)).toBeTruthy(); + it('returns false if no ranges exist', function () { + telemetryMetadata.valuesForHints.andReturn([]); + expect(policy.allow(testView, mockDomainObject)).toBe(false); }); - it("disallows the imagery view for domain objects without image telemetry", function () { - testMetadata.ranges = [{ key: "foo", format: "somethingElse" }]; - expect(policy.allow(testView, mockDomainObject)).toBeFalsy(); + it('returns true if any ranges exist', function () { + telemetryMetadata.valuesForHints.andReturn([{}]); + expect(policy.allow(testView, mockDomainObject)).toBe(true); + }); + + it('returns false if all ranges are strings', function () { + telemetryMetadata.valuesForHints.andReturn([{ + format: 'string' + }, { + format: 'string' + }]); + expect(policy.allow(testView, mockDomainObject)).toBe(false); + }); + + it('returns true if only some ranges are strings', function () { + telemetryMetadata.valuesForHints.andReturn([{ + format: 'string' + }, {}]); + expect(policy.allow(testView, mockDomainObject)).toBe(true); }); it("allows other views", function () { testView.key = "somethingElse"; - testMetadata.ranges = [{ key: "foo", format: "somethingElse" }]; - expect(policy.allow(testView, mockDomainObject)).toBeTruthy(); + expect(policy.allow(testView, mockDomainObject)).toBe(true); }); }); } ); -