/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { DepotServerClient } from '@finos/legend-server-depot'; import { type ApplicationStore, LegendApplicationTelemetryHelper, APPLICATION_EVENT, } from '@finos/legend-application'; import type { LegendQueryPluginManager } from '../application/LegendQueryPluginManager.js'; import type { LegendQueryApplicationConfig } from '../application/LegendQueryApplicationConfig.js'; import { ActionState, assertErrorThrown, LogEvent, type GeneratorFn, } from '@finos/legend-shared'; import { flow, makeObservable } from 'mobx'; import { getCurrentUserIDFromEngineServer } from '@finos/legend-graph'; export type LegendQueryApplicationStore = ApplicationStore< LegendQueryApplicationConfig, LegendQueryPluginManager >; export class LegendQueryBaseStore { readonly applicationStore: LegendQueryApplicationStore; readonly depotServerClient: DepotServerClient; readonly pluginManager: LegendQueryPluginManager; readonly initState = ActionState.create(); constructor(applicationStore: LegendQueryApplicationStore) { makeObservable(this, { initialize: flow, }); this.applicationStore = applicationStore; this.pluginManager = applicationStore.pluginManager; // setup servers this.depotServerClient = new DepotServerClient({ serverUrl: this.applicationStore.config.depotServerUrl, }); this.depotServerClient.setTracerService( this.applicationStore.tracerService, ); } *initialize(): GeneratorFn { if (!this.initState.isInInitialState) { this.applicationStore.notificationService.notifyIllegalState( 'Base store is re-initialized', ); return; } this.initState.inProgress(); try { this.applicationStore.identityService.setCurrentUser( (yield getCurrentUserIDFromEngineServer( this.applicationStore.config.engineServerUrl, )) as string, ); } catch (error) { assertErrorThrown(error); this.applicationStore.logService.error( LogEvent.create(APPLICATION_EVENT.IDENTITY_AUTO_FETCH__FAILURE), error, ); this.applicationStore.notificationService.notifyWarning(error.message); } // setup telemetry service this.applicationStore.telemetryService.setup(); LegendApplicationTelemetryHelper.logEvent_ApplicationInitializationSucceeded( this.applicationStore.telemetryService, this.applicationStore, ); this.initState.complete(); } }