This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
mock-connection.service.ts
152 lines (133 loc) · 5.43 KB
/
mock-connection.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* @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, ReflectiveInjector } from "@angular/core";
import { Http } from "@angular/http";
import { Connection } from "@connections/shared/connection.model";
import { ConnectionService } from "@connections/shared/connection.service";
import { JdbcTableFilter } from "@connections/shared/jdbc-table-filter.model";
import { SchemaInfo } from "@connections/shared/schema-info.model";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import "rxjs/add/observable/of";
import "rxjs/add/observable/throw";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/map";
import { Observable } from "rxjs/Observable";
import { ServiceCatalogSource } from "@connections/shared/service-catalog-source.model";
import { NewConnection } from "@connections/shared/new-connection.model";
import { TestDataService } from "@shared/test-data.service";
@Injectable()
export class MockConnectionService extends ConnectionService {
private connections: Connection[];
private serviceCatalogSources: ServiceCatalogSource[];
private connectionSourceSchemaInfoMap: Map<string, SchemaInfo[]>;
constructor( http: Http, appSettings: AppSettingsService, logger: LoggerService ) {
super(http, appSettings, logger);
// Inject service for test data
let injector = ReflectiveInjector.resolveAndCreate([TestDataService]);
const testDataService = injector.get(TestDataService);
// Get test data
this.connections = testDataService.getConnections();
this.serviceCatalogSources = testDataService.getServiceCatalogSources();
this.connectionSourceSchemaInfoMap = testDataService.getConnectionSourceSchemaInfoMap();
}
public isValidName( name: string ): Observable< string > {
if ( !name || name.length === 0 ) {
return Observable.of( "Connection name cannot be empty" );
}
// make sure no dataservice exists with that name
for ( const conn of this.connections ) {
if ( conn.getId() === name ) {
return Observable.of( "Connection with that name already exists" );
}
}
// just implement a case where no special characters allowed
for ( let i = 0; i < name.length; i++ ) {
const c = name.charAt( i );
// special characters have the same upper and lower case values
if ( c.toUpperCase() === c.toLowerCase() ) {
return Observable.of( "No special characters allowed" );
}
}
// valid
return Observable.of( "" );
}
/**
* Get the connections from the komodo rest interface
* @returns {Observable<Connection[]>}
*/
public getAllConnections(): Observable<Connection[]> {
return Observable.of(this.connections);
}
/**
* Delete a connection via the komodo rest interface
* @param {string} connectionId
* @returns {Observable<boolean>}
*/
public deleteConnection(connectionId: string): Observable<boolean> {
const size = this.connections.length;
this.connections = this.connections.filter( ( conn ) => conn.getId() !== connectionId );
return Observable.of( size === this.connections.length );
}
/**
* Get the available ServiceCatalogSources from the komodo rest interface
* @returns {Observable<ServiceCatalogSource[]>}
*/
public getAllServiceCatalogSources(): Observable<ServiceCatalogSource[]> {
return Observable.of(this.serviceCatalogSources);
}
/**
* Get the connection schema info for a connection source
* @returns {Observable<SchemaInfo[]>}
*/
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[] > {
const tableNames = [];
tableNames.push( "table1" );
tableNames.push( "table2" );
tableNames.push( "table3" );
return Observable.of( tableNames );
}
/**
* Create a connection in the Komodo repo - also binds the specified serviceCatalogSource
* @param {NewConnection} connection the connection object
* @returns {Observable<boolean>}
*/
public createAndBindConnection(connection: NewConnection): Observable<boolean> {
return Observable.of(true);
}
/**
* Update a connection in the Komodo repo - also binds the specified serviceCatalogSource.
* @param {NewConnection} connection the connection object
* @returns {Observable<boolean>}
*/
public updateAndBindConnection(connection: NewConnection): Observable<boolean> {
return Observable.of(true);
}
}