import { DataModelBase } from './Base' ; import { IRawHealthEvent , IRawHealth } from '../RawDataTypes' ; import { DataService } from 'src/app/services/data.service' ; import { TimeUtils } from 'src/app/Utils/TimeUtils' ; import { IHealthStateChunk } from '../HealthChunkRawDataTypes' ; import { HealthEvaluation } from './Shared' ; import { Observable , of } from 'rxjs' ; import { CollectionUtils } from 'src/app/Utils/CollectionUtils' ; import { checkForJson , HealthUtils } from 'src/app/Utils/healthUtils' ; import { map , tap } from 'rxjs/operators' ; export class HealthEvent extends DataModelBase < IRawHealthEvent > { public constructor ( data , raw ) { super ( data , raw ) ; } public get uniqueId ( ) : string { return `${ this . raw . SourceId }_${ this . raw . Property }_${ this . raw . SequenceNumber }` ; } public get description ( ) : string { return checkForJson ( this . raw . Description . trim ( ) ) ; } public get sourceUtcTimestamp ( ) : string { return TimeUtils . timestampToUTCString ( this . raw . SourceUtcTimestamp ) ; } public get TTL ( ) : string { return TimeUtils . getDuration ( this . raw . TimeToLiveInMilliSeconds ) ; } } export class HealthBase < T extends IRawHealth > extends DataModelBase < T > { public healthEvents : HealthEvent [ ] = [ ] ; public unhealthyEvaluations : HealthEvaluation [ ] = [ ] ; public constructor ( data , parent ? ) { super ( data , { } as T , parent ) ; } public mergeHealthStateChunk ( healthChunk ) { this . raw . AggregatedHealthState = healthChunk . HealthState ; return of ( true ) ; } protected updateInternal ( ) { this . parseCommonHealthProperties ( ) . subscribe ( ) ; } protected parseCommonHealthProperties ( ) { this . healthEvents = this . raw . HealthEvents . map ( rawHealthEvent => new HealthEvent ( this . data , rawHealthEvent as IRawHealthEvent ) ) ; return this . data . apps . ensureInitialized ( ) . pipe ( map ( ( ) => { this . unhealthyEvaluations = HealthUtils . getParsedHealthEvaluations ( this . raw . UnhealthyEvaluations , null , null , this . data ) ; } ) ) ; } }