Remove mso-oof-adapter from SO
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / data.service.ts
1 /**
2 ============LICENSE_START=======================================================
3  Copyright (C) 2018 Ericsson. All rights reserved.
4 ================================================================================
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15  limitations under the License.
16
17 SPDX-License-Identifier: Apache-2.0
18 ============LICENSE_END=========================================================
19
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com
21 */
22
23 import { Injectable } from '@angular/core';
24 import { HttpClient, HttpErrorResponse } from '@angular/common/http';
25 import { BpmnInfraRequest } from './model/bpmnInfraRequest.model';
26 import { catchError } from 'rxjs/operators';
27 import { Observable } from 'rxjs';
28 import { ProcessInstanceId } from './model/processInstanceId.model';
29 import { environment } from '../environments/environment';
30 import { HttpResponse } from '@angular/common/http';
31 import { ProcessInstanceDetail } from './model/processInstance.model';
32 import { HttpErrorHandlerService } from './http-error-handler.service';
33 import { ActivityInstance } from './model/activityInstance.model';
34
35
36 @Injectable({
37   providedIn: 'root'
38 })
39 export class DataService {
40
41   constructor(private http: HttpClient, private httpErrorHandlerService: HttpErrorHandlerService) { }
42
43   // HTTP POST call to running Spring Boot application
44   getBpmnInfraRequest(servInstId: {}, from: number, to: number): Observable<BpmnInfraRequest[]> {
45     var url = environment.soMonitoringBackendURL + 'v1/search?from=' + from + "&to=" + to;
46     return this.http.post<BpmnInfraRequest[]>(url, servInstId)
47       .pipe(
48         catchError(this.httpErrorHandlerService.handleError("POST", url))
49       );
50   }
51
52   // HTTP GET to return Process Instance using RequestID
53   getProcessInstanceId(requestId: string): Observable<HttpResponse<ProcessInstanceId>> {
54     var url = environment.soMonitoringBackendURL + 'process-instance-id/' + requestId;
55     console.log(requestId);
56     return this.http.get<ProcessInstanceId>(url, { observe: 'response' })
57       .pipe(
58         catchError(this.httpErrorHandlerService.handleError("GET", url))
59       );
60   }
61
62   // HTTP GET to return Activity instancs using ProcessInstanceID
63   getActivityInstance(processInstanceId: string): Promise<ActivityInstance[]> {
64     var url = environment.soMonitoringBackendURL + 'activity-instance/' + processInstanceId;
65     return this.http.get<ActivityInstance[]>(url)
66       .pipe(
67         catchError(this.httpErrorHandlerService.handleError("GET", url))
68       ).toPromise();
69   }
70
71   // HTTP GET to return Activity Instance using ProcessInstanceID
72   async getProcessInstance(processInstanceId: string): Promise<ProcessInstanceDetail> {
73     var url = environment.soMonitoringBackendURL + 'process-instance/' + processInstanceId;
74     return await (this.http.get<ProcessInstanceDetail>(url)
75       .pipe(
76         catchError(this.httpErrorHandlerService.handleError("GET", url))))
77       .toPromise();
78   }
79
80   // HTTP GET to return Process Definition using processDefinitionId
81   getProcessDefinition(processDefinitionId: string): Observable<Object> {
82     var url = environment.soMonitoringBackendURL + 'process-definition/' + processDefinitionId;
83     return this.http.get(url).pipe(
84       catchError(this.httpErrorHandlerService.handleError("GET", url))
85     );
86   }
87
88   // HTTP GET to return Variable Instance using ProcessInstanceID
89   getVariableInstance(processDefinitionId: string): Observable<Object> {
90     var url = environment.soMonitoringBackendURL + 'variable-instance/' + processDefinitionId;
91     return this.http.get(url).pipe(
92       catchError(this.httpErrorHandlerService.handleError("GET", url))
93     );
94   }
95 }