1
1
import { Injectable } from '@angular/core' ;
2
- import { Http , Response , RequestOptionsArgs , URLSearchParams } from '@angular/http' ;
2
+ import { HttpClient , HttpParams } from '@angular/common /http' ;
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
import { Subscription } from 'rxjs/Subscription' ;
5
5
import 'rxjs/add/operator/catch' ;
@@ -43,7 +43,7 @@ export class AnalyticsService {
43
43
private rowId = 1 ; // For Dashboard
44
44
public dashboardItems : DashboardItem [ ] ;
45
45
46
- constructor ( private http : Http ,
46
+ constructor ( private httpClient : HttpClient ,
47
47
private errorHandler : ErrorHandler ,
48
48
private loggerService : LoggerService ,
49
49
private notificationService : NotificationService ) {
@@ -119,14 +119,16 @@ export class AnalyticsService {
119
119
}
120
120
121
121
const params = HttpUtils . getPaginationParams ( this . counters . pageNumber , this . counters . pageSize ) ;
122
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
122
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
123
123
124
124
if ( detailed ) {
125
125
params . append ( 'detailed' , detailed . toString ( ) ) ;
126
126
}
127
127
128
- requestOptionsArgs . search = params ;
129
- return this . http . get ( this . metricsCountersUrl , requestOptionsArgs )
128
+ return this . httpClient . get < any > ( this . metricsCountersUrl , {
129
+ headers : httpHeaders ,
130
+ params : params
131
+ } )
130
132
. map ( response => this . extractData ( response , detailed ) )
131
133
. catch ( this . errorHandler . handleError ) as Observable < Page < Counter > > ;
132
134
}
@@ -136,10 +138,12 @@ export class AnalyticsService {
136
138
*/
137
139
private getAllFieldValueCounters ( ) : Observable < Page < FieldValueCounter > > {
138
140
const params = HttpUtils . getPaginationParams ( 0 , 100 ) ;
139
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
141
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
140
142
141
- requestOptionsArgs . search = params ;
142
- return this . http . get ( this . metricsFieldValueCountersUrl , requestOptionsArgs )
143
+ return this . httpClient . get < any > ( this . metricsFieldValueCountersUrl , {
144
+ params : params ,
145
+ headers : httpHeaders
146
+ } )
143
147
. map ( response => this . extractData ( response , false ) )
144
148
. catch ( this . errorHandler . handleError ) as Observable < Page < FieldValueCounter > > ;
145
149
}
@@ -149,16 +153,17 @@ export class AnalyticsService {
149
153
*/
150
154
private getAllAggregateCounters ( ) : Observable < Page < AggregateCounter > > {
151
155
const params = HttpUtils . getPaginationParams ( 0 , 100 ) ;
152
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
156
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
153
157
154
- requestOptionsArgs . search = params ;
155
- return this . http . get ( this . metricsAggregateCountersUrl , requestOptionsArgs )
158
+ return this . httpClient . get < any > ( this . metricsAggregateCountersUrl , {
159
+ params : params ,
160
+ headers : httpHeaders
161
+ } )
156
162
. map ( response => this . extractData ( response , false ) )
157
163
. catch ( this . errorHandler . handleError ) as Observable < Page < AggregateCounter > > ;
158
164
}
159
165
160
- private extractData ( response : Response , handleRates : boolean ) : Page < BaseCounter > {
161
- const body = response . json ( ) ;
166
+ private extractData ( body , handleRates : boolean ) : Page < BaseCounter > {
162
167
const items : BaseCounter [ ] = [ ] ;
163
168
const cache : BaseCounter [ ] = [ ] ;
164
169
@@ -374,10 +379,11 @@ export class AnalyticsService {
374
379
* @param counterName Name of the counter for which to retrieve details
375
380
*/
376
381
private getSingleCounter ( counterName : string ) : Observable < Counter > {
377
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
378
- return this . http . get ( this . metricsCountersUrl + '/' + counterName , requestOptionsArgs )
379
- . map ( response => {
380
- const body = response . json ( ) ;
382
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
383
+ return this . httpClient . get < any > ( this . metricsCountersUrl + '/' + counterName , {
384
+ headers : httpHeaders
385
+ } )
386
+ . map ( body => {
381
387
this . loggerService . log ( 'body' , body ) ;
382
388
return new Counter ( ) . deserialize ( body ) ;
383
389
} )
@@ -390,10 +396,11 @@ export class AnalyticsService {
390
396
* @param counterName Name of the counter for which to retrieve details
391
397
*/
392
398
private getSingleFieldValueCounter ( counterName : string ) : Observable < FieldValueCounter > {
393
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
394
- return this . http . get ( this . metricsFieldValueCountersUrl + '/' + counterName , requestOptionsArgs )
395
- . map ( response => {
396
- const body = response . json ( ) ;
399
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
400
+ return this . httpClient . get < any > ( this . metricsFieldValueCountersUrl + '/' + counterName , {
401
+ headers : httpHeaders
402
+ } )
403
+ . map ( body => {
397
404
return new FieldValueCounter ( ) . deserialize ( body ) ;
398
405
} )
399
406
. catch ( this . errorHandler . handleError ) ;
@@ -405,16 +412,16 @@ export class AnalyticsService {
405
412
* @param counterName Name of the counter for which to retrieve details
406
413
*/
407
414
private getSingleAggregateCounter ( counter : AggregateCounter ) : Observable < AggregateCounter > {
408
- const requestOptionsArgs : RequestOptionsArgs = HttpUtils . getDefaultRequestOptions ( ) ;
409
- const params = new URLSearchParams ( ) ;
410
-
411
- requestOptionsArgs . params = params ;
415
+ const httpHeaders = HttpUtils . getDefaultHttpHeaders ( ) ;
416
+ const params = new HttpParams ( ) ;
412
417
413
418
params . append ( 'resolution' , counter . resolutionType . name . toLowerCase ( ) ) ;
414
419
415
- return this . http . get ( this . metricsAggregateCountersUrl + '/' + counter . name , requestOptionsArgs )
416
- . map ( response => {
417
- const body = response . json ( ) ;
420
+ return this . httpClient . get < any > ( this . metricsAggregateCountersUrl + '/' + counter . name , {
421
+ headers : httpHeaders ,
422
+ params : params
423
+ } )
424
+ . map ( body => {
418
425
return new AggregateCounter ( ) . deserialize ( body ) ;
419
426
} )
420
427
. catch ( this . errorHandler . handleError ) ;
0 commit comments