From 21fe5bb6215be2218daa486a4f92f6779c980b1f Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Thu, 26 Mar 2020 18:44:12 +0200 Subject: [PATCH] Replace the usage of environment.ts with config.json (not too stable) (ref #251) --- dmp-frontend/src/app/app.component.ts | 11 ++- dmp-frontend/src/app/app.module.ts | 13 +-- .../src/app/core/core-service.module.ts | 17 +++- .../help-service.model.ts | 20 ++++ .../configuration-models/logging.model.ts | 19 ++++ .../login-configuration.model.ts | 22 +++++ .../login-providers.model.ts | 57 +++++++++++ .../app/core/services/auth/auth.service.ts | 9 +- .../configuration/configuration.service.ts | 97 +++++++++++++++++++ .../contact-support.service.ts | 6 +- .../services/dashboard/dashboard.service.ts | 6 +- .../dataset-profile.service.ts | 5 +- .../dataset-wizard/dataset-wizard.service.ts | 5 +- .../dataset-external-autocomplete.service.ts | 8 +- .../core/services/dataset/dataset.service.ts | 9 +- .../services/dmp/dmp-invitation.service.ts | 5 +- .../core/services/dmp/dmp-profile.service.ts | 5 +- .../src/app/core/services/dmp/dmp.service.ts | 5 +- .../email-confirmation.service.ts | 5 +- .../extternal-data-repository.service.ts | 5 +- .../dataset/external-dataset.service.ts | 5 +- .../external-sources-configuration.service.ts | 5 +- .../external-sources.service.ts | 7 +- .../registry/external-registry.service.ts | 5 +- .../researcher/external-researcher.service.ts | 5 +- .../service/external-service.service.ts | 5 +- .../core/services/funder/funder.service.ts | 5 +- .../grant/grant-file-upload.service.ts | 5 +- .../app/core/services/grant/grant.service.ts | 5 +- .../help-content/help-content.service.ts | 6 +- .../services/language/language.service.ts | 10 +- .../core/services/language/server.loader.ts | 11 ++- .../app/core/services/lock/lock.service.ts | 5 +- .../core/services/logging/logging-service.ts | 7 +- .../organisation/organisation.service.ts | 5 +- .../core/services/project/project.service.ts | 5 +- .../quick-wizard/quick-wizard.service.ts | 5 +- .../services/search-bar/search-bar.service.ts | 5 +- .../services/user-guide/user-guide.service.ts | 12 ++- .../app/core/services/user/user.service.ts | 5 +- .../editor/dmp-profile-editor.component.ts | 7 +- .../b2access/b2access-login.component.ts | 14 +-- .../configurable-login.component.ts | 6 +- .../linkedin-login.component.ts | 16 +-- .../src/app/ui/auth/login/login.component.ts | 26 ++--- .../openaire-login.component.ts | 16 +-- .../orcid-login/orcid-login.component.ts | 12 ++- .../twitter-login/twitter-login.component.ts | 8 +- .../dataset-wizard.component.ts | 8 +- .../app/ui/dmp/editor/dmp-editor.component.ts | 8 +- .../ui/grant/editor/grant-editor.component.ts | 7 +- .../user-guide-editor.component.ts | 4 +- dmp-frontend/src/assets/config/config.json | 48 +++++++++ .../interceptors/auth-token.interceptor.ts | 4 +- .../http/interceptors/base.interceptor.ts | 5 +- .../http/interceptors/json.interceptor.ts | 4 +- .../http/interceptors/locale.interceptor.ts | 4 +- .../progress-indication.interceptor.ts | 4 +- .../request-timing.interceptor.ts | 4 +- .../response-payload.interceptor.ts | 6 +- .../interceptors/status-code.interceptor.ts | 4 +- .../unauthorized-response.interceptor.ts | 4 +- 62 files changed, 524 insertions(+), 147 deletions(-) create mode 100644 dmp-frontend/src/app/core/model/configuration-models/help-service.model.ts create mode 100644 dmp-frontend/src/app/core/model/configuration-models/logging.model.ts create mode 100644 dmp-frontend/src/app/core/model/configuration-models/login-configuration.model.ts create mode 100644 dmp-frontend/src/app/core/model/configuration-models/login-providers.model.ts create mode 100644 dmp-frontend/src/app/core/services/configuration/configuration.service.ts create mode 100644 dmp-frontend/src/assets/config/config.json diff --git a/dmp-frontend/src/app/app.component.ts b/dmp-frontend/src/app/app.component.ts index 3dceca965..898ec3cf4 100644 --- a/dmp-frontend/src/app/app.component.ts +++ b/dmp-frontend/src/app/app.component.ts @@ -13,6 +13,7 @@ import { Title } from '@angular/platform-browser'; import { NgcCookieConsentService, NgcStatusChangeEvent } from "ngx-cookieconsent"; import { CookieService } from "ngx-cookie-service"; import { LanguageService } from './core/services/language/language.service'; +import { ConfigurationService } from './core/services/configuration/configuration.service'; declare const gapi: any; @@ -27,7 +28,7 @@ export class AppComponent implements OnInit { hasBreadCrumb = observableOf(false); sideNavOpen = false; - helpContentEnabled = environment.HelpService.Enabled; + helpContentEnabled : boolean; private statusChangeSubscription: Subscription; constructor( @@ -40,9 +41,11 @@ export class AppComponent implements OnInit { private cultureService: CultureService, private cookieService: CookieService, private ccService: NgcCookieConsentService, - private language: LanguageService + private language: LanguageService, + private configurationService: ConfigurationService ) { this.initializeServices(); + this.helpContentEnabled = configurationService.helpService.enabled; } onActivate(event: any) { @@ -99,6 +102,8 @@ export class AppComponent implements OnInit { } }); + this.ccService.getConfig().content.href = this.configurationService.app + "terms-of-service"; + this.ccService.getConfig().cookie.domain = this.configurationService.app; this.translate .get(['COOKIE.MESSAGE', 'COOKIE.DISMISS', 'COOKIE.DENY', 'COOKIE.LINK', 'COOKIE.POLICY']) .subscribe(data => { @@ -146,7 +151,7 @@ export class AppComponent implements OnInit { initializeServices() { this.translate.setDefaultLang('en'); - this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(environment.defaultCulture); + this.authentication.current() && this.authentication.current().culture ? this.cultureService.cultureSelected(this.authentication.current().culture) : this.cultureService.cultureSelected(this.configurationService.defaultCulture); this.authentication.current() && this.authentication.current().language ? this.language.changeLanguage(this.authentication.current().language) : this.language.changeLanguage('en'); } } diff --git a/dmp-frontend/src/app/app.module.ts b/dmp-frontend/src/app/app.module.ts index 44eb869ba..fdb790e30 100644 --- a/dmp-frontend/src/app/app.module.ts +++ b/dmp-frontend/src/app/app.module.ts @@ -1,6 +1,6 @@ import { OverlayModule } from '@angular/cdk/overlay'; import { HttpClient, HttpClientModule } from '@angular/common/http'; -import { LOCALE_ID, NgModule } from '@angular/core'; +import { LOCALE_ID, NgModule, APP_INITIALIZER } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatMomentDateModule, MAT_MOMENT_DATE_FORMATS } from '@angular/material-moment-adapter'; import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core'; @@ -29,10 +29,11 @@ import { CookieService } from 'ngx-cookie-service'; import { NgcCookieConsentConfig, NgcCookieConsentModule } from 'ngx-cookieconsent'; import { TranslateServerLoader } from './core/services/language/server.loader'; import { BaseHttpService } from './core/services/http/base-http.service'; +import { ConfigurationService } from './core/services/configuration/configuration.service'; // AoT requires an exported function for factories -export function HttpLoaderFactory(http: HttpClient) { - return new TranslateServerLoader(http); +export function HttpLoaderFactory(http: HttpClient, appConfig: ConfigurationService) { + return new TranslateServerLoader(http, appConfig); //GK: In case we want the original translation provider uncomment the line below. //return new TranslateHttpLoader(http, 'assets/i18n/', '.json'); } @@ -40,7 +41,7 @@ export function HttpLoaderFactory(http: HttpClient) { const cookieConfig: NgcCookieConsentConfig = { enabled: true, cookie: { - domain: environment.App // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A) + domain: ""//environment.App // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A) }, palette: { popup: { @@ -59,7 +60,7 @@ const cookieConfig: NgcCookieConsentConfig = { dismiss: "Got it!", deny: "Refuse cookies", link: "Learn more", - href: environment.App + "terms-of-service", + href: "",//environment.App + "terms-of-service", policy: "Cookie Policy" }, position: "bottom-right", @@ -78,7 +79,7 @@ const cookieConfig: NgcCookieConsentConfig = { loader: { provide: TranslateLoader, useFactory: HttpLoaderFactory, - deps: [HttpClient] + deps: [HttpClient, ConfigurationService] } }), HttpClientModule, diff --git a/dmp-frontend/src/app/core/core-service.module.ts b/dmp-frontend/src/app/core/core-service.module.ts index 0fbfbf240..0990f14c1 100644 --- a/dmp-frontend/src/app/core/core-service.module.ts +++ b/dmp-frontend/src/app/core/core-service.module.ts @@ -1,4 +1,4 @@ -import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; +import { ModuleWithProviders, NgModule, Optional, SkipSelf, APP_INITIALIZER } from '@angular/core'; import { CookieService } from 'ngx-cookie-service'; import { AuthGuard } from './auth-guard.service'; import { AuthService } from './services/auth/auth.service'; @@ -39,12 +39,18 @@ import { LanguageService } from './services/language/language.service'; import { AdminAuthGuard } from './admin-auth-guard.service'; import { LockService } from './services/lock/lock.service'; import { UserGuideService } from './services/user-guide/user-guide.service'; +import { ConfigurationService } from './services/configuration/configuration.service'; +import { HttpClient } from '@angular/common/http'; // // // This is shared module that provides all the services. Its imported only once on the AppModule. // // +export function ConfigurationFactory(appConfig: ConfigurationService) { + return () => appConfig.loadConfiguration(); +} + @NgModule({ }) export class CoreServiceModule { @@ -97,7 +103,14 @@ export class CoreServiceModule { ContactSupportService, LanguageService, LockService, - UserGuideService + UserGuideService, + ConfigurationService, + { + provide: APP_INITIALIZER, + useFactory: ConfigurationFactory, + deps: [ConfigurationService, HttpClient], + multi: true + }, ], }; } diff --git a/dmp-frontend/src/app/core/model/configuration-models/help-service.model.ts b/dmp-frontend/src/app/core/model/configuration-models/help-service.model.ts new file mode 100644 index 000000000..032d76e7f --- /dev/null +++ b/dmp-frontend/src/app/core/model/configuration-models/help-service.model.ts @@ -0,0 +1,20 @@ +export class HelpService { + + private _enabled: boolean; + get enabled(): boolean { + return this._enabled; + } + + private _url: string; + get url(): string { + return this._url; + } + + public static parseValue(value: any): HelpService { + const obj: HelpService = new HelpService(); + obj._enabled = value.Enabled; + obj._url = value.Url; + return obj; + } + +} diff --git a/dmp-frontend/src/app/core/model/configuration-models/logging.model.ts b/dmp-frontend/src/app/core/model/configuration-models/logging.model.ts new file mode 100644 index 000000000..2fb47ee7e --- /dev/null +++ b/dmp-frontend/src/app/core/model/configuration-models/logging.model.ts @@ -0,0 +1,19 @@ +export class Logging { + + private _enabled: boolean; + get enabled(): boolean { + return this._enabled; + } + + private _loglevels: string[] = []; + get loglevels(): string[] { + return this._loglevels; + } + + public static parseValue(value: any): Logging { + const obj: Logging = new Logging(); + obj._enabled = value.enabled; + obj._loglevels = value.logLevels; + return obj; + } +} diff --git a/dmp-frontend/src/app/core/model/configuration-models/login-configuration.model.ts b/dmp-frontend/src/app/core/model/configuration-models/login-configuration.model.ts new file mode 100644 index 000000000..18f467e99 --- /dev/null +++ b/dmp-frontend/src/app/core/model/configuration-models/login-configuration.model.ts @@ -0,0 +1,22 @@ +export class LoginConfiguration { + + private _clientId: string; + get clientId(): string { + return this._clientId; + } + + private _oauthUrl: string; + get oauthUrl(): string { + return this._oauthUrl; + } + + private _redirectUri: string; + get redirectUri(): string { + return this._redirectUri; + } + + private _state: string; + get state(): string { + return this._state; + } +} diff --git a/dmp-frontend/src/app/core/model/configuration-models/login-providers.model.ts b/dmp-frontend/src/app/core/model/configuration-models/login-providers.model.ts new file mode 100644 index 000000000..8c7751e2c --- /dev/null +++ b/dmp-frontend/src/app/core/model/configuration-models/login-providers.model.ts @@ -0,0 +1,57 @@ +import { LoginConfiguration } from './login-configuration.model'; + +export class LoginProviders { + + private _enabled: number[] = []; + get enabled(): number[] { + return this._enabled; + } + + private _facebookConfiguration: LoginConfiguration; + get facebookConfiguration(): LoginConfiguration { + return this._facebookConfiguration; + } + + private _googleConfiguration: LoginConfiguration; + get googleConfiguration(): LoginConfiguration { + return this._googleConfiguration; + } + + private _linkedInConfiguration: LoginConfiguration; + get linkedInConfiguration(): LoginConfiguration { + return this._linkedInConfiguration; + } + + private _twitterConfiguration: LoginConfiguration; + get twitterConfiguration(): LoginConfiguration { + return this._twitterConfiguration; + } + + private _b2accessConfiguration: LoginConfiguration; + get b2accessConfiguration(): LoginConfiguration { + return this._b2accessConfiguration; + } + + private _orcidConfiguration: LoginConfiguration; + get orcidConfiguration(): LoginConfiguration { + return this._orcidConfiguration; + } + + private _openAireConfiguration: LoginConfiguration; + get openAireConfiguration(): LoginConfiguration { + return this._openAireConfiguration; + } + + public static parseValue(value: any): LoginProviders { + const obj: LoginProviders = new LoginProviders(); + obj._enabled = value.enabled; + obj._facebookConfiguration = value.facebookConfiguration; + obj._googleConfiguration = value.googleConfiguration; + obj._linkedInConfiguration = value.linkedInConfiguration; + obj._twitterConfiguration = value.twitterConfiguration; + obj._b2accessConfiguration = value.b2accessConfiguration; + obj._orcidConfiguration = value.orcidConfiguration; + obj._openAireConfiguration = value.openAireConfiguration; + return obj; + } +} diff --git a/dmp-frontend/src/app/core/services/auth/auth.service.ts b/dmp-frontend/src/app/core/services/auth/auth.service.ts index bcb59345a..a48a2d478 100644 --- a/dmp-frontend/src/app/core/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/core/services/auth/auth.service.ts @@ -13,6 +13,7 @@ import { TranslateService } from '@ngx-translate/core'; import { environment } from 'environments/environment'; import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; import { catchError, map, takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class AuthService extends BaseService { @@ -24,10 +25,11 @@ export class AuthService extends BaseService { private snackBar: MatSnackBar, private language: TranslateService, private router: Router, - private uiNotificationService: UiNotificationService + private uiNotificationService: UiNotificationService, + private configurationService: ConfigurationService ) { super(); - this.actionUrl = environment.Server + 'auth/'; + this.headers = new HttpHeaders(); this.headers = this.headers.set('Content-Type', 'application/json'); @@ -65,6 +67,7 @@ export class AuthService extends BaseService { //} public login(loginInfo: LoginInfo): Observable { + this.actionUrl = this.configurationService.server + 'auth/'; const url = this.actionUrl + 'externallogin'; return this.http.post(url, loginInfo, { headers: this.headers }).pipe( @@ -80,6 +83,7 @@ export class AuthService extends BaseService { } public nativeLogin(credentials: Credential): Observable { + this.actionUrl = this.configurationService.server + 'auth/'; const url = this.actionUrl + 'nativelogin'; return this.http.post(url, credentials, { headers: this.headers }).pipe( @@ -96,6 +100,7 @@ export class AuthService extends BaseService { public logout(): void { + this.actionUrl = this.configurationService.server + 'auth/'; const url = this.actionUrl + 'logout'; const principal = this.current(); this.clear(); diff --git a/dmp-frontend/src/app/core/services/configuration/configuration.service.ts b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts new file mode 100644 index 000000000..e95d87773 --- /dev/null +++ b/dmp-frontend/src/app/core/services/configuration/configuration.service.ts @@ -0,0 +1,97 @@ +import { Injectable } from '@angular/core'; +import { BaseHttpParams } from '@common/http/base-http-params'; +import { InterceptorType } from '@common/http/interceptors/interceptor-type'; +import { BaseHttpService } from '@common/base/base-http.service'; +import { BaseComponent } from '@common/base/base.component'; +import { catchError, takeUntil } from 'rxjs/operators'; +import { Observable, throwError } from 'rxjs'; +import { HelpService } from '@app/core/model/configuration-models/help-service.model'; +import { LoginProviders } from '@app/core/model/configuration-models/login-providers.model'; +import { Logging } from '@app/core/model/configuration-models/logging.model'; +import { HttpClient } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root', + }) +export class ConfigurationService extends BaseComponent { + + constructor(private http: HttpClient) { super(); } + + private _server: string; + get server(): string { + return this._server; + } + + private _app: string; + get app(): string { + return this._app; + } + + private _helpService: HelpService; + get helpService(): HelpService { + return this._helpService; + } + + private _defaultCulture: string; + get defaultCulture(): string { + return this._defaultCulture; + } + + private _loginProviders: LoginProviders; + get loginProviders(): LoginProviders { + return this._loginProviders; + } + + private _logging: Logging; + get logging(): Logging { + return this._logging; + } + + private _lockInterval: number; + get lockInterval(): number { + return this._lockInterval; + } + + private _guideAssets: string; + get guideAssets():string { + return this._guideAssets; + } + + + public loadConfiguration(): Promise { + return new Promise((r, e) => { + + // We need to exclude all interceptors here, for the initial configuration request. + const params = new BaseHttpParams(); + params.interceptorContext = { + excludedInterceptors: [InterceptorType.AuthToken, + InterceptorType.JSONContentType, + InterceptorType.Locale, + InterceptorType.ProgressIndication, + InterceptorType.RequestTiming, + InterceptorType.UnauthorizedResponse] + }; + + this.http.get('./assets/config/config.json', { params: params }).pipe(catchError((err: any, caught: Observable) => throwError(err))) + .pipe(takeUntil(this._destroyed)) + .subscribe( + (content: ConfigurationService) => { + this.parseResponse(content); + r(this); + }, + reason => e(reason)); + }); + } + + private parseResponse(config: any) { + this._server = config.Server; + this._app = config.App; + this._helpService = HelpService.parseValue(config.HelpService); + this._defaultCulture = config.defaultCulture; + this._loginProviders = LoginProviders.parseValue(config.loginProviders); + this._logging = Logging.parseValue(config.logging); + this._lockInterval = config.lockInterval; + this._guideAssets = config.guideAssets; + } + +} diff --git a/dmp-frontend/src/app/core/services/contact-support/contact-support.service.ts b/dmp-frontend/src/app/core/services/contact-support/contact-support.service.ts index 1c1c3af08..3d2610eb5 100644 --- a/dmp-frontend/src/app/core/services/contact-support/contact-support.service.ts +++ b/dmp-frontend/src/app/core/services/contact-support/contact-support.service.ts @@ -4,14 +4,16 @@ import { environment } from "../../../../environments/environment"; import { Injectable } from "@angular/core"; import { ContactEmail } from "../../model/contact/contact-email-form-model"; import { Observable } from "rxjs"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class ContactSupportService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'contactEmail/'; + constructor(private http: BaseHttpService, + private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'contactEmail/'; } postEmail(contentEmail: ContactEmail): Observable { diff --git a/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts b/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts index 156a5d596..2046a1b20 100644 --- a/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts +++ b/dmp-frontend/src/app/core/services/dashboard/dashboard.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../environments/environment'; import { DashboardStatisticsModel } from '../../model/dashboard/dashboard-statistics-model'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DashboardService { @@ -11,8 +12,9 @@ export class DashboardService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'dashboard/'; + constructor(private http: BaseHttpService, + private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'dashboard/'; } getStatistics(): Observable { diff --git a/dmp-frontend/src/app/core/services/dataset-profile/dataset-profile.service.ts b/dmp-frontend/src/app/core/services/dataset-profile/dataset-profile.service.ts index 2d19bdea8..c368b2638 100644 --- a/dmp-frontend/src/app/core/services/dataset-profile/dataset-profile.service.ts +++ b/dmp-frontend/src/app/core/services/dataset-profile/dataset-profile.service.ts @@ -14,6 +14,7 @@ import { InterceptorType } from '@common/http/interceptors/interceptor-type'; import { environment } from 'environments/environment'; import { Observable } from 'rxjs'; import { takeUntil } from "rxjs/operators"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DatasetProfileService extends BaseService { @@ -24,9 +25,9 @@ export class DatasetProfileService extends BaseService { private actionUrl: string; private headers = new HttpHeaders(); - constructor(private http: BaseHttpService, private httpClient: HttpClient) { + constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) { super(); - this.actionUrl = environment.Server + 'admin/'; + this.actionUrl = configurationService.server + 'admin/'; } createForm(data) { diff --git a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts index ef43731f6..3f1b65a33 100644 --- a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts +++ b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts @@ -10,6 +10,7 @@ import { DatasetWizardModel } from '../../model/dataset/dataset-wizard'; import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-profile-criteria'; import { RequestItem } from '../../query/request-item'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DatasetWizardService { @@ -17,8 +18,8 @@ export class DatasetWizardService { private actionUrl: string; private headers = new HttpHeaders(); - constructor(private http: BaseHttpService, private httpClient: HttpClient) { - this.actionUrl = environment.Server + 'datasetwizard/'; + constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'datasetwizard/'; } // public userDmps(criteria: RequestItem): Observable { diff --git a/dmp-frontend/src/app/core/services/dataset/dataset-external-autocomplete.service.ts b/dmp-frontend/src/app/core/services/dataset/dataset-external-autocomplete.service.ts index 571e73f94..21d3f814a 100644 --- a/dmp-frontend/src/app/core/services/dataset/dataset-external-autocomplete.service.ts +++ b/dmp-frontend/src/app/core/services/dataset/dataset-external-autocomplete.service.ts @@ -5,6 +5,7 @@ import { environment } from '../../../../environments/environment'; import { DatasetExternalAutocompleteCriteria } from '../../query/dataset/daatset-external-autocomplete-criteria'; import { RequestItem } from '../../query/request-item'; import { DatasetProfileService } from '../dataset-profile/dataset-profile.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DatasetExternalAutocompleteService { @@ -13,8 +14,9 @@ export class DatasetExternalAutocompleteService { constructor( private httpClient: HttpClient, - private datasetProfileService: DatasetProfileService) { - this.actionUrl = environment.Server + 'datasetwizard/'; + private datasetProfileService: DatasetProfileService, + private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'datasetwizard/'; } getDatasetProfileById(datasetProfileID) { @@ -22,7 +24,7 @@ export class DatasetExternalAutocompleteService { } queryAutocomplete(lookUpItem: RequestItem): Observable { - return this.httpClient.post(environment.Server + 'search/autocomplete', lookUpItem); + return this.httpClient.post(this.configurationService.server + 'search/autocomplete', lookUpItem); } } diff --git a/dmp-frontend/src/app/core/services/dataset/dataset.service.ts b/dmp-frontend/src/app/core/services/dataset/dataset.service.ts index 70b806bed..7b157833a 100644 --- a/dmp-frontend/src/app/core/services/dataset/dataset.service.ts +++ b/dmp-frontend/src/app/core/services/dataset/dataset.service.ts @@ -9,14 +9,17 @@ import { DatasetCriteria } from '../../query/dataset/dataset-criteria'; import { ExploreDatasetCriteriaModel } from '../../query/explore-dataset/explore-dataset-criteria'; import { BaseHttpService } from '../http/base-http.service'; import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-profile-criteria'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DatasetService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'datasets/'; + constructor( + private http: BaseHttpService, + private configurationSevice: ConfigurationService) { + this.actionUrl = configurationSevice.server + 'datasets/'; } getPaged(dataTableRequest: DataTableRequest): Observable> { @@ -32,7 +35,7 @@ export class DatasetService { } getDatasetProfiles(dataTableRequest: DataTableRequest): Observable { - return this.http.post(environment.Server + 'datasetprofiles/getAll', dataTableRequest); + return this.http.post(this.configurationSevice.server + 'datasetprofiles/getAll', dataTableRequest); } getDatasetProfilesUsedPaged(dataTableRequest: DataTableRequest) { diff --git a/dmp-frontend/src/app/core/services/dmp/dmp-invitation.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp-invitation.service.ts index 3f7dca82f..a19663de8 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp-invitation.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp-invitation.service.ts @@ -7,6 +7,7 @@ import { DmpInvitation } from '../../model/dmp/invitation/dmp-invitation'; import { DmpInvitationUser } from '../../model/dmp/invitation/dmp-invitation-user'; import { DmpInvitationUserCriteria } from '../../query/dmp/dmp-invitation-user-criteria'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DmpInvitationService { @@ -14,8 +15,8 @@ export class DmpInvitationService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'invite/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'invite/'; } public inviteDmpInvitationUsers(invitation: DmpInvitation): Observable { diff --git a/dmp-frontend/src/app/core/services/dmp/dmp-profile.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp-profile.service.ts index a6679c832..9b9f16f39 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp-profile.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp-profile.service.ts @@ -13,6 +13,7 @@ import { DatasetListingModel } from '../../model/dataset/dataset-listing'; import { BaseHttpParams } from '../../../../common/http/base-http-params'; import { InterceptorType } from '../../../../common/http/interceptors/interceptor-type'; import { DmpProfileExternalAutocompleteCriteria } from '../../query/dmp/dmp-profile-external-autocomplete-criteria'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DmpProfileService { @@ -20,8 +21,8 @@ export class DmpProfileService { private actionUrl: string; private headers = new HttpHeaders(); - constructor(private http: BaseHttpService, private httpClient: HttpClient) { - this.actionUrl = environment.Server + 'dmpprofile/'; + constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'dmpprofile/'; } getPaged(dataTableRequest: DataTableRequest): Observable> { diff --git a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts index 0edd621a9..edafe2ba3 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts @@ -18,6 +18,7 @@ import { DmpCriteria } from '../../query/dmp/dmp-criteria'; import { ExploreDmpCriteriaModel } from '../../query/explore-dmp/explore-dmp-criteria'; import { RequestItem } from '../../query/request-item'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class DmpService { @@ -25,8 +26,8 @@ export class DmpService { private actionUrl: string; private headers = new HttpHeaders(); - constructor(private http: BaseHttpService, private httpClient: HttpClient) { - this.actionUrl = environment.Server + 'dmps/'; + constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'dmps/'; } diff --git a/dmp-frontend/src/app/core/services/email-confirmation/email-confirmation.service.ts b/dmp-frontend/src/app/core/services/email-confirmation/email-confirmation.service.ts index 29433964f..bae593b87 100644 --- a/dmp-frontend/src/app/core/services/email-confirmation/email-confirmation.service.ts +++ b/dmp-frontend/src/app/core/services/email-confirmation/email-confirmation.service.ts @@ -2,14 +2,15 @@ import { HttpHeaders } from '@angular/common/http'; import { Injectable } from "@angular/core"; import { environment } from "../../../../environments/environment"; import { BaseHttpService } from "../http/base-http.service"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class EmailConfirmationService { private actioUrl: string; private headers: HttpHeaders - constructor(private http: BaseHttpService) { - this.actioUrl = environment.Server + 'emailConfirmation/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actioUrl = configurationService.server + 'emailConfirmation/'; } public emailConfirmation(token: string) { diff --git a/dmp-frontend/src/app/core/services/external-sources/data-repository/extternal-data-repository.service.ts b/dmp-frontend/src/app/core/services/external-sources/data-repository/extternal-data-repository.service.ts index 43a8d6f3c..5fd29f12b 100644 --- a/dmp-frontend/src/app/core/services/external-sources/data-repository/extternal-data-repository.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/data-repository/extternal-data-repository.service.ts @@ -3,13 +3,14 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../../environments/environment'; import { DataRepositoryModel } from '../../../model/data-repository/data-repository'; import { BaseHttpService } from '../../http/base-http.service'; +import { ConfigurationService } from '../../configuration/configuration.service'; @Injectable() export class ExternalDataRepositoryService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'external/datarepos'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'external/datarepos'; } create(dataRepoModel: DataRepositoryModel): Observable { diff --git a/dmp-frontend/src/app/core/services/external-sources/dataset/external-dataset.service.ts b/dmp-frontend/src/app/core/services/external-sources/dataset/external-dataset.service.ts index 19ef67bd5..260bb989a 100644 --- a/dmp-frontend/src/app/core/services/external-sources/dataset/external-dataset.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/dataset/external-dataset.service.ts @@ -7,13 +7,14 @@ import { DataTableRequest } from '../../../model/data-table/data-table-request'; import { ExternalDatasetModel } from '../../../model/external-dataset/external-dataset'; import { ExternalDatasetCriteria } from '../../../query/external-dataset/external-dataset-criteria'; import { BaseHttpService } from '../../http/base-http.service'; +import { ConfigurationService } from '../../configuration/configuration.service'; @Injectable() export class ExternalDatasetService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'externaldatasets/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'externaldatasets/'; } create(externalDatasetModel: ExternalDatasetModel): Observable { diff --git a/dmp-frontend/src/app/core/services/external-sources/external-sources-configuration.service.ts b/dmp-frontend/src/app/core/services/external-sources/external-sources-configuration.service.ts index ab6247a64..f443a4004 100644 --- a/dmp-frontend/src/app/core/services/external-sources/external-sources-configuration.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/external-sources-configuration.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../environments/environment'; import { ExternalSourcesConfiguration } from '../../model/external-sources/external-sources-configuration'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class ExternalSourcesConfigurationService { @@ -11,8 +12,8 @@ export class ExternalSourcesConfigurationService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'common/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'common/'; } public getExternalSourcesConfiguration(): Observable { diff --git a/dmp-frontend/src/app/core/services/external-sources/external-sources.service.ts b/dmp-frontend/src/app/core/services/external-sources/external-sources.service.ts index d8b5b76a4..471b6f954 100644 --- a/dmp-frontend/src/app/core/services/external-sources/external-sources.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/external-sources.service.ts @@ -11,6 +11,7 @@ import { ResearcherCriteria } from '../../query/researcher/researcher-criteria'; import { ServiceCriteria } from '../../query/service/service-criteria'; import { TagCriteria } from '../../query/tag/tag-criteria'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class ExternalSourcesService { @@ -18,9 +19,9 @@ export class ExternalSourcesService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { - this.actionUrl = environment.Server + 'external/'; + this.actionUrl = configurationService.server + 'external/'; this.headers = new HttpHeaders(); this.headers = this.headers.set('Content-Type', 'application/json'); @@ -58,7 +59,7 @@ export class ExternalSourcesService { } public searchDMPResearchers(requestItem: RequestItem): Observable { - return this.http.post(environment.Server + 'researchers/getWithExternal', requestItem, { headers: this.headers }); + return this.http.post(this.configurationService.server + 'researchers/getWithExternal', requestItem, { headers: this.headers }); } public searchDMPOrganizations(like: string): Observable { diff --git a/dmp-frontend/src/app/core/services/external-sources/registry/external-registry.service.ts b/dmp-frontend/src/app/core/services/external-sources/registry/external-registry.service.ts index 163390444..3b4e1ef3a 100644 --- a/dmp-frontend/src/app/core/services/external-sources/registry/external-registry.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/registry/external-registry.service.ts @@ -3,13 +3,14 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../../environments/environment'; import { RegistryModel } from '../../../model/registry/registry'; import { BaseHttpService } from '../../http/base-http.service'; +import { ConfigurationService } from '../../configuration/configuration.service'; @Injectable() export class ExternalRegistryService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'registries/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'registries/'; } create(registerModel: RegistryModel): Observable { diff --git a/dmp-frontend/src/app/core/services/external-sources/researcher/external-researcher.service.ts b/dmp-frontend/src/app/core/services/external-sources/researcher/external-researcher.service.ts index f51c9cd78..3651c83e4 100644 --- a/dmp-frontend/src/app/core/services/external-sources/researcher/external-researcher.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/researcher/external-researcher.service.ts @@ -2,14 +2,15 @@ import { Injectable } from '@angular/core'; import { environment } from '../../../../../environments/environment'; import { ResearcherModel } from '../../../model/researcher/researcher'; import { BaseHttpService } from '../../http/base-http.service'; +import { ConfigurationService } from '../../configuration/configuration.service'; @Injectable() export class ExternalResearcherService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'researchers/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'researchers/'; } public createResearcher(researcher: ResearcherModel) { diff --git a/dmp-frontend/src/app/core/services/external-sources/service/external-service.service.ts b/dmp-frontend/src/app/core/services/external-sources/service/external-service.service.ts index 45e7e9193..3a5fa623e 100644 --- a/dmp-frontend/src/app/core/services/external-sources/service/external-service.service.ts +++ b/dmp-frontend/src/app/core/services/external-sources/service/external-service.service.ts @@ -3,13 +3,14 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../../environments/environment'; import { ServiceModel } from '../../../model/service/service'; import { BaseHttpService } from '../../http/base-http.service'; +import { ConfigurationService } from '../../configuration/configuration.service'; @Injectable() export class ExternalServiceService { private actionUrl: string; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'services/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'services/'; } create(serviceModel: ServiceModel): Observable { diff --git a/dmp-frontend/src/app/core/services/funder/funder.service.ts b/dmp-frontend/src/app/core/services/funder/funder.service.ts index 9b19c05d0..86430d977 100644 --- a/dmp-frontend/src/app/core/services/funder/funder.service.ts +++ b/dmp-frontend/src/app/core/services/funder/funder.service.ts @@ -6,14 +6,15 @@ import { BaseHttpService } from "../http/base-http.service"; import { environment } from '../../../../environments/environment'; import { FunderCriteria } from "../../query/funder/funder-criteria"; import { FunderModel } from "../../model/funder/funder"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class FunderService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'funders/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'funders/'; } getWithExternal(requestItem: RequestItem): Observable { diff --git a/dmp-frontend/src/app/core/services/grant/grant-file-upload.service.ts b/dmp-frontend/src/app/core/services/grant/grant-file-upload.service.ts index a4cd0a646..78aa904d3 100644 --- a/dmp-frontend/src/app/core/services/grant/grant-file-upload.service.ts +++ b/dmp-frontend/src/app/core/services/grant/grant-file-upload.service.ts @@ -6,14 +6,15 @@ import { ContentFile } from '../../model/grant/grant-listing'; import { BaseHttpService } from '../http/base-http.service'; import { BaseHttpParams } from '../../../../common/http/base-http-params'; import { InterceptorType } from '../../../../common/http/interceptors/interceptor-type'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class GrantFileUploadService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'files/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'files/'; } uploadFile(formData: FormData): Observable { diff --git a/dmp-frontend/src/app/core/services/grant/grant.service.ts b/dmp-frontend/src/app/core/services/grant/grant.service.ts index 4da0cd913..01d80993f 100644 --- a/dmp-frontend/src/app/core/services/grant/grant.service.ts +++ b/dmp-frontend/src/app/core/services/grant/grant.service.ts @@ -8,6 +8,7 @@ import { GrantListingModel } from '../../model/grant/grant-listing'; import { GrantCriteria } from '../../query/grant/grant-criteria'; import { RequestItem } from '../../query/request-item'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() @@ -16,8 +17,8 @@ export class GrantService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'grants/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'grants/'; } getPaged(dataTableRequest: DataTableRequest, fieldsGroup?: string): Observable> { diff --git a/dmp-frontend/src/app/core/services/help-content/help-content.service.ts b/dmp-frontend/src/app/core/services/help-content/help-content.service.ts index f0397b5b6..5682d934f 100644 --- a/dmp-frontend/src/app/core/services/help-content/help-content.service.ts +++ b/dmp-frontend/src/app/core/services/help-content/help-content.service.ts @@ -8,14 +8,16 @@ import { catchError, map } from 'rxjs/operators'; import { environment } from '../../../../environments/environment'; import { PageHelpContent } from '../../model/help-content/page-help-content'; import { CachedContentItem } from './cached-content-item'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class HelpContentService { - private _helpServiceUrl = environment.HelpService.Url; + private _helpServiceUrl: string; cache = new Map(); - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private configurationService: ConfigurationService) { + this._helpServiceUrl = configurationService.helpService.url; } // getActivePageContent(route: string) { diff --git a/dmp-frontend/src/app/core/services/language/language.service.ts b/dmp-frontend/src/app/core/services/language/language.service.ts index 4999d6f8a..ad69aeebc 100644 --- a/dmp-frontend/src/app/core/services/language/language.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.service.ts @@ -5,19 +5,23 @@ import { Observable } from 'rxjs'; import { HttpResponse, HttpClient } from '@angular/common/http'; import { BaseHttpService } from '../http/base-http.service'; import { Language } from '@app/models/language/Language'; +import { ConfigurationService } from '../configuration/configuration.service'; const availableLanguages: any[] = require('../../../../assets/resources/language.json'); @Injectable() export class LanguageService { private currentLanguage: string = 'en'; - private languageUrl = `${environment.Server}language`; + private languageUrl : string; constructor( private translate: TranslateService, private http: HttpClient, - private baseHttp: BaseHttpService - ) {} + private baseHttp: BaseHttpService, + private configurationService: ConfigurationService + ) { + this.languageUrl = `${configurationService.server}language`; + } public changeLanguage(lang: string) { this.currentLanguage = lang; diff --git a/dmp-frontend/src/app/core/services/language/server.loader.ts b/dmp-frontend/src/app/core/services/language/server.loader.ts index a9030e633..f97d19433 100644 --- a/dmp-frontend/src/app/core/services/language/server.loader.ts +++ b/dmp-frontend/src/app/core/services/language/server.loader.ts @@ -2,14 +2,19 @@ import { TranslateLoader } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { environment } from 'environments/environment'; import { HttpClient } from '@angular/common/http'; +import { ConfigurationService } from '../configuration/configuration.service'; export class TranslateServerLoader implements TranslateLoader{ - private languageUrl = `${environment.Server}language`; + private languageUrl: string; constructor( - private http: HttpClient - ) {} + private http: HttpClient, + private configurationService: ConfigurationService + ) { + + } getTranslation(lang: string): Observable { + this.languageUrl = `${this.configurationService.server}language`; return this.http.get(`${this.languageUrl}/${lang}`); } } diff --git a/dmp-frontend/src/app/core/services/lock/lock.service.ts b/dmp-frontend/src/app/core/services/lock/lock.service.ts index 0348386c4..a816163e5 100644 --- a/dmp-frontend/src/app/core/services/lock/lock.service.ts +++ b/dmp-frontend/src/app/core/services/lock/lock.service.ts @@ -4,6 +4,7 @@ import { BaseHttpService } from '../http/base-http.service'; import { environment } from 'environments/environment'; import { Observable } from 'rxjs'; import { LockModel } from '@app/core/model/lock/lock.model'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class LockService { @@ -11,8 +12,8 @@ export class LockService { private actionUrl: string; private headers = new HttpHeaders(); - constructor(private http: BaseHttpService, private httpClient: HttpClient) { - this.actionUrl = environment.Server + 'lock/'; + constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'lock/'; } checkLockStatus(id: string): Observable { diff --git a/dmp-frontend/src/app/core/services/logging/logging-service.ts b/dmp-frontend/src/app/core/services/logging/logging-service.ts index 1da0dc0cc..b8d8a2629 100644 --- a/dmp-frontend/src/app/core/services/logging/logging-service.ts +++ b/dmp-frontend/src/app/core/services/logging/logging-service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { environment } from '../../../../environments/environment'; +import { ConfigurationService } from '../configuration/configuration.service'; export enum LogLevel { Error = 'error', @@ -16,7 +17,7 @@ export class LoggingService { private loggingLevels: LogLevel[]; private loggingOutputs: LogOutput[] = []; - constructor() { + constructor(private configurationService: ConfigurationService) { } @@ -37,7 +38,7 @@ export class LoggingService { } init() { - this.loggingLevels = environment.logging.logLevels as LogLevel[]; + this.loggingLevels = this.configurationService.logging.loglevels as LogLevel[]; this.loggingOutputs.push((level: LogLevel, ...objects: any[]) => { switch (level) { @@ -62,7 +63,7 @@ export class LoggingService { private log(level: LogLevel, logs: any[]) { if (!this.loggingLevels) { this.init(); } - if (environment.logging.enabled && this.loggingLevels.includes(level)) { + if (this.configurationService.logging.enabled && this.loggingLevels.includes(level)) { this.loggingOutputs.forEach((output) => output.apply(output, [level, logs])); } } diff --git a/dmp-frontend/src/app/core/services/organisation/organisation.service.ts b/dmp-frontend/src/app/core/services/organisation/organisation.service.ts index a927bfcfa..274968b86 100644 --- a/dmp-frontend/src/app/core/services/organisation/organisation.service.ts +++ b/dmp-frontend/src/app/core/services/organisation/organisation.service.ts @@ -7,6 +7,7 @@ import { DataTableData } from "../../model/data-table/data-table-data"; import { OrganizationModel } from "../../model/organisation/organization"; import { OrganisationCriteria } from "../../query/organisation/organisation-criteria"; import { DataTableRequest } from "../../model/data-table/data-table-request"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class OrganisationService { @@ -14,9 +15,9 @@ export class OrganisationService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { - this.actionUrl = environment.Server; + this.actionUrl = configurationService.server; this.headers = new HttpHeaders(); this.headers = this.headers.set('Content-Type', 'application/json'); diff --git a/dmp-frontend/src/app/core/services/project/project.service.ts b/dmp-frontend/src/app/core/services/project/project.service.ts index 625be3581..0532f8c95 100644 --- a/dmp-frontend/src/app/core/services/project/project.service.ts +++ b/dmp-frontend/src/app/core/services/project/project.service.ts @@ -7,14 +7,15 @@ import { BaseHttpService } from "../http/base-http.service"; import { environment } from '../../../../environments/environment'; import { ProjectCriteria } from "../../query/project/project-criteria"; import { ProjectModel } from "../../model/project/project"; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class ProjectService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'projects/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'projects/'; } getWithExternal(requestItem: RequestItem): Observable { diff --git a/dmp-frontend/src/app/core/services/quick-wizard/quick-wizard.service.ts b/dmp-frontend/src/app/core/services/quick-wizard/quick-wizard.service.ts index 28174bb11..4a6d3579d 100644 --- a/dmp-frontend/src/app/core/services/quick-wizard/quick-wizard.service.ts +++ b/dmp-frontend/src/app/core/services/quick-wizard/quick-wizard.service.ts @@ -5,14 +5,15 @@ import { environment } from '../../../../environments/environment'; import { QuickWizardEditorWizardModel } from '../../../ui/quick-wizard/quick-wizard-editor/quick-wizard-editor.model'; import { BaseHttpService } from '../http/base-http.service'; import { DatasetCreateWizardModel } from '../../../ui/dataset-create-wizard/dataset-create-wizard.model'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class QuickWizardService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { - this.actionUrl = environment.Server + 'quick-wizard/'; + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { + this.actionUrl = configurationService.server + 'quick-wizard/'; } createQuickWizard(quickWizard: QuickWizardEditorWizardModel): Observable { diff --git a/dmp-frontend/src/app/core/services/search-bar/search-bar.service.ts b/dmp-frontend/src/app/core/services/search-bar/search-bar.service.ts index 3e2cd1876..db5d6341e 100644 --- a/dmp-frontend/src/app/core/services/search-bar/search-bar.service.ts +++ b/dmp-frontend/src/app/core/services/search-bar/search-bar.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { environment } from '../../../../environments/environment'; import { SearchBarItem } from '../../model/dashboard/search-bar-item'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class SearchBarService { @@ -11,9 +12,9 @@ export class SearchBarService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { - this.actionUrl = environment.Server + 'dashboard/'; + this.actionUrl = configurationService.server + 'dashboard/'; } search(like: string): Observable { diff --git a/dmp-frontend/src/app/core/services/user-guide/user-guide.service.ts b/dmp-frontend/src/app/core/services/user-guide/user-guide.service.ts index 4a4133c10..abdf49738 100644 --- a/dmp-frontend/src/app/core/services/user-guide/user-guide.service.ts +++ b/dmp-frontend/src/app/core/services/user-guide/user-guide.service.ts @@ -4,21 +4,25 @@ import { environment } from 'environments/environment'; import { Observable } from 'rxjs'; import { HttpResponse, HttpClient } from '@angular/common/http'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class UserGuideService { - private userGuideUrl = `${environment.Server}userguide`; + private userGuideUrl : string; constructor( private translate: TranslateService, private http: HttpClient, - private baseHttp: BaseHttpService - ) {} + private baseHttp: BaseHttpService, + private configurationService: ConfigurationService + ) { + this.userGuideUrl = `${configurationService.server}userguide`; + } public getUserGuide(): Observable> { return this.http.get(`${this.userGuideUrl}/current`, { responseType: 'blob', observe: 'response', headers: {'Content-type': 'text/html', 'Accept': 'text/html', - 'Access-Control-Allow-Origin': environment.App, + 'Access-Control-Allow-Origin': this.configurationService.app, 'Access-Control-Allow-Credentials': 'true'} }); } diff --git a/dmp-frontend/src/app/core/services/user/user.service.ts b/dmp-frontend/src/app/core/services/user/user.service.ts index b4c8659a2..21f6381b2 100644 --- a/dmp-frontend/src/app/core/services/user/user.service.ts +++ b/dmp-frontend/src/app/core/services/user/user.service.ts @@ -7,6 +7,7 @@ import { DataTableRequest } from '../../model/data-table/data-table-request'; import { UserListingModel } from '../../model/user/user-listing'; import { UserCriteria } from '../../query/user/user-criteria'; import { BaseHttpService } from '../http/base-http.service'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class UserService { @@ -14,9 +15,9 @@ export class UserService { private actionUrl: string; private headers: HttpHeaders; - constructor(private http: BaseHttpService) { + constructor(private http: BaseHttpService, private configurationService: ConfigurationService) { - this.actionUrl = environment.Server + 'user/'; + this.actionUrl = configurationService.server + 'user/'; } getPaged(dataTableRequest: DataTableRequest): Observable> { diff --git a/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts b/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts index b7cf3cdd0..6ee859cf1 100644 --- a/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/dmp-profile/editor/dmp-profile-editor.component.ts @@ -20,6 +20,7 @@ import { environment } from 'environments/environment'; import * as FileSaver from 'file-saver'; import { Observable, of as observableOf } from 'rxjs'; import { map, takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ @@ -33,7 +34,7 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie viewOnly = false; dmpProfileModel: DmpProfileEditorModel; formGroup: FormGroup = null; - host = environment.Server; + host: string; dmpProfileId: string; breadCrumbs: Observable; @@ -44,9 +45,11 @@ export class DmpProfileEditorComponent extends BaseComponent implements AfterVie private language: TranslateService, private enumUtils: EnumUtils, private uiNotificationService: UiNotificationService, - private formService: FormService + private formService: FormService, + private configurationService: ConfigurationService ) { super(); + this.host = configurationService.server; } ngAfterViewInit() { diff --git a/dmp-frontend/src/app/ui/auth/login/b2access/b2access-login.component.ts b/dmp-frontend/src/app/ui/auth/login/b2access/b2access-login.component.ts index bdba62c6c..a5e2948f8 100644 --- a/dmp-frontend/src/app/ui/auth/login/b2access/b2access-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/b2access/b2access-login.component.ts @@ -7,6 +7,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-b2access-login', @@ -20,7 +21,8 @@ export class B2AccessLoginComponent extends BaseComponent implements OnInit { private route: ActivatedRoute, private authService: AuthService, private loginService: LoginService, - private httpClient: HttpClient + private httpClient: HttpClient, + private configurationService: ConfigurationService ) { super(); } @@ -36,10 +38,10 @@ export class B2AccessLoginComponent extends BaseComponent implements OnInit { } public b2AccessGetAuthCode() { - window.location.href = environment.loginProviders.b2accessConfiguration.oauthUrl - + '?response_type=code&client_id=' + environment.loginProviders.b2accessConfiguration.clientId - + '&redirect_uri=' + environment.loginProviders.b2accessConfiguration.redirectUri - + '&state=' + environment.loginProviders.b2accessConfiguration.state + window.location.href = this.configurationService.loginProviders.b2accessConfiguration.oauthUrl + + '?response_type=code&client_id=' + this.configurationService.loginProviders.b2accessConfiguration.clientId + + '&redirect_uri=' + this.configurationService.loginProviders.b2accessConfiguration.redirectUri + + '&state=' + this.configurationService.loginProviders.b2accessConfiguration.state + '&scope=USER_PROFILE'; } @@ -47,7 +49,7 @@ export class B2AccessLoginComponent extends BaseComponent implements OnInit { let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json'); headers = headers.set('Accept', 'application/json'); - this.httpClient.post(environment.Server + 'auth/b2AccessRequestToken', { code: code }, { headers: headers }) + this.httpClient.post(this.configurationService.server + 'auth/b2AccessRequestToken', { code: code }, { headers: headers }) .pipe(takeUntil(this._destroyed)) .subscribe((data: any) => { this.authService.login({ ticket: data.payload.accessToken, provider: AuthProvider.B2Access, data: null }) diff --git a/dmp-frontend/src/app/ui/auth/login/configurable-login/configurable-login.component.ts b/dmp-frontend/src/app/ui/auth/login/configurable-login/configurable-login.component.ts index 95f170f8d..69d35a0d4 100644 --- a/dmp-frontend/src/app/ui/auth/login/configurable-login/configurable-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/configurable-login/configurable-login.component.ts @@ -9,6 +9,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-configurable-login', @@ -33,7 +34,8 @@ export class ConfigurableLoginComponent extends BaseComponent implements OnInit private authService: AuthService, private router: Router, private httpClient: HttpClient, - private providers: ConfigurableProvidersService + private providers: ConfigurableProvidersService, + private configurationService: ConfigurationService ) { super(); } @@ -80,7 +82,7 @@ export class ConfigurableLoginComponent extends BaseComponent implements OnInit if (state !== this.provider.state) { this.router.navigate(['/login']) } - this.httpClient.post(environment.Server + 'auth/configurableProviderRequestToken', { code: code, provider: AuthProvider.Configurable, configurableLoginId: this.providerId }) + this.httpClient.post(this.configurationService.server + 'auth/configurableProviderRequestToken', { code: code, provider: AuthProvider.Configurable, configurableLoginId: this.providerId }) .pipe(takeUntil(this._destroyed)) .subscribe((data: any) => { this.authService.login({ ticket: data.payload.accessToken, provider: AuthProvider.Configurable, data: { configurableLoginId: this.provider.configurableLoginId } }) diff --git a/dmp-frontend/src/app/ui/auth/login/linkedin-login/linkedin-login.component.ts b/dmp-frontend/src/app/ui/auth/login/linkedin-login/linkedin-login.component.ts index 4d6acf28e..6b87652c8 100644 --- a/dmp-frontend/src/app/ui/auth/login/linkedin-login/linkedin-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/linkedin-login/linkedin-login.component.ts @@ -7,6 +7,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-linkedin-login', @@ -21,7 +22,8 @@ export class LinkedInLoginComponent extends BaseComponent implements OnInit { private loginService: LoginService, private authService: AuthService, private router: Router, - private httpClient: HttpClient + private httpClient: HttpClient, + private configurationService: ConfigurationService ) { super(); } @@ -37,18 +39,18 @@ export class LinkedInLoginComponent extends BaseComponent implements OnInit { } public linkedinAuthorize() { - window.location.href = environment.loginProviders.linkedInConfiguration.oauthUrl - + '?response_type=code&client_id=' + environment.loginProviders.linkedInConfiguration.clientId - + '&redirect_uri=' + environment.loginProviders.linkedInConfiguration.redirectUri - + '&state=' + environment.loginProviders.linkedInConfiguration.state + window.location.href = this.configurationService.loginProviders.linkedInConfiguration.oauthUrl + + '?response_type=code&client_id=' + this.configurationService.loginProviders.linkedInConfiguration.clientId + + '&redirect_uri=' + this.configurationService.loginProviders.linkedInConfiguration.redirectUri + + '&state=' + this.configurationService.loginProviders.linkedInConfiguration.state + '&scope=r_emailaddress'; } public linkedInLoginUser(code: string, state: string) { - if (state !== environment.loginProviders.linkedInConfiguration.state) { + if (state !== this.configurationService.loginProviders.linkedInConfiguration.state) { this.router.navigate(['/login']); } - this.httpClient.post(environment.Server + 'auth/linkedInRequestToken', { code: code, provider: AuthProvider.LinkedIn }) + this.httpClient.post(this.configurationService.server + 'auth/linkedInRequestToken', { code: code, provider: AuthProvider.LinkedIn }) .pipe(takeUntil(this._destroyed)) .subscribe((data: any) => { this.authService.login({ ticket: data.payload.accessToken, provider: AuthProvider.LinkedIn, data: null }) diff --git a/dmp-frontend/src/app/ui/auth/login/login.component.ts b/dmp-frontend/src/app/ui/auth/login/login.component.ts index 3f2662445..d439a234f 100644 --- a/dmp-frontend/src/app/ui/auth/login/login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/login.component.ts @@ -8,6 +8,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; /// /// @@ -31,7 +32,8 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn private route: ActivatedRoute, private loginService: LoginService, private authService: AuthService, - public configurableProviderService: ConfigurableProvidersService + public configurableProviderService: ConfigurableProvidersService, + private configurationService: ConfigurationService ) { super(); } ngOnInit(): void { @@ -110,21 +112,21 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn } public hasProvider(provider: AuthProvider) { - for (let i = 0; i < environment.loginProviders.enabled.length; i++) { - if (provider === environment.loginProviders.enabled[i]) { return this.isProviderProperlyConfigured(provider); } + for (let i = 0; i < this.configurationService.loginProviders.enabled.length; i++) { + if (provider === this.configurationService.loginProviders.enabled[i]) { return this.isProviderProperlyConfigured(provider); } } return false; } private isProviderProperlyConfigured(provider: AuthProvider) { switch (provider) { - case AuthProvider.Facebook: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.facebookConfiguration); - case AuthProvider.Google: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.googleConfiguration); - case AuthProvider.LinkedIn: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.linkedInConfiguration); - case AuthProvider.Twitter: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.twitterConfiguration); - case AuthProvider.B2Access: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.b2accessConfiguration); - case AuthProvider.ORCID: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.orcidConfiguration); - case AuthProvider.OpenAire: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.openAireConfiguration); + case AuthProvider.Facebook: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.facebookConfiguration); + case AuthProvider.Google: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.googleConfiguration); + case AuthProvider.LinkedIn: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.linkedInConfiguration); + case AuthProvider.Twitter: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.twitterConfiguration); + case AuthProvider.B2Access: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.b2accessConfiguration); + case AuthProvider.ORCID: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.orcidConfiguration); + case AuthProvider.OpenAire: return this.hasAllRequiredFieldsConfigured(this.configurationService.loginProviders.openAireConfiguration); default: throw new Error('Unsupported Provider Type'); } } @@ -140,7 +142,7 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn private initializeGoogleOauth(): void { gapi.load('auth2', () => { this.auth2 = gapi.auth2.init({ - client_id: environment.loginProviders.googleConfiguration.clientId, + client_id: this.configurationService.loginProviders.googleConfiguration.clientId, scope: 'profile email' }); this.attachGoogleSignΙn(document.getElementById('googleSignInButton')); @@ -169,7 +171,7 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn */ private initializeFacebookOauth(): void { FB.init({ - appId: environment.loginProviders.facebookConfiguration.clientId, + appId: this.configurationService.loginProviders.facebookConfiguration.clientId, cookie: false, xfbml: true, version: 'v2.8' diff --git a/dmp-frontend/src/app/ui/auth/login/openaire-login/openaire-login.component.ts b/dmp-frontend/src/app/ui/auth/login/openaire-login/openaire-login.component.ts index d621cd22a..f54db7cc6 100644 --- a/dmp-frontend/src/app/ui/auth/login/openaire-login/openaire-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/openaire-login/openaire-login.component.ts @@ -7,6 +7,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-openaire-login', @@ -20,7 +21,8 @@ export class OpenAireLoginComponent extends BaseComponent implements OnInit { private loginService: LoginService, private authService: AuthService, private router: Router, - private httpClient: HttpClient + private httpClient: HttpClient, + private configurationService: ConfigurationService ) { super(); } @@ -36,18 +38,18 @@ export class OpenAireLoginComponent extends BaseComponent implements OnInit { } public openaireAuthorize() { - window.location.href = environment.loginProviders.openAireConfiguration.oauthUrl - + '?response_type=code&client_id=' + environment.loginProviders.openAireConfiguration.clientId - + '&redirect_uri=' + environment.loginProviders.openAireConfiguration.redirectUri - + '&state=' + environment.loginProviders.openAireConfiguration.state + window.location.href = this.configurationService.loginProviders.openAireConfiguration.oauthUrl + + '?response_type=code&client_id=' + this.configurationService.loginProviders.openAireConfiguration.clientId + + '&redirect_uri=' + this.configurationService.loginProviders.openAireConfiguration.redirectUri + + '&state=' + this.configurationService.loginProviders.openAireConfiguration.state + '&scope=openid profile email'; } public openaireLoginUser(code: string, state: string) { - if (state !== environment.loginProviders.openAireConfiguration.state) { + if (state !== this.configurationService.loginProviders.openAireConfiguration.state) { this.router.navigate(['/login']) } - this.httpClient.post(environment.Server + 'auth/openAireRequestToken', { code: code, provider: AuthProvider.OpenAire }) + this.httpClient.post(this.configurationService.server + 'auth/openAireRequestToken', { code: code, provider: AuthProvider.OpenAire }) .pipe(takeUntil(this._destroyed)) .subscribe((data: any) => { this.authService.login({ ticket: data.payload.accessToken, provider: AuthProvider.OpenAire, data: null }) diff --git a/dmp-frontend/src/app/ui/auth/login/orcid-login/orcid-login.component.ts b/dmp-frontend/src/app/ui/auth/login/orcid-login/orcid-login.component.ts index ea7b24e93..bfa846180 100644 --- a/dmp-frontend/src/app/ui/auth/login/orcid-login/orcid-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/orcid-login/orcid-login.component.ts @@ -9,6 +9,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-orcid-login', @@ -26,7 +27,8 @@ export class OrcidLoginComponent extends BaseComponent implements OnInit { private route: ActivatedRoute, private authService: AuthService, private loginService: LoginService, - private httpClient: HttpClient + private httpClient: HttpClient, + private configurationService: ConfigurationService ) { super(); this.orcidUser = new OrcidUser; @@ -43,18 +45,18 @@ export class OrcidLoginComponent extends BaseComponent implements OnInit { } public orcidAccessGetAuthCode() { - window.location.href = environment.loginProviders.orcidConfiguration.oauthUrl + window.location.href = this.configurationService.loginProviders.orcidConfiguration.oauthUrl + '?client_id=' - + environment.loginProviders.orcidConfiguration.clientId + + this.configurationService.loginProviders.orcidConfiguration.clientId + '&response_type=code&scope=/authenticate&redirect_uri=' - + environment.loginProviders.orcidConfiguration.redirectUri; + + this.configurationService.loginProviders.orcidConfiguration.redirectUri; } public orcidLogin(code: string) { let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json'); headers = headers.set('Accept', 'application/json'); - this.httpClient.post(environment.Server + 'auth/orcidRequestToken', { code: code }, { headers: headers }) + this.httpClient.post(this.configurationService.server + 'auth/orcidRequestToken', { code: code }, { headers: headers }) .pipe(takeUntil(this._destroyed)) .subscribe((responseData: any) => { this.orcidUser.orcidId = responseData.payload.orcidId diff --git a/dmp-frontend/src/app/ui/auth/login/twitter-login/twitter-login.component.ts b/dmp-frontend/src/app/ui/auth/login/twitter-login/twitter-login.component.ts index 66729e3c6..fdf7f7657 100644 --- a/dmp-frontend/src/app/ui/auth/login/twitter-login/twitter-login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/twitter-login/twitter-login.component.ts @@ -8,6 +8,7 @@ import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { BaseComponent } from '@common/base/base.component'; import { environment } from 'environments/environment'; import { takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-twitter-login', @@ -21,7 +22,8 @@ export class TwitterLoginComponent extends BaseComponent implements OnInit { private route: ActivatedRoute, private authService: AuthService, private httpClient: BaseHttpService, - private loginService: LoginService + private loginService: LoginService, + private configurationService: ConfigurationService ) { super(); } @@ -40,10 +42,10 @@ export class TwitterLoginComponent extends BaseComponent implements OnInit { let headers = new HttpHeaders(); headers = headers.set('Content-Type', 'application/json'); headers = headers.set('Accept', 'application/json'); - this.httpClient.get(environment.Server + 'auth/twitterRequestToken', { headers: headers }) + this.httpClient.get(this.configurationService.server + 'auth/twitterRequestToken', { headers: headers }) .pipe(takeUntil(this._destroyed)) .subscribe((data: any) => { - window.location.href = environment.loginProviders.twitterConfiguration.oauthUrl + '?oauth_token=' + data.value; + window.location.href = this.configurationService.loginProviders.twitterConfiguration.oauthUrl + '?oauth_token=' + data.value; }); } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index 2e66c4bce..cbf4d22a8 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -40,6 +40,7 @@ import { Guid } from '@common/types/guid'; import { isNullOrUndefined } from 'util'; import { AuthService } from '@app/core/services/auth/auth.service'; import { environment } from 'environments/environment'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-dataset-wizard-component', @@ -85,7 +86,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr private formService: FormService, private lockService: LockService, private location: Location, - private authService: AuthService + private authService: AuthService, + private configurationService: ConfigurationService ) { super(); } @@ -152,7 +154,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { this.lock.id = Guid.parse(result); - interval(environment.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); + interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); }); } // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. @@ -259,7 +261,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { this.lock.id = Guid.parse(result); - interval(environment.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); + interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); }); } // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index 2470b70e1..b74092256 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -42,6 +42,7 @@ import { LockModel } from '@app/core/model/lock/lock.model'; import { Guid } from '@common/types/guid'; import { isNullOrUndefined } from 'util'; import { environment } from 'environments/environment'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-dmp-editor-component', @@ -82,7 +83,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC private authentication: AuthService, private authService: AuthService, private formService: FormService, - private lockService: LockService + private lockService: LockService, + private configurationService: ConfigurationService ) { super(); } @@ -139,7 +141,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { this.lock.id = Guid.parse(result); - interval(environment.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); + interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); }); } // if (!this.isAuthenticated) { @@ -198,7 +200,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { this.lock.id = Guid.parse(result); - interval(environment.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); + interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); }); } }) diff --git a/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts b/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts index 428cf5a1d..eb5325f52 100644 --- a/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts +++ b/dmp-frontend/src/app/ui/grant/editor/grant-editor.component.ts @@ -20,6 +20,7 @@ import { TranslateService } from '@ngx-translate/core'; import { environment } from 'environments/environment'; import { Observable, of as observableOf } from 'rxjs'; import { map, takeUntil } from 'rxjs/operators'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ @@ -33,7 +34,7 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea isNew = true; grant: GrantEditorModel; formGroup: FormGroup = null; - host = environment.Server; + host: string; editMode = false; sizeError = false; maxFileSize: number = 1048576; @@ -46,9 +47,11 @@ export class GrantEditorComponent extends BaseComponent implements OnInit, IBrea private dialog: MatDialog, private grantFileUploadService: GrantFileUploadService, private uiNotificationService: UiNotificationService, - private formService: FormService + private formService: FormService, + private configurationService: ConfigurationService ) { super(); + this.host = this.configurationService.server; } ngOnInit() { diff --git a/dmp-frontend/src/app/ui/user-guide-editor/user-guide-editor.component.ts b/dmp-frontend/src/app/ui/user-guide-editor/user-guide-editor.component.ts index 142dc7192..e4e1b1aa3 100644 --- a/dmp-frontend/src/app/ui/user-guide-editor/user-guide-editor.component.ts +++ b/dmp-frontend/src/app/ui/user-guide-editor/user-guide-editor.component.ts @@ -8,6 +8,7 @@ import { TranslateService } from '@ngx-translate/core'; import { Router } from '@angular/router'; import { isNullOrUndefined } from 'util'; import { environment } from 'environments/environment'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Component({ selector: 'app-user-guide-editor', @@ -22,6 +23,7 @@ export class UserGuideEditorComponent extends BaseComponent implements OnInit { private uiNotificationService: UiNotificationService, private translate: TranslateService, private router: Router, + private configurationService: ConfigurationService ) { super(); } ngOnInit() { @@ -40,7 +42,7 @@ export class UserGuideEditorComponent extends BaseComponent implements OnInit { } private parseText(source: string): string { - source = source.replace(/src="images/g, `src="${environment.guideAssets}`); + source = source.replace(/src="images/g, `src="${this.configurationService.guideAssets}`); source = source.replace(/\r\n +>/g, '>\n'); const brokenElements = Array.from(new Set(source.match(/<\/\w+\d* >/g))); if (!isNullOrUndefined(brokenElements)) { diff --git a/dmp-frontend/src/assets/config/config.json b/dmp-frontend/src/assets/config/config.json new file mode 100644 index 000000000..7298e06b8 --- /dev/null +++ b/dmp-frontend/src/assets/config/config.json @@ -0,0 +1,48 @@ +{ + "production": false, + "Server": "http://localhost:8080/api/", + "App": "http://localhost:4200/", + "HelpService": { + "Enabled": false, + "Url": "localhost:5000/" + }, + "defaultCulture": "en-US", + "loginProviders": { + "enabled": [1, 2, 3, 4, 5, 6, 7, 8], + "facebookConfiguration": { "clientId": "" }, + "googleConfiguration": { "clientId": "" }, + "linkedInConfiguration": { + "clientId": "", + "oauthUrl": "https://www.linkedin.com/oauth/v2/authorization", + "redirectUri": "http://localhost:4200/login/linkedin", + "state": "987654321" + }, + "twitterConfiguration": { + "clientId": "", + "oauthUrl": "https://api.twitter.com/oauth/authenticate" + }, + "b2accessConfiguration": { + "clientId": "", + "oauthUrl": "https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz", + "redirectUri": "http://localhost:4200/api/oauth/authorized/b2access", + "state": "" + }, + "orcidConfiguration": { + "clientId": "", + "oauthUrl": "https://orcid.org/oauth/authorize", + "redirectUri": "http://localhost:4200/login/external/orcid" + }, + "openAireConfiguration": { + "clientId": "", + "oauthUrl": "", + "redirectUri": "", + "state": "987654321" + } + }, + "logging": { + "enabled": true, + "logLevels": ["debug", "info", "warning", "error"] + }, + "lockInterval": 60000, + "guideAssets": "assets/images/guide" +} diff --git a/dmp-frontend/src/common/http/interceptors/auth-token.interceptor.ts b/dmp-frontend/src/common/http/interceptors/auth-token.interceptor.ts index 41b5443b9..7fc64d108 100644 --- a/dmp-frontend/src/common/http/interceptors/auth-token.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/auth-token.interceptor.ts @@ -4,12 +4,14 @@ import { Observable } from 'rxjs'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; import { AuthService } from '../../../app/core/services/auth/auth.service'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class AuthTokenInterceptor extends BaseInterceptor { constructor( - private authService: AuthService) { super(); } + private authService: AuthService, + configurationService: ConfigurationService) { super(configurationService); } get type(): InterceptorType { return InterceptorType.AuthToken; } diff --git a/dmp-frontend/src/common/http/interceptors/base.interceptor.ts b/dmp-frontend/src/common/http/interceptors/base.interceptor.ts index 13374a21f..89e48679b 100644 --- a/dmp-frontend/src/common/http/interceptors/base.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/base.interceptor.ts @@ -3,10 +3,11 @@ import { Observable } from 'rxjs'; import { BaseHttpParams } from '../base-http-params'; import { InterceptorType } from './interceptor-type'; import { environment } from '../../../environments/environment'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; export abstract class BaseInterceptor implements HttpInterceptor { - constructor() { } + constructor(public configurationService: ConfigurationService) { } abstract type: InterceptorType; abstract interceptRequest(req: HttpRequest, next: HttpHandler): Observable>; @@ -25,6 +26,6 @@ export abstract class BaseInterceptor implements HttpInterceptor { } return (req.params instanceof BaseHttpParams && req.params.interceptorContext && Array.isArray(req.params.interceptorContext.interceptAllRequests) && req.params.interceptorContext.interceptAllRequests.includes(this.type)) - || req.url.startsWith(environment.Server); + || req.url.startsWith(this.configurationService.server); } } diff --git a/dmp-frontend/src/common/http/interceptors/json.interceptor.ts b/dmp-frontend/src/common/http/interceptors/json.interceptor.ts index c5bdfb4f0..d96718ee7 100644 --- a/dmp-frontend/src/common/http/interceptors/json.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/json.interceptor.ts @@ -3,12 +3,14 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class JsonInterceptor extends BaseInterceptor { constructor( - ) { super(); } + configurationService: ConfigurationService + ) { super(configurationService); } get type(): InterceptorType { return InterceptorType.JSONContentType; } diff --git a/dmp-frontend/src/common/http/interceptors/locale.interceptor.ts b/dmp-frontend/src/common/http/interceptors/locale.interceptor.ts index 5df39499a..368333760 100644 --- a/dmp-frontend/src/common/http/interceptors/locale.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/locale.interceptor.ts @@ -4,12 +4,14 @@ import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class LocaleInterceptor extends BaseInterceptor { constructor( - private language: TranslateService) { super(); } + private language: TranslateService, + configurationService: ConfigurationService) { super(configurationService); } get type(): InterceptorType { return InterceptorType.Locale; } diff --git a/dmp-frontend/src/common/http/interceptors/progress-indication.interceptor.ts b/dmp-frontend/src/common/http/interceptors/progress-indication.interceptor.ts index 939d25f41..a86defa8a 100644 --- a/dmp-frontend/src/common/http/interceptors/progress-indication.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/progress-indication.interceptor.ts @@ -5,12 +5,14 @@ import { finalize } from 'rxjs/operators'; import { ProgressIndicationService } from '../../../app/core/services/progress-indication/progress-indication-service'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class ProgressIndicationInterceptor extends BaseInterceptor { constructor( - private progressIndicationService: ProgressIndicationService) { super(); } + private progressIndicationService: ProgressIndicationService, + configurationService: ConfigurationService) { super(configurationService); } get type(): InterceptorType { return InterceptorType.ProgressIndication; } diff --git a/dmp-frontend/src/common/http/interceptors/request-timing.interceptor.ts b/dmp-frontend/src/common/http/interceptors/request-timing.interceptor.ts index 295701614..5b3615152 100644 --- a/dmp-frontend/src/common/http/interceptors/request-timing.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/request-timing.interceptor.ts @@ -5,12 +5,14 @@ import { tap } from 'rxjs/operators'; import { LoggingService } from '../../../app/core/services/logging/logging-service'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class RequestTimingInterceptor extends BaseInterceptor { constructor( - private logger: LoggingService) { super(); } + private logger: LoggingService, + configurationService: ConfigurationService) { super(configurationService); } get type(): InterceptorType { return InterceptorType.RequestTiming; } diff --git a/dmp-frontend/src/common/http/interceptors/response-payload.interceptor.ts b/dmp-frontend/src/common/http/interceptors/response-payload.interceptor.ts index f34b273d4..dab8544f8 100644 --- a/dmp-frontend/src/common/http/interceptors/response-payload.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/response-payload.interceptor.ts @@ -5,13 +5,15 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class ResponsePayloadInterceptor extends BaseInterceptor { constructor( - private snackBar: MatSnackBar - ) { super(); } + private snackBar: MatSnackBar, + configurationService: ConfigurationService + ) { super(configurationService); } get type(): InterceptorType { return InterceptorType.ResponsePayload; } diff --git a/dmp-frontend/src/common/http/interceptors/status-code.interceptor.ts b/dmp-frontend/src/common/http/interceptors/status-code.interceptor.ts index 867889a96..03ea053e2 100644 --- a/dmp-frontend/src/common/http/interceptors/status-code.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/status-code.interceptor.ts @@ -6,6 +6,7 @@ import { InterceptorType } from "./interceptor-type"; import { HttpHandler, HttpRequest, HttpEvent } from "@angular/common/http"; import { Observable } from "rxjs"; import { Router } from "@angular/router"; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class StatusCodeInterceptor extends BaseInterceptor { @@ -21,5 +22,6 @@ export class StatusCodeInterceptor extends BaseInterceptor { constructor( private router: Router, - ) { super(); } + configurationService: ConfigurationService + ) { super(configurationService); } } diff --git a/dmp-frontend/src/common/http/interceptors/unauthorized-response.interceptor.ts b/dmp-frontend/src/common/http/interceptors/unauthorized-response.interceptor.ts index 542df6dac..c33369a3b 100644 --- a/dmp-frontend/src/common/http/interceptors/unauthorized-response.interceptor.ts +++ b/dmp-frontend/src/common/http/interceptors/unauthorized-response.interceptor.ts @@ -6,6 +6,7 @@ import { catchError, mergeMap, tap } from 'rxjs/operators'; import { AuthService } from '../../../app/core/services/auth/auth.service'; import { BaseInterceptor } from './base.interceptor'; import { InterceptorType } from './interceptor-type'; +import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; @Injectable() export class UnauthorizedResponseInterceptor extends BaseInterceptor { @@ -13,7 +14,8 @@ export class UnauthorizedResponseInterceptor extends BaseInterceptor { constructor( public router: Router, private authService: AuthService, - ) { super(); } + configurationService: ConfigurationService + ) { super(configurationService); } get type(): InterceptorType { return InterceptorType.UnauthorizedResponse; }