UNPKG

@itwin/core-backend

Version:
89 lines 3.91 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { BentleyError, CompressedId64Set, Logger } from "@itwin/core-bentley"; import { BackendLoggerCategory } from "./BackendLoggerCategory"; /** @internal */ export class ViewStateHydrator { _imodel; constructor(iModel) { this._imodel = iModel; } async getHydrateResponseProps(options) { const response = {}; const promises = []; if (options.acsId) promises.push(this.handleAcsId(response, options.acsId)); if (options.sheetViewAttachmentIds) promises.push(this.handleSheetViewAttachmentIds(response, options.sheetViewAttachmentIds, options.viewStateLoadProps)); if (options.spatialViewId) promises.push(this.handleSpatialViewId(response, options.spatialViewId, options.viewStateLoadProps)); if (options.notLoadedModelSelectorStateModels) promises.push(this.handleModelSelectorStateModels(response, options.notLoadedModelSelectorStateModels)); if (options.baseModelId) promises.push(this.handleBaseModelId(response, options.baseModelId)); await Promise.all(promises); return response; } async handleBaseModelId(response, baseModelId) { let modelProps; try { modelProps = this._imodel.models.getModelProps(baseModelId); } catch (err) { Logger.logError(BackendLoggerCategory.ViewStateHydrator, `Error getting modelProps for baseModelId: ${baseModelId}`, () => ({ error: BentleyError.getErrorProps(err) })); } response.baseModelProps = modelProps; } async handleModelSelectorStateModels(response, models) { const decompressedModelIds = CompressedId64Set.decompressSet(models); const modelJsonArray = []; for (const id of decompressedModelIds) { try { const modelProps = this._imodel.models.getModelProps(id); modelJsonArray.push(modelProps); } catch { } } response.modelSelectorStateModels = modelJsonArray; } async handleSpatialViewId(response, spatialViewId, viewStateLoadProps) { response.spatialViewProps = await this._imodel.views.getViewStateProps(spatialViewId, viewStateLoadProps); } async handleAcsId(response, acsId) { try { const props = this._imodel.elements.getElementProps(acsId); response.acsElementProps = props; } catch { } } async handleSheetViewAttachmentIds(response, sheetViewAttachmentIds, viewStateLoadProps) { const decompressedIds = CompressedId64Set.decompressSet(sheetViewAttachmentIds); const attachmentProps = []; for (const id of decompressedIds) { try { attachmentProps.push(this._imodel.elements.getElementProps({ id })); } catch { } } const promises = []; for (const attachment of attachmentProps) { const loadView = async () => { try { const view = await this._imodel.views.getViewStateProps(attachment.view.id, viewStateLoadProps); return view; } catch { return undefined; } }; promises.push(loadView()); } const views = await Promise.all(promises); response.sheetViewViews = views; response.sheetViewAttachmentProps = attachmentProps; return; } } //# sourceMappingURL=ViewStateHydrator.js.map