diff --git a/ngapp/src/app/connections/shared/mock-connection.service.ts b/ngapp/src/app/connections/shared/mock-connection.service.ts index bce12830..40be1850 100644 --- a/ngapp/src/app/connections/shared/mock-connection.service.ts +++ b/ngapp/src/app/connections/shared/mock-connection.service.ts @@ -43,7 +43,7 @@ export class MockConnectionService extends ConnectionService { super(http, appSettings, logger); // Inject service for test data - let injector = ReflectiveInjector.resolveAndCreate([TestDataService]); + const injector = ReflectiveInjector.resolveAndCreate([TestDataService]); const testDataService = injector.get(TestDataService); // Get test data diff --git a/ngapp/src/app/dataservices/dataservices-cards/dataservice-card/dataservice-card.component.ts b/ngapp/src/app/dataservices/dataservices-cards/dataservice-card/dataservice-card.component.ts index 0eb742cf..0d19023d 100644 --- a/ngapp/src/app/dataservices/dataservices-cards/dataservice-card/dataservice-card.component.ts +++ b/ngapp/src/app/dataservices/dataservices-cards/dataservice-card/dataservice-card.component.ts @@ -107,13 +107,7 @@ export class DataserviceCardComponent implements DoCheck, OnInit { * @returns {string[]} the names of the views */ public getViews(): string[] { - const result: string[] = []; - - for (const viewName of this.dataservice.getServiceViewNames()) { - result.push(viewName); - } - - return result; + return this.dataservice.getServiceViewNames(); } /** diff --git a/ngapp/src/app/dataservices/shared/dataservice.model.ts b/ngapp/src/app/dataservices/shared/dataservice.model.ts index a14a5be7..39981abc 100644 --- a/ngapp/src/app/dataservices/shared/dataservice.model.ts +++ b/ngapp/src/app/dataservices/shared/dataservice.model.ts @@ -116,10 +116,10 @@ export class Dataservice implements Identifiable< string > { */ public getServiceViewNames(): string[] { if ( this.serviceViews ) { - this.serviceViews = []; + return this.serviceViews; } - return this.serviceViews; + return []; } /** diff --git a/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts b/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts index d4c297f3..d1339972 100644 --- a/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts +++ b/ngapp/src/app/dataservices/shared/mock-dataservice.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Injectable } from "@angular/core"; +import { Injectable, ReflectiveInjector } from "@angular/core"; import { Http, Response } from "@angular/http"; import { AppSettingsService } from "@core/app-settings.service"; import { LoggerService } from "@core/logger.service"; @@ -25,6 +25,7 @@ import { NewDataservice } from "@dataservices/shared/new-dataservice.model"; import { NotifierService } from "@dataservices/shared/notifier.service"; import { Table } from "@dataservices/shared/table.model"; import { VdbService } from "@dataservices/shared/vdb.service"; +import { TestDataService } from "@shared/test-data.service"; import "rxjs/add/observable/of"; import "rxjs/add/observable/throw"; import "rxjs/add/operator/catch"; @@ -35,28 +36,18 @@ import { ErrorObservable } from "rxjs/observable/ErrorObservable"; @Injectable() export class MockDataserviceService extends DataserviceService { - private serv1 = new Dataservice(); - private serv2 = new Dataservice(); - private serv3 = new Dataservice(); - private services: Dataservice[] = [this.serv1, this.serv2, this.serv3]; + private services: Dataservice[]; constructor(http: Http, vdbService: VdbService, appSettings: AppSettingsService, notifierService: NotifierService, logger: LoggerService ) { super(http, vdbService, appSettings, notifierService, logger); - this.serv1.setId("serv1"); - this.serv1.setServiceViewTables(["table1", "table2"]); - this.serv1.setServiceViewModel("viewModel"); - const viewNames: string[] = []; - viewNames.push("views"); - this.serv1.setServiceViewNames(viewNames); - this.serv2.setId("serv2"); - this.serv2.setServiceViewTables(["table1", "table2"]); - this.serv2.setServiceViewModel("viewModel"); - this.serv2.setServiceViewNames(viewNames); - this.serv3.setId("serv3"); - this.serv3.setServiceViewTables(["table1", "table2"]); - this.serv3.setServiceViewModel("viewModel"); - this.serv3.setServiceViewNames(viewNames); + + // Inject service for test data + const injector = ReflectiveInjector.resolveAndCreate([TestDataService]); + const testDataService = injector.get(TestDataService); + + // Get test data + this.services = testDataService.getDataservices(); } /** @@ -89,14 +80,14 @@ export class MockDataserviceService extends DataserviceService { public deleteDataservice(dataserviceId: string): Observable { return Observable.of(true); } - - /** - * Get the current Dataservice selection - * @returns {Dataservice} the selected Dataservice - */ - public getSelectedDataservice( ): Dataservice { - return this.serv1; - } + // + // /** + // * Get the current Dataservice selection + // * @returns {Dataservice} the selected Dataservice + // */ + // public getSelectedDataservice( ): Dataservice { + // return this.serv1; + // } /** * Get the views for the selected Dataservice diff --git a/ngapp/src/app/dataservices/shared/mock-vdb.service.ts b/ngapp/src/app/dataservices/shared/mock-vdb.service.ts index 2559480a..0c145d3e 100644 --- a/ngapp/src/app/dataservices/shared/mock-vdb.service.ts +++ b/ngapp/src/app/dataservices/shared/mock-vdb.service.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Injectable } from "@angular/core"; +import { Injectable, ReflectiveInjector } from "@angular/core"; import { Http } from "@angular/http"; import { AppSettingsService } from "@core/app-settings.service"; import { LoggerService } from "@core/logger.service"; @@ -26,6 +26,7 @@ import { VdbModel } from "@dataservices/shared/vdb-model.model"; import { VdbStatus } from "@dataservices/shared/vdb-status.model"; import { Vdb } from "@dataservices/shared/vdb.model"; import { VdbService } from "@dataservices/shared/vdb.service"; +import { TestDataService } from "@shared/test-data.service"; import "rxjs/add/observable/of"; import "rxjs/add/observable/throw"; import "rxjs/add/operator/catch"; @@ -35,32 +36,19 @@ import { Observable } from "rxjs/Observable"; @Injectable() export class MockVdbService extends VdbService { - private vdb1 = new Vdb(); - private vdb2 = new Vdb(); - private vdb3 = new Vdb(); - private vdbs: Vdb[] = [this.vdb1, this.vdb2, this.vdb3]; - - private vdbStatus1 = new VdbStatus(); - private vdbStatus2 = new VdbStatus(); - private vdbStatus3 = new VdbStatus(); - private statuses: VdbStatus[] = [this.vdbStatus1, this.vdbStatus3, this.vdbStatus3]; + private vdbs: Vdb[]; + private statuses: VdbStatus[]; constructor(http: Http, appSettings: AppSettingsService, notifierService: NotifierService, logger: LoggerService ) { super(http, appSettings, notifierService, logger); - this.vdb1.setId("serv1"); - this.vdbStatus1.setName( "serv1" ); - this.vdbStatus1.setLoading( false ); - this.vdbStatus1.setActive( true ); - - this.vdb2.setId("serv2"); - this.vdbStatus2.setName("serv2"); - this.vdbStatus2.setLoading( false ); - this.vdbStatus2.setActive( true ); - - this.vdb3.setId("serv3"); - this.vdbStatus3.setName("serv2"); - this.vdbStatus3.setLoading( false ); - this.vdbStatus3.setActive( true ); + + // Inject service for test data + const injector = ReflectiveInjector.resolveAndCreate([TestDataService]); + const testDataService = injector.get(TestDataService); + + // Get test data + this.statuses = testDataService.getVdbStatuses(); + this.vdbs = testDataService.getVdbs(); } /** diff --git a/ngapp/src/app/shared/test-data.service.ts b/ngapp/src/app/shared/test-data.service.ts index 8bfdc62a..b9e92aef 100644 --- a/ngapp/src/app/shared/test-data.service.ts +++ b/ngapp/src/app/shared/test-data.service.ts @@ -1,9 +1,28 @@ -import { Injectable } from '@angular/core'; -import {Connection} from "@connections/shared/connection.model"; -import {ServiceCatalogSource} from "@connections/shared/service-catalog-source.model"; -import {MockConnectionService} from "@connections/shared/mock-connection.service"; -import {Observable} from "rxjs/Observable"; -import {SchemaInfo} from "@connections/shared/schema-info.model"; +/** + * @license + * Copyright 2017 JBoss Inc + * + * 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. + */ + +import { Injectable } from "@angular/core"; +import { Connection } from "@connections/shared/connection.model"; +import { SchemaInfo } from "@connections/shared/schema-info.model"; +import { ServiceCatalogSource } from "@connections/shared/service-catalog-source.model"; +import { Dataservice } from "@dataservices/shared/dataservice.model"; +import { DeploymentState } from "@dataservices/shared/deployment-state.enum"; +import { VdbStatus } from "@dataservices/shared/vdb-status.model"; +import { Vdb } from "@dataservices/shared/vdb.model"; @Injectable() export class TestDataService { @@ -12,6 +31,88 @@ export class TestDataService { private static catalogSourceId2 = "postgresql-persistent-a8xrt"; private static catalogSourceId3 = "mysql-persistent-t3irv"; + // ================================================================= + // VDBs + // ================================================================= + + private static accountsVdb = Vdb.create( + { + keng__id: "AccountsVDB", + vdb__description: "This is an accounts VDB.", + keng__dataPath: "/path/in/repository/AccountsVDB", + keng__kType: "Vdb", + vdb__name: "AccountsVDB", + vdb__originalFile: "/Users/dsbUser/vdbs/accounts.vdb", + vdb__preview: false, + vdb__version: "1" + }, + ); + + private static accountsVdbStatus = VdbStatus.create( + { + name: TestDataService.accountsVdb.getName(), + deployedName: TestDataService.accountsVdb.getName() + "-vdb.xml", + version: TestDataService.accountsVdb.getVersion(), + active: true, + loading: false, + failed: false, + errors: [ + ] + } + ); + + private static employeesVdb = Vdb.create( + { + keng__id: "EmployeesVDB", + vdb__description: "This is an employees VDB.", + keng__dataPath: "/path/in/repository/EmployeesVDB", + keng__kType: "Vdb", + vdb__name: "EmployeesVDB", + vdb__originalFile: "/Users/dsbUser/vdbs/employees.vdb", + vdb__preview: false, + vdb__version: "1" + }, + ); + + private static employeesVdbStatus = VdbStatus.create( + { + name: TestDataService.employeesVdb.getName(), + deployedName: TestDataService.employeesVdb.getName() + "-vdb.xml", + version: TestDataService.employeesVdb.getVersion(), + active: true, + loading: false, + failed: false, + errors: [ + ] + } + ); + + private static productsVdb = Vdb.create( + { + keng__id: "ProductsVDB", + vdb__description: "This is a products VDB.", + keng__dataPath: "/path/in/repository/ProductsVDB", + keng__kType: "Vdb", + vdb__name: "ProductsVDB", + vdb__originalFile: "/Users/dsbUser/vdbs/products.vdb", + vdb__preview: false, + vdb__version: "1" + }, + ); + + private static productsVdbStatus = VdbStatus.create( + { + name: TestDataService.productsVdb.getName(), + deployedName: TestDataService.productsVdb.getName() + "-vdb.xml", + version: TestDataService.productsVdb.getVersion(), + active: true, + loading: false, + failed: false, + errors: [ + ] + } + ); + // ================================================================= // ServiceCatalog DataSources // ================================================================= @@ -31,10 +132,6 @@ export class TestDataService { "mysql", true ); - private catalogSources: ServiceCatalogSource[] = [TestDataService.catalogSource1, - TestDataService.catalogSource2, - TestDataService.catalogSource3]; - // ================================================================= // Connections // ================================================================= @@ -45,10 +142,6 @@ export class TestDataService { private static conn2 = TestDataService.createConnection(TestDataService.connId2, TestDataService.catalogSource2 ); private static conn3 = TestDataService.createConnection(TestDataService.connId3, TestDataService.catalogSource3 ); - private connections: Connection[] = [TestDataService.conn1, - TestDataService.conn2, - TestDataService.conn3]; - // ================================================================= // SchemaInfos for the connections // ================================================================= @@ -70,32 +163,127 @@ export class TestDataService { SchemaInfo.create( { name: "conn3SchemaInfo2", type: "Schema" } ) ]; - constructor() { } + // ================================================================= + // Dataservices + // ================================================================= - /** - * @returns {Connection[]} the array of test connections - */ - public getConnections(): Connection[] { - return this.connections; - } + private static accountsService = Dataservice.create( + { + keng__id: "Accounts", + tko__description: "A dataservice for accounts.", + serviceVdbName: TestDataService.accountsVdb.getName(), + serviceVdbVersion: TestDataService.accountsVdb.getVersion(), + serviceViews: [ + "AcctView1", + "AcctView2" + ], + serviceViewModel: "AccountsViewModel", + serviceViewTables: [ + "AcctView1Table1", + "AcctView1Table2", + "AcctView1Table3", + "AcctView2Table1" + ], + deploymentState: DeploymentState.LOADING + } + ); - /** - * @returns {ServiceCatalogSource[]} the array of test Service Catalog datasources - */ - public getServiceCatalogSources(): ServiceCatalogSource[] { - return this.catalogSources; - } + private static employeesService = Dataservice.create( + { + keng__id: "Employees", + tko__description: "A dataservice for employees.", + serviceVdbName: TestDataService.employeesVdb.getName(), + serviceVdbVersion: TestDataService.employeesVdb.getVersion(), + serviceViews: [ + "EmpView1", + "EmpView2", + "EmpView3", + "EmpView4" + ], + serviceViewModel: "EmployeesViewModel", + serviceViewTables: [ + "EmpView1Table1", + "EmpView2Table1", + "EmpView2Table2", + "EmpView3Table1", + "EmpView3Table2", + "EmpView3Table3", + "EmpView4Table1", + "EmpView4Table2", + "EmpView4Table3", + "EmpView4Table4" + ], + deploymentState: DeploymentState.LOADING + } + ); - /** - * @returns {Map} the array of test Service Catalog datasources - */ - public getConnectionSourceSchemaInfoMap( ): Map { - const infoMap = new Map(); - infoMap.set( TestDataService.conn1.getServiceCatalogSourceName(), TestDataService.conn1SchemaInfos ); - infoMap.set( TestDataService.conn2.getServiceCatalogSourceName(), TestDataService.conn2SchemaInfos ); - infoMap.set( TestDataService.conn3.getServiceCatalogSourceName(), TestDataService.conn3SchemaInfos ); - return infoMap; - } + private static productsService = Dataservice.create( + { + keng__id: "Products", + tko__description: "A dataservice for products. These are really good products. These products are the best products money can buy.", + serviceVdbName: TestDataService.productsVdb.getName(), + serviceVdbVersion: TestDataService.productsVdb.getVersion(), + serviceViews: [ + "ProdView1", + "ProdView2", + "ProdView3", + "ProdView4", + "ProdView5", + "ProdView6" + ], + serviceViewModel: "ProductsViewModel", + serviceViewTables: [ + "ProdView1Table1", + "ProdView2Table1", + "ProdView2Table2", + "ProdView3Table1", + "ProdView3Table2", + "ProdView3Table3", + "ProdView4Table1", + "ProdView4Table2", + "ProdView4Table3", + "ProdView4Table4", + "ProdView5Table1", + "ProdView5Table2", + "ProdView5Table3", + "ProdView5Table4", + "ProdView5Table5", + "ProdView6Table1", + "ProdView6Table2", + "ProdView6Table3", + "ProdView6Table4", + "ProdView6Table5", + "ProdView6Table6" + ], + deploymentState: DeploymentState.LOADING + } + ); + + private catalogSources: ServiceCatalogSource[] = [TestDataService.catalogSource1, + TestDataService.catalogSource2, + TestDataService.catalogSource3]; + + private connections: Connection[] = [TestDataService.conn1, + TestDataService.conn2, + TestDataService.conn3]; + + private dataServices: Dataservice[] = [ + TestDataService.accountsService, + TestDataService.employeesService, + TestDataService.productsService + ]; + + private vdbs: Vdb[] = [ + TestDataService.accountsVdb, + TestDataService.employeesVdb, + TestDataService.productsVdb + ]; + + private vdbStatuses: VdbStatus[] = [ + TestDataService.accountsVdbStatus, + TestDataService.employeesVdbStatus, + TestDataService.productsVdbStatus + ]; /** * Create a connection of the specified id using the supplied ServiceCatalogSource @@ -108,7 +296,7 @@ export class TestDataService { newConn.setId( id ); const driverName = serviceCatalogSource.getType(); newConn.setDriverName( driverName ); - if( driverName === 'mysql' || driverName === 'postgresql') { + if ( driverName === "mysql" || driverName === "postgresql") { newConn.setJdbc( true ); } else { newConn.setJdbc( false ); @@ -126,7 +314,7 @@ export class TestDataService { * @param {boolean} bound 'true' if bound * @returns {ServiceCatalogSource} */ - private static createServiceCatalogSource( id: string, name: string, type: string, bound: boolean ) { + private static createServiceCatalogSource( id: string, name: string, type: string, bound: boolean ): ServiceCatalogSource { const catalogSource = new ServiceCatalogSource(); catalogSource.setId(id); catalogSource.setName(name); @@ -135,4 +323,54 @@ export class TestDataService { return catalogSource; } + constructor() { + // nothing to do + } + + /** + * @returns {Connection[]} the array of test connections + */ + public getConnections(): Connection[] { + return this.connections; + } + + /** + * @returns {ServiceCatalogSource[]} the array of test Service Catalog datasources + */ + public getServiceCatalogSources(): ServiceCatalogSource[] { + return this.catalogSources; + } + + /** + * @returns {Map} the array of test Service Catalog datasources + */ + public getConnectionSourceSchemaInfoMap( ): Map { + const infoMap = new Map(); + infoMap.set( TestDataService.conn1.getServiceCatalogSourceName(), TestDataService.conn1SchemaInfos ); + infoMap.set( TestDataService.conn2.getServiceCatalogSourceName(), TestDataService.conn2SchemaInfos ); + infoMap.set( TestDataService.conn3.getServiceCatalogSourceName(), TestDataService.conn3SchemaInfos ); + return infoMap; + } + + /** + * @returns {Dataservice[]} the array of test dataservices + */ + public getDataservices(): Dataservice[] { + return this.dataServices; + } + + /** + * @returns {Vdb[]} the VDB collection + */ + public getVdbs(): Vdb[] { + return this.vdbs; + } + + /** + * @returns {VdbStatus[]} the VDB status collection + */ + public getVdbStatuses(): VdbStatus[] { + return this.vdbStatuses; + } + }