/** Angular Imports */ import { Injectable } from '@angular/core' ; import { HttpClient , HttpParams } from '@angular/common/http' ; /** rxjs Imports */ import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; /** Custom Models */ import { ReportParameter } from './common-models/report-parameter.model' ; import { SelectOption } from './common-models/select-option.model' ; import { ChartData } from './common-models/chart-data.model' ; /**
 * Reports service.
 */ @ Injectable ( { providedIn : 'root' } ) export class ReportsService { param { HttpClient } http constructor ( private http ) { } returns { Observable < any > } getReports ( ) { return this . http . get ( '/reports' ) ; } returns { Observable < any > } getMixTaxonomyArray ( ) { return this . http . get ( '/mixtaxonomy' ) ; } returns { Observable < any > } getMixMappings ( ) { return this . http . get ( '/mixmapping' ) ; } param { any } mixMappingData returns { Observable < any > } editMixMappings ( mixMappingData ) { return this . http . put ( '/mixmapping' , mixMappingData ) ; } param { any } dates returns { Observable < any > } getMixReport ( dates ) { const httpParams = new HttpParams ( ) . set ( 'startDate' , dates . startDate ) . set ( 'endDate' , dates . endDate ) ; return this . http . get ( '/mixreport' , { params : httpParams , responseType : 'text' } ) ; } param { string } reportName returns { Observable < ReportParameter [ ] > } getReportParams ( reportName ) { const httpParams = new HttpParams ( ) . set ( 'R_reportListing' , `'${ reportName }'` ) . set ( 'parameterType' , 'true' ) ; return this . http . get ( `/runreports/FullParameterList` , { params : httpParams } ) . pipe ( map ( ( response ) => response . data . map ( ( entry ) => new ReportParameter ( entry . row ) ) ) ) ; } param { string } inputString returns { Observable < SelectOption [ ] > } getSelectOptions ( inputString ) { const httpParams = new HttpParams ( ) . set ( 'parameterType' , 'true' ) ; return this . http . get ( `/runreports/${ inputString }` , { params : httpParams } ) . pipe ( map ( ( response ) => response . data . map ( ( entry ) => new SelectOption ( entry . row ) ) ) ) ; } param { number } reportId returns { Observable < any > } getPentahoParams ( reportId ) { const httpParams = new HttpParams ( ) . set ( 'fields' , 'reportParameters' ) ; return this . http . get ( `/reports/${ reportId }` , { params : httpParams } ) . pipe ( map ( ( response ) => response . reportParameters ) ) ; } param { any } reportName param { object } formData returns { Observable < any > } getRunReportData ( reportName , formData ) { let httpParams = new HttpParams ( ) ; for ( const [ key , value ] of Object . entries ( formData ) ) { httpParams = httpParams . set ( key , value ) ; } return this . http . get ( `/runreports/${ reportName }` , { params : httpParams } ) ; } param { any } reportName param { object } formData returns { Observable < ChartData > } getChartRunReportData ( reportName , formData ) { let httpParams = new HttpParams ( ) ; for ( const [ key , value ] of Object . entries ( formData ) ) { httpParams = httpParams . set ( key , value ) ; } return this . http . get ( `/runreports/${ reportName }` , { params : httpParams } ) . pipe ( map ( ( response ) => new ChartData ( response ) ) ) ; } param { any } reportName param { object } formData returns { Observable < any > } getPentahoRunReportData ( reportName , formData , tenantIdentifier , locale , dateFormat ) { let httpParams = new HttpParams ( ) . set ( 'tenantIdentifier' , tenantIdentifier ) . set ( 'locale' , locale ) . set ( 'dateFormat' , dateFormat ) ; for ( const [ key , value ] of Object . entries ( formData ) ) { httpParams = httpParams . set ( key , value ) ; } return this . http . get ( `/runreports/${ reportName }` , { responseType : 'arraybuffer' , observe : 'response' , params : httpParams } ) ; } }