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