From 62962e119ef254187cb0f22a66cc9de4913cdae6 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 10 Sep 2015 15:18:24 -0700 Subject: [PATCH] [Time Controller] Decorate telemetry service Decorate telemetry service instead of capability service to enforce time conductor bounds. WTD-1515. --- platform/features/conductor/bundle.json | 4 +- .../src/ConductorTelemetryCapability.js | 81 -------------- ...ator.js => ConductorTelemetryDecorator.js} | 50 +++++---- .../test/ConductorCapabilityDecoratorSpec.js | 101 ----------------- .../test/ConductorTelemetryCapabilitySpec.js | 105 ------------------ platform/features/conductor/test/suite.json | 2 - 6 files changed, 31 insertions(+), 312 deletions(-) delete mode 100644 platform/features/conductor/src/ConductorTelemetryCapability.js rename platform/features/conductor/src/{ConductorCapabilityDecorator.js => ConductorTelemetryDecorator.js} (54%) delete mode 100644 platform/features/conductor/test/ConductorCapabilityDecoratorSpec.js delete mode 100644 platform/features/conductor/test/ConductorTelemetryCapabilitySpec.js diff --git a/platform/features/conductor/bundle.json b/platform/features/conductor/bundle.json index 39d45628bb..b230f9d370 100644 --- a/platform/features/conductor/bundle.json +++ b/platform/features/conductor/bundle.json @@ -9,8 +9,8 @@ "components": [ { "type": "decorator", - "provides": "capabilityService", - "implementation": "ConductorCapabilityDecorator.js", + "provides": "telemetryService", + "implementation": "ConductorTelemetryDecorator.js", "depends": [ "conductorService" ] } ], diff --git a/platform/features/conductor/src/ConductorTelemetryCapability.js b/platform/features/conductor/src/ConductorTelemetryCapability.js deleted file mode 100644 index ca9a18a24b..0000000000 --- a/platform/features/conductor/src/ConductorTelemetryCapability.js +++ /dev/null @@ -1,81 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ -/*global define*/ - -define( - [], - function () { - 'use strict'; - - /** - * Wrapper for the `telemetry` capability which adds start/end - * times to all requests based on the current state of a time - * conductor. - * - * @constructor - * @memberof platform/features/conductor - * @augments {platform/telemetry.TelemetryCapability} - * @param {platform/features/conductor.TimeConductor} timeConductor - * the time conductor which controls these queries - * @param {platform/telemetry.TelemetryCapability} telemetryCapability - * the wrapped capability - */ - function ConductorTelemetryCapability(timeConductor, telemetryCapability) { - this.timeConductor = timeConductor; - this.wrappedCapability = telemetryCapability; - } - - ConductorTelemetryCapability.prototype.amendRequest = function (request) { - request = request || {}; - - // This isn't really the right check, but it happens to distinguish - // plots (which want to query for the full set of data for easy - // panning) from views like fixed position, which only want the - // single latest data point. - if (request.size !== undefined) { - request.start = this.timeConductor.displayStart(); - request.end = this.timeConductor.displayEnd(); - } else { - request.start = this.timeConductor.queryStart(); - request.end = this.timeConductor.queryEnd(); - } - - return request; - }; - - ConductorTelemetryCapability.prototype.getMetadata = function () { - return this.wrappedCapability.getMetadata(); - }; - - ConductorTelemetryCapability.prototype.requestData = function (request) { - request = this.amendRequest(request); - return this.wrappedCapability.requestData(request); - }; - - ConductorTelemetryCapability.prototype.subscribe = function (callback, request) { - request = this.amendRequest(request); - return this.wrappedCapability.subscribe(callback, request); - }; - - return ConductorTelemetryCapability; - } -); diff --git a/platform/features/conductor/src/ConductorCapabilityDecorator.js b/platform/features/conductor/src/ConductorTelemetryDecorator.js similarity index 54% rename from platform/features/conductor/src/ConductorCapabilityDecorator.js rename to platform/features/conductor/src/ConductorTelemetryDecorator.js index 7c6ba46133..6d75125b7a 100644 --- a/platform/features/conductor/src/ConductorCapabilityDecorator.js +++ b/platform/features/conductor/src/ConductorTelemetryDecorator.js @@ -22,43 +22,51 @@ /*global define*/ define( - ['./ConductorTelemetryCapability'], - function (ConductorTelemetryCapability) { + [], + function () { 'use strict'; /** - * Decorates the `capabilityService` such that any exposed `telemetry` - * capabilities have their requests mediated by the time conductor. + * Decorates the `telemetryService` such that requests are + * mediated by the time conductor. * * @constructor * @memberof platform/features/conductor - * @implements {CapabilityService} + * @implements {TelemetryService} * @param {platform/features/conductor.ConductorService} conductorServe * the service which exposes the global time conductor - * @param {CapabilityService} capabilityService the decorated service + * @param {TelemetryService} telemetryService the decorated service */ - function ConductorCapabilityDecorator(conductorService, capabilityService) { + function ConductorTelemetryDecorator(conductorService, telemetryService) { this.conductorService = conductorService; - this.capabilityService = capabilityService; + this.telemetryService = telemetryService; } - ConductorCapabilityDecorator.prototype.getCapabilities = function (model) { - var capabilities = this.capabilityService.getCapabilities(model), - TelemetryCapability = capabilities.telemetry, - conductorService = this.conductorService; + ConductorTelemetryDecorator.prototype.amendRequests = function (requests) { + var conductor = this.conductorService.getConductor(), + start = conductor.displayStart(), + end = conductor.displayEnd(); - if (TelemetryCapability) { - capabilities.telemetry = function (domainObject) { - return new ConductorTelemetryCapability( - conductorService.getConductor(), - new TelemetryCapability(domainObject) - ); - }; + function amendRequest(request) { + request = request || {}; + request.start = start; + request.end = end; + return request; } - return capabilities; + return (requests || []).map(amendRequest); }; - return ConductorCapabilityDecorator; + ConductorTelemetryDecorator.prototype.requestTelemetry = function (requests) { + return this.telemetryService + .requestTelemetry(this.amendRequests(requests)); + }; + + ConductorTelemetryDecorator.prototype.subscribe = function (callback, requests) { + return this.telemetryService + .subscribe(callback, this.amendRequests(requests)); + }; + + return ConductorTelemetryDecorator; } ); diff --git a/platform/features/conductor/test/ConductorCapabilityDecoratorSpec.js b/platform/features/conductor/test/ConductorCapabilityDecoratorSpec.js deleted file mode 100644 index b98270148b..0000000000 --- a/platform/features/conductor/test/ConductorCapabilityDecoratorSpec.js +++ /dev/null @@ -1,101 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ -/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ - -/** - * EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015. - */ -define( - ["../src/ConductorCapabilityDecorator"], - function (ConductorCapabilityDecorator) { - "use strict"; - - describe("ConductorCapabilityDecorator", function () { - var mockCapabilityService, - mockConductorService, - testModel, - testCapabilities, - decorator; - - function instantiate(Constructor) { - return new Constructor(); - } - - beforeEach(function () { - testCapabilities = { - telemetry: jasmine.createSpy('Telemetry'), - other: jasmine.createSpy('Other') - }; - - mockCapabilityService = jasmine.createSpyObj( - 'capabilityService', - [ 'getCapabilities' ] - ); - mockConductorService = jasmine.createSpyObj( - 'conductorService', - [ 'getConductor' ] - ); - testModel = { someKey: "some value" }; - - mockCapabilityService.getCapabilities.andCallFake(function () { - // Wrap with object.create so we can still - // reliably expect properties of testCapabilities itself - return Object.create(testCapabilities); - }); - - decorator = new ConductorCapabilityDecorator( - mockConductorService, - mockCapabilityService - ); - }); - - it("delegates to the decorated capability service", function () { - expect(mockCapabilityService.getCapabilities).not.toHaveBeenCalled(); - decorator.getCapabilities(testModel); - expect(mockCapabilityService.getCapabilities).toHaveBeenCalled(); - }); - - it("wraps the 'telemetry' capability of objects", function () { - var capabilities = decorator.getCapabilities(testModel); - expect(capabilities.telemetry) - .not.toBe(testCapabilities.telemetry); - - // Should wrap - verify by invocation - expect(testCapabilities.telemetry).not.toHaveBeenCalled(); - instantiate(capabilities.telemetry); - expect(testCapabilities.telemetry).toHaveBeenCalled(); - }); - - it("does not wrap other capabilities", function () { - var capabilities = decorator.getCapabilities(testModel); - expect(capabilities.other) - .toBe(testCapabilities.other); - }); - - it("gets a time conductor from the conductorService", function () { - expect(mockConductorService.getConductor).not.toHaveBeenCalled(); - instantiate(decorator.getCapabilities(testModel).telemetry); - expect(mockConductorService.getConductor).toHaveBeenCalled(); - }); - }); - } -); diff --git a/platform/features/conductor/test/ConductorTelemetryCapabilitySpec.js b/platform/features/conductor/test/ConductorTelemetryCapabilitySpec.js deleted file mode 100644 index 2cc30229bc..0000000000 --- a/platform/features/conductor/test/ConductorTelemetryCapabilitySpec.js +++ /dev/null @@ -1,105 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ -/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ - -/** - * EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015. - */ -define( - ["../src/ConductorTelemetryCapability"], - function (ConductorTelemetryCapability) { - "use strict"; - - describe("ConductorTelemetryCapability", function () { - var mockConductor, - mockTelemetryCapability, - mockUnsubscribe, - testMetadata, - testStartTime, - testEndTime, - conductorTelemetryCapability; - - beforeEach(function () { - mockConductor = jasmine.createSpyObj( - 'timeConductor', - [ - 'queryStart', - 'queryEnd', - 'displayStart', - 'displayEnd' - ] - ); - mockTelemetryCapability = jasmine.createSpyObj( - 'telemetry', - [ 'getMetadata', 'requestData', 'subscribe' ] - ); - mockUnsubscribe = jasmine.createSpy('unsubscribe'); - - testStartTime = 42; - testEndTime = 12321; - testMetadata = { someKey: 'some value' }; - mockTelemetryCapability.getMetadata.andReturn(testMetadata); - mockTelemetryCapability.subscribe.andReturn(mockUnsubscribe); - mockConductor.queryStart.andReturn(testStartTime); - mockConductor.queryEnd.andReturn(testEndTime); - - conductorTelemetryCapability = new ConductorTelemetryCapability( - mockConductor, - mockTelemetryCapability - ); - }); - - it("simply delegates getMetadata calls", function () { - expect(conductorTelemetryCapability.getMetadata()) - .toBe(testMetadata); - }); - - it("adds start/end times to requests", function () { - conductorTelemetryCapability - .requestData({ someKey: "some value" }); - expect(mockTelemetryCapability.requestData).toHaveBeenCalledWith({ - someKey: "some value", - start: testStartTime, - end: testEndTime - }); - }); - - it("adds start/end times to subscribe calls", function () { - var mockCallback = jasmine.createSpy('callback'), - testRequest = { someKey: "some value" }; - expect(conductorTelemetryCapability.subscribe( - mockCallback, - testRequest - )).toBe(mockUnsubscribe); - expect(mockTelemetryCapability.subscribe).toHaveBeenCalledWith( - mockCallback, - { - someKey: "some value", - start: testStartTime, - end: testEndTime - } - ); - }); - - }); - } -); diff --git a/platform/features/conductor/test/suite.json b/platform/features/conductor/test/suite.json index 85a155c5df..d4d291e4d7 100644 --- a/platform/features/conductor/test/suite.json +++ b/platform/features/conductor/test/suite.json @@ -1,7 +1,5 @@ [ - "ConductorCapabilityDecorator", "ConductorRepresenter", "ConductorService", - "ConductorTelemetryCapability", "TimeConductor" ]