summaryrefslogtreecommitdiffstats
path: root/public/src/app/rule-engine/api/rule-engine-api.service.ts
blob: 7bf5e182b932fae08e4f1007eca89d43c7c74c21 (plain)
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
import { Injectable } from '@angular/core';
import {
  Headers,
  Http,
  RequestOptions,
  Response,
  URLSearchParams
} from '@angular/http';
import 'rxjs/add/operator/catch';
// Import RxJs required methods
import 'rxjs/add/operator/map';
import { Observable, Subject } from 'rxjs/Rx';
import { v4 as uuid } from 'uuid';
import { environment } from '../../../environments/environment';

@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();
  tabIndex: 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(nofityId) {
    const url = `${this.baseUrl}/rule/translate`;
    const params = {
      vfcmtUuid: this.vfcmtUuid,
      dcaeCompLabel: this.dcaeCompName,
      nid: this.nid,
      configParam: this.configParam,
      flowType: this.flowType,
      notifyId: nofityId
    };
    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
      .post(url, params, this.options)
      .map(response => response.json())
      .catch((error: any) => {
        return Observable.throw(error.json().requestError || 'Server error');
      });
  }

  generateMappingRulesFileName(dcaeCompLabel, nid, vfcmtUuid) {
    const url = `${
      this.baseUrl
    }/getExistingRuleTargets/${vfcmtUuid}/${dcaeCompLabel}/${nid}`;
    this.options.headers.set('X-ECOMP-RequestID', uuid());
    const params = new URLSearchParams();
    return this.http
      .get(url, this.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();
  }

  callUpdateTabIndex(index) {
    this.tabIndex.next(index);
  }
}