1
+ import { ActuatorApiService } from './service/Backend/Api/ActuatorApi.service' ;
1
2
import { AppConfigService } from './config/app-config.service' ;
2
3
import { catchError , concatMap , map , tap } from 'rxjs/operators' ;
3
4
import { DataSelectionMainProfileInitializerService } from './service/DataSelectionMainProfileInitializerService' ;
4
5
import { DataSelectionProfile } from './model/DataSelection/Profile/DataSelectionProfile' ;
5
6
import { FeatureProviderService } from './service/FeatureProvider.service' ;
6
7
import { FeatureService } from './service/Feature.service' ;
7
- import { HttpClient } from '@angular/common/http' ;
8
8
import { IAppConfig } from './config/app-config.model' ;
9
9
import { Injectable } from '@angular/core' ;
10
10
import { OAuthInitService } from './core/auth/oauth-init.service' ;
11
11
import { Observable , of , throwError } from 'rxjs' ;
12
12
import { ProvidersInitService } from './service/Provider/ProvidersInit.service' ;
13
13
import { TerminologySystemProvider } from './service/Provider/TerminologySystemProvider.service' ;
14
- import { ActuatorApiService } from './service/Backend/Api/ActuatorApi.service' ;
15
-
16
- interface PatientProfileInitResult {
17
- config : IAppConfig
18
- patientProfileResult : DataSelectionProfile
19
- }
20
-
14
+ import { UserProfileService } from './service/User/UserProfile.service' ;
21
15
@Injectable ( { providedIn : 'root' } )
22
16
export class CoreInitService {
23
17
constructor (
@@ -28,13 +22,21 @@ export class CoreInitService {
28
22
private featureService : FeatureService ,
29
23
private featureProviderService : FeatureProviderService ,
30
24
private providersInitService : ProvidersInitService ,
31
- private http : HttpClient ,
32
- private actuatorApiService : ActuatorApiService
25
+ private actuatorApiService : ActuatorApiService ,
26
+ private userProfileService : UserProfileService
33
27
) { }
34
28
29
+ /**
30
+ * @see Once the pipe has more than nine operators the return type will
31
+ * be Observable<unknown> therefore it needs to be casted explicitly
32
+ * to the return desired type
33
+ * Initializes core services and features.
34
+ * @returns An observable of the application configuration.
35
+ */
35
36
public init ( ) : Observable < IAppConfig > {
36
37
return this . loadConfig ( ) . pipe (
37
38
concatMap ( ( config ) => this . initOAuth ( config ) ) ,
39
+ concatMap ( ( config ) => this . initUserProfile ( config ) ) ,
38
40
concatMap ( ( config ) => this . initFeatureService ( config ) ) ,
39
41
concatMap ( ( config ) => this . initFeatureProviderService ( config ) ) ,
40
42
concatMap ( ( config ) => this . checkBackendHealth ( config ) ) ,
@@ -52,7 +54,7 @@ export class CoreInitService {
52
54
console . error ( 'CoreInitService failed:' , err ) ;
53
55
return throwError ( ( ) => err ) ;
54
56
} )
55
- ) ;
57
+ ) as Observable < IAppConfig > ;
56
58
}
57
59
58
60
private loadConfig ( ) : Observable < IAppConfig > {
@@ -78,6 +80,18 @@ export class CoreInitService {
78
80
) ;
79
81
}
80
82
83
+ private initUserProfile ( config : IAppConfig ) : Observable < IAppConfig > {
84
+ return this . userProfileService . initializeProfile ( ) . pipe (
85
+ tap ( ( result ) => console . log ( 'UserProfile initialized:' , result ) ) ,
86
+ concatMap ( ( result : boolean ) =>
87
+ result === true
88
+ ? of ( config )
89
+ : throwError ( ( ) => new Error ( 'UserProfile initialization failed' ) )
90
+ ) ,
91
+ map ( ( ) => config )
92
+ ) ;
93
+ }
94
+
81
95
private initFeatureService ( config : IAppConfig ) : Observable < IAppConfig > {
82
96
return this . featureService . initFeatureService ( config ) . pipe (
83
97
tap ( ( result ) => console . log ( 'FeatureService initialized:' , result === true ) ) ,
0 commit comments