Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #128 from mdrillin/TTOOLS-358
Browse files Browse the repository at this point in the history
TEIIDTOOLS-358 Adapt UI to connection schema
  • Loading branch information
mdrillin committed Apr 18, 2018
2 parents 13a1f49 + b4454b8 commit 15a969a
Show file tree
Hide file tree
Showing 35 changed files with 868 additions and 1,407 deletions.
89 changes: 89 additions & 0 deletions ngapp/src/app/connections/shared/connection-table.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @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 { Connection } from "@connections/shared/connection.model";

export class ConnectionTable {
private keng__id: string;
private connection: Connection;
private isSelected = false;

/**
* @param {Object} json the JSON representation of a ConnectionTable
* @returns {ConnectionTable} the new ConnectionTable (never null)
*/
public static create( json: object = {} ): ConnectionTable {
const connTable = new ConnectionTable();
connTable.setValues( json );
return connTable;
}

constructor() {
// nothing to do
}

/**
* @returns {string} the property id
*/
public getId(): string {
return this.keng__id;
}

/**
* @returns {Connection} the connection
*/
public getConnection(): Connection {
return this.connection;
}

/**
* @param {string} id the property id
*/
public setId( id?: string ): void {
this.keng__id = id ? id : null;
}

/**
* @param {Connection} conn the connection
*/
public setConnection( conn?: Connection ): void {
this.connection = conn ? conn : null;
}

/**
* @returns {boolean} true if selected
*/
public get selected(): boolean {
return this.isSelected;
}

/**
* @param {boolean} selected 'true' if selected
*/
public set selected( selected: boolean ) {
this.isSelected = selected;
}

/**
* Set all object values using the supplied View json
* @param {Object} values
*/
public setValues(values: object = {}): void {
Object.assign(this, values);
}

}
55 changes: 55 additions & 0 deletions ngapp/src/app/connections/shared/connection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { ConnectionStatus } from "@connections/shared/connection-status";
import { VdbsConstants } from "@dataservices/shared/vdbs-constants";
import { Identifiable } from "@shared/identifiable";
import { SortDirection } from "@shared/sort-direction.enum";

Expand Down Expand Up @@ -250,6 +251,33 @@ export class Connection implements Identifiable< string > {
return this.status.isServerVdbMissing();
}

/**
* @returns {string} the connection schema vdb name
*/
public get schemaVdbName(): string {
if (this.status && !(this.status == null)) {
return this.status.getSchemaVdbName();
}
return this.deriveSchemaVdbName();
}

/**
* @returns {string} the connection schema vdb model name
*/
public get schemaVdbModelName(): string {
if (this.status && !(this.status == null)) {
return this.status.getSchemaModelName();
}
return this.deriveSchemaVdbModelName();
}

/**
* @returns {string} the connection schema vdb model source name
*/
public get schemaVdbModelSourceName(): string {
return this.deriveSchemaVdbModelSourceName();
}

/**
* @param {string} driverName the connection driver name (optional)
*/
Expand Down Expand Up @@ -308,4 +336,31 @@ export class Connection implements Identifiable< string > {
Object.assign(this, values);
}

/**
* Derive the schema VDB name for this connection
* @returns {string} the default schema VDB name
*/
private deriveSchemaVdbName( ): string {
const name = this.getId() + VdbsConstants.SCHEMA_VDB_SUFFIX;
return name.toLowerCase();
}

/**
* Derive the schema VDB model name for this connection
* @returns {string} the default schema VDB model name
*/
private deriveSchemaVdbModelName( ): string {
const name = this.getId() + VdbsConstants.SCHEMA_MODEL_SUFFIX;
return name.toLowerCase();
}

/**
* Derive the schema VDB model source name for this connection
* @returns {string}
*/
private deriveSchemaVdbModelSourceName( ): string {
return this.getServiceCatalogSourceName() ?
this.getServiceCatalogSourceName() : this.getId().toLowerCase();
}

}
76 changes: 10 additions & 66 deletions ngapp/src/app/connections/shared/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@
import { Injectable } from "@angular/core";
import { Http, RequestOptions } from "@angular/http";
import { ConnectionStatus } from "@connections/shared/connection-status";
import { ConnectionTable } from "@connections/shared/connection-table.model";
import { ConnectionType } from "@connections/shared/connection-type.model";
import { ConnectionsConstants } from "@connections/shared/connections-constants";
import { JdbcTableFilter } from "@connections/shared/jdbc-table-filter.model";
import { NewConnection } from "@connections/shared/new-connection.model";
import { SchemaInfo } from "@connections/shared/schema-info.model";
import { ServiceCatalogSource } from "@connections/shared/service-catalog-source.model";
import { TemplateDefinition } from "@connections/shared/template-definition.model";
import { ApiService } from "@core/api.service";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { ConnectionSummary } from "@dataservices/shared/connection-summary.model";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { Table } from "@dataservices/shared/table.model";
import { VdbService } from "@dataservices/shared/vdb.service";
import { environment } from "@environments/environment";
import { PropertyDefinition } from "@shared/property-form/property-definition.model";
import { Observable } from "rxjs/Observable";
import { Subscription } from "rxjs/Subscription";

