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
|
import { Injectable, EventEmitter } from '@angular/core';
import {
Http,
Response,
Headers,
RequestOptions,
URLSearchParams
} from '@angular/http';
import { Observable, Subject } from 'rxjs/Rx';
// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { environment } from '../../../environments/environment';
import { v4 as uuid } from 'uuid';
@Injectable()
export class RuleEngineApiService {
options: RequestOptions;
headers: Headers;
baseUrl: string;
vfcmtUuid: string;
dcaeCompName: string;
nid: string;
configParam: string;
flowType: string;
editorData: Subject<any> = new Subject();
updateVersionLock: Subject<any> = new Subject();
constructor(private http: Http) {
this.baseUrl = `${environment.apiBaseUrl}/rule-editor`;
}
setParams(params) {
this.headers = new Headers({
'Content-Type': 'application/json',
USER_ID: params.userId
});
this.options = new RequestOptions({ headers: this.headers });
this.vfcmtUuid = params.vfcmtUuid;
this.dcaeCompName = params.nodeName;
this.nid = params.nodeId;
this.configParam = params.fieldName;
this.flowType = params.flowType;
}
setFieldName(name) {
this.configParam = name;
}
getMetaData() {
const url = `${this.baseUrl}/list-events-by-versions`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
return this.http
.get(url, this.options)
.map((res: Response) => res.json())
.catch((error: any) =>
Observable.throw(error.json().requestError || 'Server error')
);
}
getSchema(version, eventType) {
const url = `${this.baseUrl}/definition/${version}/${eventType}`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
return this.http
.get(url, this.options)
.map((res: Response) => res.json())
.catch((error: any) =>
Observable.throw(error.json().requestError || 'Server error')
);
}
getListOfRules(): Observable<any> {
const url = `${this.baseUrl}/rule/${this.vfcmtUuid}/${this.dcaeCompName}/${
this.nid
}/${this.configParam}`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
return this.http
.get(url, this.options)
.map(response => response.json())
.catch((error: any) => {
return Observable.throw(error.json().requestError || 'Server error');
});
}
modifyRule(newRole) {
const url = `${this.baseUrl}/rule/${this.vfcmtUuid}/${this.dcaeCompName}/${
this.nid
}/${this.configParam}`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
return this.http
.post(url, newRole, this.options)
.map((res: Response) => res.json())
.catch((error: any) => {
return Observable.throw(error.json().requestError || 'Server error');
});
}
deleteRule(uid) {
const url = `${this.baseUrl}/rule/${this.vfcmtUuid}/${this.dcaeCompName}/${
this.nid
}/${this.configParam}/${uid}`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
return this.http
.delete(url, this.options)
.map((res: Response) => res.json())
.catch((error: any) => {
return Observable.throw(error.json().requestError || 'Server error');
});
}
translate() {
const url = `${this.baseUrl}/rule/translate/${this.vfcmtUuid}/${
this.dcaeCompName
}/${this.nid}/${this.configParam}`;
this.options.headers.set('X-ECOMP-RequestID', uuid());
const params = new URLSearchParams();
params.append('flowType', this.flowType);
const options = { ...this.options, params: params };
return this.http
.get(url, options)
.map(response => response.json())
.catch((error: any) => {
return Observable.throw(error.json().requestError || 'Server error');
});
}
passDataToEditor(data) {
this.editorData.next(data);
}
callUpdateVersionLock() {
this.updateVersionLock.next();
}
}
|