UNPKG

@finos/legend-extension-dsl-data-quality

Version:
110 lines 4.79 kB
import {} from '@finos/legend-application-studio'; import { action, computed, makeObservable, observable } from 'mobx'; import { assertErrorThrown, hashArray, LogEvent, } from '@finos/legend-shared'; import { buildSourceInformationSourceId, GRAPH_MANAGER_EVENT, isStubbed_RawLambda, ParserError, stub_RawLambda, } from '@finos/legend-graph'; import { LambdaEditorWithGUIState } from './LambdaEditorWithGUIState.js'; import { VALIDATION_SOURCE_ID_LABEL } from './ConstraintState.js'; import { dataQualityRelationValidation_setAssertion, dataQualityRelationValidation_setType, } from '../../graph-manager/DSL_DataQuality_GraphModifierHelper.js'; import { DATA_QUALITY_HASH_STRUCTURE } from '../../graph/metamodel/DSL_DataQuality_HashUtils.js'; export class DataQualityRelationValidationState extends LambdaEditorWithGUIState { relationValidation; editorStore; isValidationDialogOpen = false; initializedGUIEditor = false; // only used for validation suggestions isSelected = false; constructor(relationValidation, editorStore) { super('true', ''); makeObservable(this, { relationValidation: observable, editorStore: observable, isValidationDialogOpen: observable, isSelected: observable, hashCode: computed, setIsSelected: action, setIsValidationDialogOpen: action, onValidationTypeChange: action, initializedGUIEditor: observable, initializeWithColumns: action, }); this.relationValidation = relationValidation; this.editorStore = editorStore; } initializeWithColumns(columns) { if (columns.length) { this.initializeGUIEditor(columns); this.initializedGUIEditor = true; } } get lambdaId() { return buildSourceInformationSourceId([ VALIDATION_SOURCE_ID_LABEL, this.relationValidation.name, this.uuid, // in case of duplications ]); } setIsSelected(b) { this.isSelected = b; } setIsValidationDialogOpen(isValidationDialogOpen) { this.isValidationDialogOpen = isValidationDialogOpen; } onValidationTypeChange(val) { dataQualityRelationValidation_setType(this.relationValidation, val.value); } *convertLambdaGrammarStringToObject() { const emptyFunctionDefinition = stub_RawLambda(); if (this.lambdaString) { try { this.disableEditorToggle = true; const lambda = (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda(this.fullLambdaString, this.lambdaId)); this.setParserError(undefined); dataQualityRelationValidation_setAssertion(this.relationValidation, lambda); this.tryParsingPureLambdaToGUIFormat(); this.disableEditorToggle = false; } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { this.setParserError(error); } this.editorStore.applicationStore.logService.error(LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE), error); } } else { this.clearErrors(); dataQualityRelationValidation_setAssertion(this.relationValidation, emptyFunctionDefinition); } } *convertLambdaObjectToGrammarString(options) { if (!isStubbed_RawLambda(this.relationValidation.assertion)) { try { const lambdas = new Map(); lambdas.set(this.lambdaId, this.relationValidation.assertion); const isolatedLambdas = (yield this.editorStore.graphManagerState.graphManager.lambdasToPureCode(lambdas, options?.pretty)); const grammarText = isolatedLambdas.get(this.lambdaId); this.setLambdaString(grammarText !== undefined ? this.extractLambdaString(grammarText) : ''); this.clearErrors({ preserveCompilationError: options?.preserveCompilationError, }); } catch (error) { assertErrorThrown(error); this.editorStore.applicationStore.logService.error(LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE), error); } } else { this.clearErrors(); this.setLambdaString(''); } } get hashCode() { return hashArray([ DATA_QUALITY_HASH_STRUCTURE.DATA_QUALITY_RELATION_VALIDATION, this.lambdaString, ]); } } //# sourceMappingURL=DataQualityRelationValidationState.js.map