Expand Down Expand Up @@ -217,70 +213,18 @@ export class ConnectionService extends ApiService {
}

/**
* Get the connection templates from the komodo rest interface
* @returns {Observable<TemplateDefinition[]>}
* Get the tables for the specified connection. The connection must be ACTIVE, otherwise the tables
* will be empty.
* @param {string} connectionId the connection id
* @returns {Observable<ConnectionTable[]>}
*/
public getConnectionTemplates(): Observable<TemplateDefinition[]> {
public getConnectionTables(connectionId: string): Observable<ConnectionTable[]> {
return this.http
.get( environment.komodoTeiidUrl + "/templates", this.getAuthRequestOptions())
.get( environment.komodoWorkspaceUrl + ConnectionsConstants.connectionsRootPath
+ "/" + connectionId + "/tables", this.getAuthRequestOptions())
.map((response) => {
const templates = response.json();
return templates.map((template) => TemplateDefinition.create( template ));
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Get the connection template property definitions from the komodo rest interface
* @param {string} templateName
* @returns {Observable<Array<PropertyDefinition<any>>>}
*/
public getConnectionTemplateProperties(templateName: string): Observable<Array<PropertyDefinition<any>>> {
return this.http
.get( environment.komodoTeiidUrl + "/templates/" + templateName + "/entries", this.getAuthRequestOptions())
.map((response) => {
const entries = response.json() as Array<PropertyDefinition<any>>;
return entries.map((entry) => PropertyDefinition.create( entry ));
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Get the schema infos for a Jdbc Connection
* @param {string} connectionId
* @returns {Observable<SchemaInfo[]>}
*/
public getConnectionSchemaInfos(connectionId: string): Observable<SchemaInfo[]> {
return this.http
.get( environment.komodoTeiidUrl + "/connections/" + connectionId + "/JdbcCatalogSchema", this.getAuthRequestOptions())
.map((response) => {
const infos = response.json();
return infos.map((info) => SchemaInfo.create( info ));
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Get the tables for the specified input (connection and filters) for a Jdbc Connection
* @param {JdbcTableFilter} tableFilter
* @returns {Observable<string>}
*/
public getJdbcConnectionTables(tableFilter: JdbcTableFilter): Observable<string[]> {
return this.http
.post( environment.komodoTeiidUrl + "/connections/Tables", tableFilter, this.getAuthRequestOptions())
.map((response) => {
const info = response.json();
const tableNames = [];
let i = 1;
let tableKey = "Table" + i;
let tableName = info.Information[tableKey];
while ( tableName && tableName.length > 0 ) {
tableNames.push(tableName);
i++;
tableKey = "Table" + i;
tableName = info.Information[tableKey];
}
return tableNames;
const connTables = response.json();
return connTables.map((connTable) => ConnectionTable.create( connTable ));
})
.catch( ( error ) => this.handleError( error ) );
}
Expand Down
34 changes: 9 additions & 25 deletions ngapp/src/app/connections/shared/mock-connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

import { Injectable, ReflectiveInjector } from "@angular/core";
import { Http } from "@angular/http";
import { ConnectionTable } from "@connections/shared/connection-table.model";
import { Connection } from "@connections/shared/connection.model";
import { ConnectionService } from "@connections/shared/connection.service";
import { JdbcTableFilter } from "@connections/shared/jdbc-table-filter.model";
import { NewConnection } from "@connections/shared/new-connection.model";
import { SchemaInfo } from "@connections/shared/schema-info.model";
import { ServiceCatalogSource } from "@connections/shared/service-catalog-source.model";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
Expand All @@ -34,15 +33,13 @@ import "rxjs/add/observable/throw";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/map";
import { Observable } from "rxjs/Observable";
import {ConnectionStatus} from "@connections/shared/connection-status";

@Injectable()
export class MockConnectionService extends ConnectionService {

private connections: Connection[];
private serviceCatalogSources: ServiceCatalogSource[];
private connectionSourceSchemaInfoMap: Map<string, SchemaInfo[]>;
private tableMap = new Map<string, string[]>();
private connectionTableMap = new Map<string, ConnectionTable[]>();
private testDataService: TestDataService;

constructor( http: Http, vdbService: VdbService, notifierService: NotifierService,
Expand All @@ -61,8 +58,7 @@ export class MockConnectionService extends ConnectionService {
}
this.connections = conns;
this.serviceCatalogSources = this.testDataService.getServiceCatalogSources();
this.connectionSourceSchemaInfoMap = this.testDataService.getConnectionSourceSchemaInfoMap();
this.tableMap = this.testDataService.getJdbcConnectionTableMap();
this.connectionTableMap = this.testDataService.getConnectionTableMap();
}

public isValidName( name: string ): Observable< string > {
Expand Down Expand Up @@ -124,25 +120,12 @@ export class MockConnectionService extends ConnectionService {
}

/**
* Get the connection schema info for a connection source
* @returns {Observable<SchemaInfo[]>}
* Get the tables for the specified Connection
* @param {string} connectionName the connection name
* @returns {Observable<ConnectionTable[]>}
*/
public getConnectionSchemaInfos( connSource: string): Observable< SchemaInfo[] > {
const schemaInfos: SchemaInfo[] = this.connectionSourceSchemaInfoMap.get(connSource);
if ( !schemaInfos || schemaInfos == null ) {
const empty: SchemaInfo[] = [];
return Observable.of( empty );
}
return Observable.of(schemaInfos);
}

/**
* Get the tables for the specified input (connection and filters) for a Jdbc Connection
* @param {JdbcTableFilter} tableFilter
* @returns {Observable<string>}
*/
public getJdbcConnectionTables( tableFilter: JdbcTableFilter ): Observable< string[] > {
return Observable.of( this.tableMap.get( tableFilter.getSchemaFilter() ) );
public getConnectionTables( connectionName: string ): Observable< ConnectionTable[] > {
return Observable.of( this.connectionTableMap.get( connectionName ) );
}

/**
Expand Down Expand Up @@ -180,6 +163,7 @@ export class MockConnectionService extends ConnectionService {
* Updates the current Connection schema states - triggers update to be broadcast to interested components
*/
public updateConnectionSchemaStates(): void {
// Nothing to do
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
(onCancel)="cancelClicked($event)"
(onNext)="nextClicked($event)"
(onStepChange)="stepChanged($event)">
<!-- ------------------------- -->
<!-- Step 1 : Table Selection -->
<!-- ------------------------- -->
<!-- ----------------------------------- -->
<!-- Step 1 : Connection Table Selection -->
<!-- ----------------------------------- -->
<pfng-wizard-step [config]="step1Config">
<div class="row">
<div class="col-sm-12">
Expand Down Expand Up @@ -68,7 +68,7 @@ <h3><i>{{ step2InstructionMessage }}</i></h3>
<div class="col-sm-7 wiz-review-tables">
<div [ngClass]="shouldCheck(table) ? 'wiz-review-table-checked' : 'wiz-review-table-unchecked'"
*ngFor="let table of dataserviceSourceTables">
{{ table.getName() }} ( {{ table.getConnection().getId() }} <span class="fa fa-plug"></span> )
{{ table.getId() }} ( {{ table.getConnection().getId() }} <span class="fa fa-plug"></span> )
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppSettingsService } from "@core/app-settings.service";
import { CoreModule } from "@core/core.module";
import { MockAppSettingsService } from "@core/mock-app-settings.service";
import { ConnectionTableSelectorComponent } from "@dataservices/connection-table-selector/connection-table-selector.component";
import { JdbcTableSelectorComponent } from "@dataservices/jdbc-table-selector/jdbc-table-selector.component";
import { RelationalTableSelectorComponent } from "@dataservices/relational-table-selector/relational-table-selector.component";
import { SelectedTableComponent } from "@dataservices/selected-table/selected-table.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.service";
Expand All @@ -28,7 +28,7 @@ describe("AddDataserviceWizardComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, FormsModule, PatternFlyNgModule, ReactiveFormsModule, RouterTestingModule ],
declarations: [ AddDataserviceWizardComponent, ConnectionTableSelectorComponent, JdbcTableSelectorComponent,
declarations: [ AddDataserviceWizardComponent, ConnectionTableSelectorComponent, RelationalTableSelectorComponent,
PropertyFormComponent, PropertyFormPropertyComponent, SelectedTableComponent ],
providers: [
NotifierService, WizardService,
Expand Down

0 comments on commit 15a969a

Please sign in to comment.