This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
dataservice.model.ts
319 lines (276 loc) · 8.74 KB
/
dataservice.model.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/**
* @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 { DeploymentState } from "@dataservices/shared/deployment-state.enum";
import { PublishState } from "@dataservices/shared/publish-state.enum";
import { Virtualization } from "@dataservices/shared/virtualization.model";
import { Identifiable } from "@shared/identifiable";
import { SortDirection } from "@shared/sort-direction.enum";
export class Dataservice implements Identifiable< string > {
private keng__id: string;
private tko__description: string;
private serviceVdbName: string;
private serviceVdbVersion: string;
private serviceViews: string[];
private serviceViewModel: string;
private serviceViewTables: string[];
private deploymentState: DeploymentState = DeploymentState.LOADING;
private virtualization: Virtualization = null;
/**
* @param {Object} json the JSON representation of a Dataservice
* @returns {Dataservice} the new Dataservice (never null)
*/
public static create( json: object = {} ): Dataservice {
const svc = new Dataservice();
svc.setValues( json );
return svc;
}
/**
* @param {Dataservice[]} dataservices the dataservices being sorted
* @param {SortDirection} sortDirection the sort direction
*/
public static sort( dataservices: Dataservice[],
sortDirection: SortDirection ): void {
dataservices.sort( ( thisDataservice: Dataservice, thatDataservice: Dataservice ) => {
const result = thisDataservice.compareTo( thatDataservice );
if ( sortDirection === SortDirection.DESC ) {
return result * -1;
}
return result;
} );
}
constructor( ) {
// nothing to do
}
/**
* See {Identifiable}.
*/
public compareTo( that: Dataservice ): number {
let result = 0;
if ( this.getId() ) {
if ( that.getId() ) {
// both have an ID
result = this.getId().localeCompare( that.getId() );
} else {
// thatItem does not have an ID
result = 1;
}
} else if ( that.getId() ) {
// thisItem does not have an ID and thatItem does
result = -1;
}
return result;
}
/**
* @returns {string} the dataservice identifier (can be null)
*/
public getId(): string {
return this.keng__id;
}
/**
* @returns {string} the dataservice description (can be null)
*/
public getDescription(): string {
return this.tko__description;
}
/**
* @returns {string} the dataservice Vdb name (can be null)
*/
public getServiceVdbName(): string {
return this.serviceVdbName;
}
/**
* @returns {string} the dataservice Vdb version (can be null)
*/
public getServiceVdbVersion(): string {
return this.serviceVdbVersion;
}
/**
* @returns {string[]} the dataservice view names (never null or undefined)
*/
public getServiceViewNames(): string[] {
if ( this.serviceViews ) {
return this.serviceViews;
}
return [];
}
/**
* @returns {string} the dataservice view model name (can be null)
*/
public getServiceViewModel(): string {
return this.serviceViewModel;
}
/**
* @returns {string} the dataservice view table names array (can be null)
*/
public getServiceViewTables(): string[] {
return this.serviceViewTables;
}
/**
* @returns {string} the dataservice type name (can be null)
*/
public getType(): string {
return "Dataservice";
}
/**
* @returns {DeploymentState} the dataservice Deployment state
*/
public getServiceDeploymentState(): DeploymentState {
return this.deploymentState;
}
/**
* Accessor to determine if service deployment is active
* @returns {boolean} the dataservice service deployment active state
*/
public get serviceDeploymentActive(): boolean {
return this.deploymentState === DeploymentState.ACTIVE;
}
/**
* Accessor to determine if service deployment is inactive
* @returns {boolean} the dataservice service deployment inactive state
*/
public get serviceDeploymentInactive(): boolean {
return this.deploymentState === DeploymentState.INACTIVE;
}
/**
* Accessor to determine if service deployment is loading
* @returns {boolean} the dataservice service deployment loading state
*/
public get serviceDeploymentLoading(): boolean {
return this.deploymentState === DeploymentState.LOADING;
}
/**
* Accessor to determine if service deployment is failed
* @returns {boolean} the dataservice service deployment failed state
*/
public get serviceDeploymentFailed(): boolean {
return this.deploymentState === DeploymentState.FAILED;
}
/**
* Accessor to determine if service is not deployed
* @returns {boolean} the dataservice service not deployed state
*/
public get serviceDeploymentNotDeployed(): boolean {
return this.deploymentState === DeploymentState.NOT_DEPLOYED;
}
/**
* @returns {DeploymentState} the dataservice Deployment state
*/
public getServicePublishState(): PublishState {
return this.virtualization ? this.virtualization.getPublishState() : PublishState.NOT_PUBLISHED;
}
/**
* Accessor to determine if service has not been published
* @returns {boolean} the dataservice service not published state
*/
public get serviceNotPublished(): boolean {
return this.getServicePublishState() === PublishState.NOT_PUBLISHED;
}
/**
* Accessor to determine if service publishing is active
* @returns {boolean} the dataservice service publishing active state
*/
public get servicePublishing(): boolean {
return this.getServicePublishState() === PublishState.PUBLISHING;
}
/**
* Accessor to determine if service has been published
* @returns {boolean} the dataservice service published state
*/
public get servicePublished(): boolean {
return this.getServicePublishState() === PublishState.PUBLISHED;
}
/**
* Accessor to determine if service has failed publishing
* @returns {boolean} the dataservice service publishing failed state
*/
public get servicePublishFailed(): boolean {
return this.getServicePublishState() === PublishState.FAILED;
}
/**
* @param {string} id the dataservice identifier (optional)
*/
public setId( id?: string ): void {
this.keng__id = id ? id : null;
}
/**
* @param {string} description the dataservice description (optional)
*/
public setDescription( description?: string ): void {
this.tko__description = description ? description : null;
}
/**
* @param {string} name the dataservice service vdb name
*/
public setServiceVdbName( name: string ): void {
this.serviceVdbName = name;
}
/**
* @param {string} version the dataservice service vdb version
*/
public setServiceVdbVersion( version: string ): void {
this.serviceVdbVersion = version;
}
/**
* @param {string[]} viewNames the dataservice view names
*/
public setServiceViewNames( viewNames: string[] ): void {
this.serviceViews = viewNames;
}
/**
* @param {string} viewModel the dataservice view model
*/
public setServiceViewModel( viewModel: string ): void {
this.serviceViewModel = viewModel;
}
/**
* @param {string[]} viewTables the dataservice view tables
*/
public setServiceViewTables( viewTables: string[] ): void {
this.serviceViewTables = viewTables;
}
/**
* @param {DeploymentState} state the dataservice deployment state
*/
public setServiceDeploymentState( state: DeploymentState ): void {
this.deploymentState = state;
}
/**
* @param {Virtualization} state the dataservice virtualization
*/
public setServiceVirtualization( state: Virtualization ): void {
this.virtualization = state ? state : null;
}
// overrides toJSON - we do not want the appSettings
public toJSON(): {} {
return {
keng__id: this.keng__id,
tko__description: this.tko__description,
serviceVdbName: this.serviceVdbName,
serviceVdbVersion: this.serviceVdbVersion,
serviceViews: this.serviceViews,
serviceViewModel: this.serviceViewModel,
serviceViewTables: this.serviceViewTables
};
}
/**
* Set all object values using the supplied Dataservice json
* @param {Object} values
*/
public setValues(values: object = {}): void {
Object.assign(this, values);
}
}