This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
mock-dataservice.service.ts
215 lines (184 loc) · 7.75 KB
/
mock-dataservice.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
* @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, Response } from "@angular/http";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { Dataservice } from "@dataservices/shared/dataservice.model";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { NewDataservice } from "@dataservices/shared/new-dataservice.model";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { QueryResults } from "@dataservices/shared/query-results.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";
import "rxjs/add/operator/map";
import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";
@Injectable()
export class MockDataserviceService extends DataserviceService {
private readonly services: Dataservice[];
private readonly queryResults: QueryResults;
private editorViewStateMap = new Map<string, ViewEditorState>();
private selectedDs: Dataservice;
constructor(http: Http, vdbService: VdbService, appSettings: AppSettingsService,
notifierService: NotifierService, logger: LoggerService ) {
super(http, vdbService, appSettings, notifierService, logger);
// Inject service for test data
const injector = ReflectiveInjector.resolveAndCreate([TestDataService]);
const testDataService = injector.get(TestDataService);
// Get test data
this.services = testDataService.getDataservices();
this.queryResults = testDataService.getQueryResults();
this.editorViewStateMap = testDataService.getViewEditorStateMap();
}
/**
* Get the dataservices from the komodo rest interface
* @returns {Observable<Dataservice[]>}
*/
public getAllDataservices(): Observable<Dataservice[]> {
return Observable.of(this.services);
}
/**
* Create a dataservice via the komodo rest interface
* @param {NewDataservice} dataservice
* @returns {Observable<boolean>}
*/
public createDataservice(dataservice: NewDataservice): Observable<boolean> {
const ds = new Dataservice();
ds.setId( dataservice.getId() );
ds.setDescription( dataservice.getDescription() );
this.services.push( ds );
return Observable.of(true);
}
/**
* Delete a dataservice via the komodo rest interface
* @param {string} dataserviceId
* @returns {Observable<boolean>}
*/
public deleteDataservice(dataserviceId: string): Observable<boolean> {
return Observable.of(true);
}
public downloadDataservice( dataserviceName: string ): Observable< boolean > {
alert( "Download of " + dataserviceName + " happens here" );
return Observable.of( true );
}
/**
* Query a Dataservice via the komodo rest interface
* @param {string} query the SQL query
* @param {string} dataserviceName the dataservice name
* @param {number} limit the limit for the number of result rows
* @param {number} offset the offset for the result rows
* @returns {Observable<boolean>}
*/
public queryDataservice(query: string, dataserviceName: string, limit: number, offset: number): Observable<any> {
return Observable.of(this.queryResults);
}
protected handleError(error: Response): ErrorObservable {
return Observable.throw(error);
}
public createReadonlyDataRole( dataserviceName: string,
model1Name: string ): Observable< boolean > {
return Observable.of( true );
}
public isValidName( name: string ): Observable<string> {
if ( !name || name.length === 0 ) {
return Observable.of( "Data virtualization name cannot be empty" );
}
// make sure no dataservice exists with that name
for ( const ds of this.services ) {
if ( ds.getId() === name ) {
return Observable.of( "Data virtualization 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( "" );
}
public setServiceVdbForSingleSourceTables( dataserviceName: string,
tablePaths: string[],
modelSourcePath: string ): Observable< boolean > {
return Observable.of( true );
}
/**
* @param {ViewEditorState} editorState the view editor state
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorState( editorState: ViewEditorState ): Observable< boolean > {
return Observable.of(true);
}
/**
* @param {string} editorId the ID of the editor state being requested
* @returns {Observable<ViewEditorState>} the view editor state or empty object if not found
*/
public getViewEditorState( editorId: string ): Observable< ViewEditorState > {
return Observable.of(this.editorViewStateMap.get(editorId));
}
/**
* @param {string} editorStatePattern the editorState name pattern
* @returns {Observable<ViewEditorState[]>} the view editor state array
*/
public getViewEditorStates( editorStatePattern?: string ): Observable< ViewEditorState[] > {
const editorStates = [];
this.editorViewStateMap.forEach( ( value, key ) => {
if (editorStatePattern && editorStatePattern.length > 0) {
// Just match the first few chars with this test method
const patternTrimmed = editorStatePattern.substring(0, 5);
const keyTrimmed = key.substring(0, 5);
if (keyTrimmed.startsWith(patternTrimmed)) {
editorStates.push(value);
}
} else {
editorStates.push(value);
}
} );
return Observable.of(editorStates);
}
/**
* @param {string} editorId the ID of the editor state being deleted
* @returns {Observable<boolean>} `true` if the editor state was successfully deleted
*/
public deleteViewEditorState( editorId: string ): Observable< boolean > {
return Observable.of(true);
}
/**
* @param {ViewEditorState} editorState the view editor state
* @param {string} dataserviceName the name of the dataservice
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorStateRefreshViews( editorState: ViewEditorState, dataserviceName: string ): Observable< boolean > {
return Observable.of(true);
}
/**
* @param {string} editorId the ID of the editor state being deleted
* @param {string} dataserviceName the name of the dataservice
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public deleteViewEditorStateRefreshViews( editorId: string, dataserviceName: string ): Observable< boolean > {
return Observable.of(true);
}
}