@finos/legend-extension-dsl-data-quality 1.0.61 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. package/lib/components/{DSL_DataQuality_ClassElementDriver.d.ts → DSL_DataQuality_ElementDriver.d.ts} +17 -7
  2. package/lib/components/DSL_DataQuality_ElementDriver.d.ts.map +1 -0
  3. package/lib/components/{DSL_DataQuality_ClassElementDriver.js → DSL_DataQuality_ElementDriver.js} +70 -23
  4. package/lib/components/DSL_DataQuality_ElementDriver.js.map +1 -0
  5. package/lib/components/DSL_DataQuality_LegendStudioApplicationPlugin.d.ts.map +1 -1
  6. package/lib/components/DSL_DataQuality_LegendStudioApplicationPlugin.js +20 -39
  7. package/lib/components/DSL_DataQuality_LegendStudioApplicationPlugin.js.map +1 -1
  8. package/lib/components/{DSL_NewDataQualityClassValidationElement.d.ts → DSL_NewDataQualityValidationElement.d.ts} +2 -2
  9. package/lib/components/DSL_NewDataQualityValidationElement.d.ts.map +1 -0
  10. package/lib/components/DSL_NewDataQualityValidationElement.js +80 -0
  11. package/lib/components/DSL_NewDataQualityValidationElement.js.map +1 -0
  12. package/lib/components/DataQualityRelationTrialRuns.d.ts +22 -0
  13. package/lib/components/DataQualityRelationTrialRuns.d.ts.map +1 -0
  14. package/lib/components/DataQualityRelationTrialRuns.js +87 -0
  15. package/lib/components/DataQualityRelationTrialRuns.js.map +1 -0
  16. package/lib/components/{DSL_NewDataQualityServiceValidationElement.d.ts → DataQualityRelationValidationConfigurationEditor.d.ts} +2 -2
  17. package/lib/components/DataQualityRelationValidationConfigurationEditor.d.ts.map +1 -0
  18. package/lib/components/DataQualityRelationValidationConfigurationEditor.js +99 -0
  19. package/lib/components/DataQualityRelationValidationConfigurationEditor.js.map +1 -0
  20. package/lib/components/DataQualityRelationValidationEditor.d.ts +30 -0
  21. package/lib/components/DataQualityRelationValidationEditor.d.ts.map +1 -0
  22. package/lib/components/DataQualityRelationValidationEditor.js +89 -0
  23. package/lib/components/DataQualityRelationValidationEditor.js.map +1 -0
  24. package/lib/components/DataQualityResultPanel.d.ts.map +1 -1
  25. package/lib/components/DataQualityResultPanel.js +1 -1
  26. package/lib/components/DataQualityResultPanel.js.map +1 -1
  27. package/lib/components/DataQualityResultValues.d.ts +0 -2
  28. package/lib/components/DataQualityResultValues.d.ts.map +1 -1
  29. package/lib/components/DataQualityResultValues.js.map +1 -1
  30. package/lib/components/DataQualitySideBar.js +2 -2
  31. package/lib/components/DataQualitySideBar.js.map +1 -1
  32. package/lib/components/DataQualityValidationDetailPanel.d.ts +36 -0
  33. package/lib/components/DataQualityValidationDetailPanel.d.ts.map +1 -0
  34. package/lib/components/DataQualityValidationDetailPanel.js +39 -0
  35. package/lib/components/DataQualityValidationDetailPanel.js.map +1 -0
  36. package/lib/components/DataQualityValidationParametersEditor.d.ts +15 -0
  37. package/lib/components/DataQualityValidationParametersEditor.d.ts.map +1 -0
  38. package/lib/components/DataQualityValidationParametersEditor.js +129 -0
  39. package/lib/components/DataQualityValidationParametersEditor.js.map +1 -0
  40. package/lib/components/states/ConstraintState.d.ts +2 -0
  41. package/lib/components/states/ConstraintState.d.ts.map +1 -1
  42. package/lib/components/states/ConstraintState.js +2 -0
  43. package/lib/components/states/ConstraintState.js.map +1 -1
  44. package/lib/components/states/DataQualityClassValidationState.d.ts +2 -2
  45. package/lib/components/states/DataQualityClassValidationState.d.ts.map +1 -1
  46. package/lib/components/states/DataQualityClassValidationState.js +4 -4
  47. package/lib/components/states/DataQualityClassValidationState.js.map +1 -1
  48. package/lib/components/states/DataQualityRelationResultState.d.ts +46 -0
  49. package/lib/components/states/DataQualityRelationResultState.d.ts.map +1 -0
  50. package/lib/components/states/DataQualityRelationResultState.js +194 -0
  51. package/lib/components/states/DataQualityRelationResultState.js.map +1 -0
  52. package/lib/components/states/DataQualityRelationValidationConfigurationState.d.ts +73 -0
  53. package/lib/components/states/DataQualityRelationValidationConfigurationState.d.ts.map +1 -0
  54. package/lib/components/states/DataQualityRelationValidationConfigurationState.js +255 -0
  55. package/lib/components/states/DataQualityRelationValidationConfigurationState.js.map +1 -0
  56. package/lib/components/states/DataQualityRelationValidationLambdaEditorState.d.ts +32 -0
  57. package/lib/components/states/DataQualityRelationValidationLambdaEditorState.d.ts.map +1 -0
  58. package/lib/components/states/DataQualityRelationValidationLambdaEditorState.js +79 -0
  59. package/lib/components/states/DataQualityRelationValidationLambdaEditorState.js.map +1 -0
  60. package/lib/components/states/DataQualityRelationValidationState.d.ts +38 -0
  61. package/lib/components/states/DataQualityRelationValidationState.d.ts.map +1 -0
  62. package/lib/components/states/DataQualityRelationValidationState.js +119 -0
  63. package/lib/components/states/DataQualityRelationValidationState.js.map +1 -0
  64. package/lib/components/states/DataQualityResultState.d.ts.map +1 -1
  65. package/lib/components/states/DataQualityResultState.js +6 -3
  66. package/lib/components/states/DataQualityResultState.js.map +1 -1
  67. package/lib/components/states/DataQualityState.js +1 -1
  68. package/lib/components/states/DataQualityState.js.map +1 -1
  69. package/lib/graph/metamodel/DSL_DataQuality_HashUtils.d.ts +5 -1
  70. package/lib/graph/metamodel/DSL_DataQuality_HashUtils.d.ts.map +1 -1
  71. package/lib/graph/metamodel/DSL_DataQuality_HashUtils.js +4 -0
  72. package/lib/graph/metamodel/DSL_DataQuality_HashUtils.js.map +1 -1
  73. package/lib/graph/metamodel/DSL_DataQuality_PureGraphPlugin.d.ts.map +1 -1
  74. package/lib/graph/metamodel/DSL_DataQuality_PureGraphPlugin.js +2 -1
  75. package/lib/graph/metamodel/DSL_DataQuality_PureGraphPlugin.js.map +1 -1
  76. package/lib/graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.d.ts +36 -3
  77. package/lib/graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.d.ts.map +1 -1
  78. package/lib/graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.js +58 -4
  79. package/lib/graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.js.map +1 -1
  80. package/lib/graph-manager/DSL_DataQuality_GraphManagerHelper.d.ts +2 -1
  81. package/lib/graph-manager/DSL_DataQuality_GraphManagerHelper.d.ts.map +1 -1
  82. package/lib/graph-manager/DSL_DataQuality_GraphManagerHelper.js +2 -1
  83. package/lib/graph-manager/DSL_DataQuality_GraphManagerHelper.js.map +1 -1
  84. package/lib/graph-manager/DSL_DataQuality_GraphModifierHelper.d.ts +13 -2
  85. package/lib/graph-manager/DSL_DataQuality_GraphModifierHelper.d.ts.map +1 -1
  86. package/lib/graph-manager/DSL_DataQuality_GraphModifierHelper.js +36 -2
  87. package/lib/graph-manager/DSL_DataQuality_GraphModifierHelper.js.map +1 -1
  88. package/lib/graph-manager/DSL_DataQuality_PureGraphManagerPlugin.d.ts.map +1 -1
  89. package/lib/graph-manager/DSL_DataQuality_PureGraphManagerPlugin.js +5 -2
  90. package/lib/graph-manager/DSL_DataQuality_PureGraphManagerPlugin.js.map +1 -1
  91. package/lib/graph-manager/action/changeDetection/DSL_DataQuality_ObserverHelper.d.ts +5 -1
  92. package/lib/graph-manager/action/changeDetection/DSL_DataQuality_ObserverHelper.d.ts.map +1 -1
  93. package/lib/graph-manager/action/changeDetection/DSL_DataQuality_ObserverHelper.js +29 -2
  94. package/lib/graph-manager/action/changeDetection/DSL_DataQuality_ObserverHelper.js.map +1 -1
  95. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureGraphManagerExtension.d.ts +6 -5
  96. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureGraphManagerExtension.d.ts.map +1 -1
  97. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureGraphManagerExtension.js.map +1 -1
  98. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureProtocolProcessorPlugin.d.ts +1 -1
  99. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureProtocolProcessorPlugin.d.ts.map +1 -1
  100. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureProtocolProcessorPlugin.js +34 -40
  101. package/lib/graph-manager/protocol/pure/DSL_DataQuality_PureProtocolProcessorPlugin.js.map +1 -1
  102. package/lib/graph-manager/protocol/pure/v1/V1_DSL_Data_Quality_PureGraphManagerExtension.d.ts +8 -6
  103. package/lib/graph-manager/protocol/pure/v1/V1_DSL_Data_Quality_PureGraphManagerExtension.d.ts.map +1 -1
  104. package/lib/graph-manager/protocol/pure/v1/V1_DSL_Data_Quality_PureGraphManagerExtension.js +19 -12
  105. package/lib/graph-manager/protocol/pure/v1/V1_DSL_Data_Quality_PureGraphManagerExtension.js.map +1 -1
  106. package/lib/graph-manager/protocol/pure/v1/{V1_DataQualityConstraintsConfiguration.d.ts → V1_DataQualityValidationConfiguration.d.ts} +26 -4
  107. package/lib/graph-manager/protocol/pure/v1/V1_DataQualityValidationConfiguration.d.ts.map +1 -0
  108. package/lib/graph-manager/protocol/pure/v1/{V1_DataQualityConstraintsConfiguration.js → V1_DataQualityValidationConfiguration.js} +49 -4
  109. package/lib/graph-manager/protocol/pure/v1/V1_DataQualityValidationConfiguration.js.map +1 -0
  110. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationBuilderHelper.d.ts +7 -3
  111. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationBuilderHelper.d.ts.map +1 -1
  112. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationBuilderHelper.js +43 -3
  113. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationBuilderHelper.js.map +1 -1
  114. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationTransformer.d.ts +6 -3
  115. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationTransformer.d.ts.map +1 -1
  116. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationTransformer.js +39 -2
  117. package/lib/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationTransformer.js.map +1 -1
  118. package/lib/graph-manager/protocol/pure/v1/transformation/pureProtocol/V1_DSL_DataQuality_ProtocolHelper.d.ts +5 -2
  119. package/lib/graph-manager/protocol/pure/v1/transformation/pureProtocol/V1_DSL_DataQuality_ProtocolHelper.d.ts.map +1 -1
  120. package/lib/graph-manager/protocol/pure/v1/transformation/pureProtocol/V1_DSL_DataQuality_ProtocolHelper.js +27 -9
  121. package/lib/graph-manager/protocol/pure/v1/transformation/pureProtocol/V1_DSL_DataQuality_ProtocolHelper.js.map +1 -1
  122. package/lib/index.css +2 -2
  123. package/lib/index.css.map +1 -1
  124. package/lib/package.json +1 -1
  125. package/package.json +7 -7
  126. package/src/components/{DSL_DataQuality_ClassElementDriver.tsx → DSL_DataQuality_ElementDriver.tsx} +87 -18
  127. package/src/components/DSL_DataQuality_LegendStudioApplicationPlugin.tsx +33 -48
  128. package/src/components/DSL_NewDataQualityValidationElement.tsx +208 -0
  129. package/src/components/DataQualityRelationTrialRuns.tsx +288 -0
  130. package/src/components/DataQualityRelationValidationConfigurationEditor.tsx +364 -0
  131. package/src/components/DataQualityRelationValidationEditor.tsx +290 -0
  132. package/src/components/DataQualityResultPanel.tsx +1 -4
  133. package/src/components/DataQualityResultValues.tsx +1 -5
  134. package/src/components/DataQualitySideBar.tsx +2 -2
  135. package/src/components/DataQualityValidationDetailPanel.tsx +182 -0
  136. package/src/components/DataQualityValidationParametersEditor.tsx +355 -0
  137. package/src/components/states/ConstraintState.ts +2 -0
  138. package/src/components/states/DataQualityClassValidationState.ts +5 -5
  139. package/src/components/states/DataQualityRelationResultState.ts +274 -0
  140. package/src/components/states/DataQualityRelationValidationConfigurationState.ts +429 -0
  141. package/src/components/states/DataQualityRelationValidationLambdaEditorState.ts +138 -0
  142. package/src/components/states/DataQualityRelationValidationState.ts +180 -0
  143. package/src/components/states/DataQualityResultState.ts +6 -8
  144. package/src/components/states/DataQualityState.ts +1 -1
  145. package/src/graph/metamodel/DSL_DataQuality_HashUtils.ts +4 -0
  146. package/src/graph/metamodel/DSL_DataQuality_PureGraphPlugin.ts +2 -0
  147. package/src/graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.ts +79 -3
  148. package/src/graph-manager/DSL_DataQuality_GraphManagerHelper.ts +13 -0
  149. package/src/graph-manager/DSL_DataQuality_GraphModifierHelper.ts +107 -0
  150. package/src/graph-manager/DSL_DataQuality_PureGraphManagerPlugin.ts +8 -0
  151. package/src/graph-manager/action/changeDetection/DSL_DataQuality_ObserverHelper.ts +54 -1
  152. package/src/graph-manager/protocol/pure/DSL_DataQuality_PureGraphManagerExtension.ts +5 -3
  153. package/src/graph-manager/protocol/pure/DSL_DataQuality_PureProtocolProcessorPlugin.ts +72 -81
  154. package/src/graph-manager/protocol/pure/v1/V1_DSL_Data_Quality_PureGraphManagerExtension.ts +20 -23
  155. package/src/graph-manager/protocol/pure/v1/{V1_DataQualityConstraintsConfiguration.ts → V1_DataQualityValidationConfiguration.ts} +63 -4
  156. package/src/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationBuilderHelper.ts +116 -2
  157. package/src/graph-manager/protocol/pure/v1/transformation/V1_DSL_DataQuality_ValueSpecificationTransformer.ts +78 -1
  158. package/src/graph-manager/protocol/pure/v1/transformation/pureProtocol/V1_DSL_DataQuality_ProtocolHelper.ts +55 -8
  159. package/style/_data-quality-relation-validation-builder.scss +454 -0
  160. package/style/index.scss +6 -0
  161. package/tsconfig.json +13 -6
  162. package/lib/components/DSL_DataQuality_ClassElementDriver.d.ts.map +0 -1
  163. package/lib/components/DSL_DataQuality_ClassElementDriver.js.map +0 -1
  164. package/lib/components/DSL_DataQuality_ServiceElementDriver.d.ts +0 -27
  165. package/lib/components/DSL_DataQuality_ServiceElementDriver.d.ts.map +0 -1
  166. package/lib/components/DSL_DataQuality_ServiceElementDriver.js +0 -41
  167. package/lib/components/DSL_DataQuality_ServiceElementDriver.js.map +0 -1
  168. package/lib/components/DSL_NewDataQualityClassValidationElement.d.ts.map +0 -1
  169. package/lib/components/DSL_NewDataQualityClassValidationElement.js +0 -64
  170. package/lib/components/DSL_NewDataQualityClassValidationElement.js.map +0 -1
  171. package/lib/components/DSL_NewDataQualityServiceValidationElement.d.ts.map +0 -1
  172. package/lib/components/DSL_NewDataQualityServiceValidationElement.js +0 -41
  173. package/lib/components/DSL_NewDataQualityServiceValidationElement.js.map +0 -1
  174. package/lib/graph-manager/protocol/pure/v1/V1_DataQualityConstraintsConfiguration.d.ts.map +0 -1
  175. package/lib/graph-manager/protocol/pure/v1/V1_DataQualityConstraintsConfiguration.js.map +0 -1
  176. package/src/components/DSL_DataQuality_ServiceElementDriver.tsx +0 -57
  177. package/src/components/DSL_NewDataQualityClassValidationElement.tsx +0 -156
  178. package/src/components/DSL_NewDataQualityServiceValidationElement.tsx +0 -74
@@ -0,0 +1,429 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ type EditorStore,
19
+ ElementEditorState,
20
+ } from '@finos/legend-application-studio';
21
+
22
+ import {
23
+ type DataQualityRelationValidation,
24
+ DataQualityRelationValidationConfiguration,
25
+ RelationValidationType,
26
+ } from '../../graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.js';
27
+ import {
28
+ type GeneratorFn,
29
+ assertErrorThrown,
30
+ assertType,
31
+ guaranteeNonNullable,
32
+ guaranteeType,
33
+ hashArray,
34
+ LogEvent,
35
+ filterByType,
36
+ } from '@finos/legend-shared';
37
+ import {
38
+ type ExecutionResult,
39
+ type ExecutionResultWithMetadata,
40
+ buildSourceInformationSourceId,
41
+ GRAPH_MANAGER_EVENT,
42
+ isStubbed_PackageableElement,
43
+ isStubbed_RawLambda,
44
+ ParserError,
45
+ RawLambda,
46
+ buildLambdaVariableExpressions,
47
+ observe_ValueSpecification,
48
+ VariableExpression,
49
+ } from '@finos/legend-graph';
50
+ import {
51
+ action,
52
+ computed,
53
+ flow,
54
+ flowResult,
55
+ makeObservable,
56
+ observable,
57
+ } from 'mobx';
58
+ import {
59
+ LambdaEditorState,
60
+ LambdaParametersState,
61
+ LambdaParameterState,
62
+ PARAMETER_SUBMIT_ACTION,
63
+ } from '@finos/legend-query-builder';
64
+ import { DataQualityRelationValidationState } from './DataQualityRelationValidationState.js';
65
+ import { DataQualityRelationResultState } from './DataQualityRelationResultState.js';
66
+ import { DATA_QUALITY_HASH_STRUCTURE } from '../../graph/metamodel/DSL_DataQuality_HashUtils.js';
67
+ import type { SelectOption } from '@finos/legend-art';
68
+
69
+ export enum DATA_QUALITY_RELATION_VALIDATION_EDITOR_TAB {
70
+ DEFINITION = 'Definition',
71
+ TRIAL_RUN = 'Trial Run',
72
+ }
73
+
74
+ export class RelationFunctionDefinitionEditorState extends LambdaEditorState {
75
+ readonly editorStore: EditorStore;
76
+ readonly relationValidationElement: DataQualityRelationValidationConfiguration;
77
+
78
+ isConvertingFunctionBodyToString = false;
79
+
80
+ constructor(
81
+ relationValidationElement: DataQualityRelationValidationConfiguration,
82
+ editorStore: EditorStore,
83
+ ) {
84
+ super('', '|');
85
+
86
+ makeObservable(this, {
87
+ relationValidationElement: observable,
88
+ isConvertingFunctionBodyToString: observable,
89
+ });
90
+
91
+ this.relationValidationElement = relationValidationElement;
92
+ this.editorStore = editorStore;
93
+ }
94
+
95
+ get lambdaId(): string {
96
+ return buildSourceInformationSourceId([
97
+ this.relationValidationElement.path,
98
+ ]);
99
+ }
100
+
101
+ *convertLambdaGrammarStringToObject(): GeneratorFn<void> {
102
+ if (this.lambdaString) {
103
+ try {
104
+ const lambda =
105
+ (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda(
106
+ this.fullLambdaString,
107
+ this.lambdaId,
108
+ )) as RawLambda;
109
+ this.setParserError(undefined);
110
+ this.relationValidationElement.query.body = lambda.body;
111
+ } catch (error) {
112
+ assertErrorThrown(error);
113
+ if (error instanceof ParserError) {
114
+ this.setParserError(error);
115
+ }
116
+ this.editorStore.applicationStore.logService.error(
117
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
118
+ error,
119
+ );
120
+ }
121
+ } else {
122
+ this.clearErrors();
123
+ this.relationValidationElement.query.body = new RawLambda(
124
+ undefined,
125
+ undefined,
126
+ ).body;
127
+ this.relationValidationElement.query.parameters = [];
128
+ }
129
+ }
130
+
131
+ *convertLambdaObjectToGrammarString(options?: {
132
+ pretty?: boolean | undefined;
133
+ preserveCompilationError?: boolean | undefined;
134
+ firstLoad?: boolean | undefined;
135
+ }): GeneratorFn<void> {
136
+ if (!isStubbed_PackageableElement(this.relationValidationElement)) {
137
+ this.isConvertingFunctionBodyToString = true;
138
+ try {
139
+ const lambdas = new Map<string, RawLambda>();
140
+ const functionLamba = new RawLambda(
141
+ [],
142
+ this.relationValidationElement.query.body,
143
+ );
144
+ lambdas.set(this.lambdaId, functionLamba);
145
+ const isolatedLambdas =
146
+ (yield this.editorStore.graphManagerState.graphManager.lambdasToPureCode(
147
+ lambdas,
148
+ options?.pretty,
149
+ )) as Map<string, string>;
150
+ const grammarText = isolatedLambdas.get(this.lambdaId);
151
+ if (grammarText) {
152
+ this.setLambdaString(this.extractLambdaString(grammarText));
153
+ } else {
154
+ this.setLambdaString('');
155
+ }
156
+ // `firstLoad` flag is used in the first rendering of the function editor (in a `useEffect`)
157
+ // This flag helps block editing while the JSON is converting to text and to avoid reseting parser/compiler error in reveal error
158
+ if (!options?.firstLoad) {
159
+ this.clearErrors({
160
+ preserveCompilationError: options?.preserveCompilationError,
161
+ });
162
+ }
163
+ this.isConvertingFunctionBodyToString = false;
164
+ } catch (error) {
165
+ assertErrorThrown(error);
166
+ this.editorStore.applicationStore.logService.error(
167
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
168
+ error,
169
+ );
170
+ this.isConvertingFunctionBodyToString = false;
171
+ }
172
+ } else {
173
+ this.clearErrors();
174
+ this.setLambdaString('');
175
+ }
176
+ }
177
+
178
+ get hashCode(): string {
179
+ return hashArray([
180
+ DATA_QUALITY_HASH_STRUCTURE.DATA_QUALITY_RELATION_FUNCTION_DEFINITION,
181
+ this.lambdaString,
182
+ ]);
183
+ }
184
+ }
185
+
186
+ export class RelationDefinitionParameterState extends LambdaParametersState {
187
+ readonly relationValidationConfigurationState: DataQualityRelationValidationConfigurationState;
188
+
189
+ constructor(
190
+ relationValidationConfigurationState: DataQualityRelationValidationConfigurationState,
191
+ ) {
192
+ super();
193
+ makeObservable(this, {
194
+ parameterValuesEditorState: observable,
195
+ parameterStates: observable,
196
+ addParameter: action,
197
+ removeParameter: action,
198
+ openModal: action,
199
+ build: action,
200
+ setParameters: action,
201
+ });
202
+ this.relationValidationConfigurationState =
203
+ relationValidationConfigurationState;
204
+ }
205
+
206
+ openModal(lambda: RawLambda): void {
207
+ this.parameterStates = this.build(lambda);
208
+ this.parameterValuesEditorState.open(
209
+ (): Promise<void> =>
210
+ flowResult(
211
+ this.relationValidationConfigurationState.resultState.runValidation(),
212
+ )
213
+ .catch(
214
+ this.relationValidationConfigurationState.editorStore
215
+ .applicationStore.alertUnhandledError,
216
+ )
217
+ .catch(
218
+ this.relationValidationConfigurationState.editorStore
219
+ .applicationStore.alertUnhandledError,
220
+ ),
221
+ PARAMETER_SUBMIT_ACTION.RUN,
222
+ );
223
+ }
224
+
225
+ build(lambda: RawLambda): LambdaParameterState[] {
226
+ const parameters = buildLambdaVariableExpressions(
227
+ lambda,
228
+ this.relationValidationConfigurationState.editorStore.graphManagerState,
229
+ )
230
+ .map((parameter) =>
231
+ observe_ValueSpecification(
232
+ parameter,
233
+ this.relationValidationConfigurationState.editorStore
234
+ .changeDetectionState.observerContext,
235
+ ),
236
+ )
237
+ .filter(filterByType(VariableExpression));
238
+ const states = parameters.map((variable) => {
239
+ const parmeterState = new LambdaParameterState(
240
+ variable,
241
+ this.relationValidationConfigurationState.editorStore.changeDetectionState.observerContext,
242
+ this.relationValidationConfigurationState.editorStore.graphManagerState.graph,
243
+ );
244
+ parmeterState.mockParameterValue();
245
+ return parmeterState;
246
+ });
247
+ return states;
248
+ }
249
+ }
250
+
251
+ export class DataQualityRelationValidationConfigurationState extends ElementEditorState {
252
+ readonly relationFunctionDefinitionEditorState: RelationFunctionDefinitionEditorState;
253
+ selectedTab: DATA_QUALITY_RELATION_VALIDATION_EDITOR_TAB;
254
+
255
+ isRunningFunc = false;
256
+ funcRunPromise: Promise<ExecutionResultWithMetadata> | undefined = undefined;
257
+ executionResult?: ExecutionResult | undefined; // NOTE: stored as lossless JSON string
258
+ validationStates: DataQualityRelationValidationState[] = [];
259
+ parametersState: RelationDefinitionParameterState;
260
+ isConvertingValidationLambdaObjects = false;
261
+ resultState: DataQualityRelationResultState;
262
+
263
+ constructor(
264
+ editorStore: EditorStore,
265
+ element: DataQualityRelationValidationConfiguration,
266
+ ) {
267
+ super(editorStore, element);
268
+
269
+ makeObservable(this, {
270
+ selectedTab: observable,
271
+ isRunningFunc: observable,
272
+ funcRunPromise: observable,
273
+ executionResult: observable,
274
+ setSelectedTab: action,
275
+ setFuncRunPromise: action,
276
+ setExecutionResult: action,
277
+ addValidationState: action,
278
+ validationElement: computed,
279
+ relationValidationOptions: computed,
280
+ convertValidationLambdaObjects: flow,
281
+ });
282
+ assertType(
283
+ element,
284
+ DataQualityRelationValidationConfiguration,
285
+ 'Element inside data quality relation validation editor state must be a data quality relation validation element',
286
+ );
287
+ this.relationFunctionDefinitionEditorState =
288
+ new RelationFunctionDefinitionEditorState(element, this.editorStore);
289
+ this.selectedTab = DATA_QUALITY_RELATION_VALIDATION_EDITOR_TAB.DEFINITION;
290
+ this.validationElement.validations.forEach((validation) => {
291
+ this.validationStates.push(
292
+ new DataQualityRelationValidationState(validation, editorStore),
293
+ );
294
+ });
295
+ this.parametersState = new RelationDefinitionParameterState(this);
296
+ this.resultState = new DataQualityRelationResultState(this);
297
+ }
298
+
299
+ reprocess(
300
+ newElement: DataQualityRelationValidationConfiguration,
301
+ editorStore: EditorStore,
302
+ ): DataQualityRelationValidationConfigurationState {
303
+ return new DataQualityRelationValidationConfigurationState(
304
+ editorStore,
305
+ newElement,
306
+ );
307
+ }
308
+
309
+ get validationElement(): DataQualityRelationValidationConfiguration {
310
+ return guaranteeType(
311
+ this.element,
312
+ DataQualityRelationValidationConfiguration,
313
+ 'Element inside data quality relation validation state must be a data quality relation validation configuration element',
314
+ );
315
+ }
316
+
317
+ getNullableValidationState = (
318
+ relationValidation: DataQualityRelationValidation,
319
+ ): DataQualityRelationValidationState | undefined =>
320
+ this.validationStates.find(
321
+ (validationState) =>
322
+ validationState.relationValidation === relationValidation,
323
+ );
324
+
325
+ getValidationState = (
326
+ validation: DataQualityRelationValidation,
327
+ ): DataQualityRelationValidationState =>
328
+ guaranteeNonNullable(
329
+ this.getNullableValidationState(validation),
330
+ `Can't find validation state for validation ${validation}`,
331
+ );
332
+
333
+ get relationValidationOptions(): SelectOption[] {
334
+ return Object.values(RelationValidationType).map((type) => ({
335
+ label: type,
336
+ value: type,
337
+ }));
338
+ }
339
+ addValidationState(validation: DataQualityRelationValidation): void {
340
+ if (
341
+ !this.validationStates.find(
342
+ (validationState) => validationState.relationValidation === validation,
343
+ )
344
+ ) {
345
+ this.validationStates.push(
346
+ new DataQualityRelationValidationState(validation, this.editorStore),
347
+ );
348
+ }
349
+ }
350
+
351
+ deleteValidationState(validation: DataQualityRelationValidation): void {
352
+ const idx = this.validationStates.findIndex(
353
+ (validationState) => validationState.relationValidation === validation,
354
+ );
355
+ if (idx !== -1) {
356
+ this.validationStates.splice(idx, 1);
357
+ }
358
+ }
359
+
360
+ setFuncRunPromise = (
361
+ promise: Promise<ExecutionResultWithMetadata> | undefined,
362
+ ): void => {
363
+ this.funcRunPromise = promise;
364
+ };
365
+
366
+ setSelectedTab(tab: DATA_QUALITY_RELATION_VALIDATION_EDITOR_TAB): void {
367
+ this.selectedTab = tab;
368
+ }
369
+
370
+ setExecutionResult = (executionResult: ExecutionResult | undefined): void => {
371
+ this.executionResult = executionResult;
372
+ };
373
+
374
+ *convertValidationLambdaObjects(): GeneratorFn<void> {
375
+ const lambdas = new Map<string, RawLambda>();
376
+ const index = new Map<string, DataQualityRelationValidationState>();
377
+ this.validationStates.forEach((validationState) => {
378
+ if (!isStubbed_RawLambda(validationState.relationValidation.assertion)) {
379
+ lambdas.set(
380
+ validationState.lambdaId,
381
+ validationState.relationValidation.assertion,
382
+ );
383
+ index.set(validationState.lambdaId, validationState);
384
+ }
385
+ });
386
+ if (lambdas.size) {
387
+ this.isConvertingValidationLambdaObjects = true;
388
+ try {
389
+ const isolatedLambdas =
390
+ (yield this.editorStore.graphManagerState.graphManager.lambdasToPureCode(
391
+ lambdas,
392
+ )) as Map<string, string>;
393
+ isolatedLambdas.forEach((grammarText, key) => {
394
+ const validationState = index.get(key);
395
+ validationState?.setLambdaString(
396
+ validationState.extractLambdaString(grammarText),
397
+ );
398
+ });
399
+ } catch (error) {
400
+ assertErrorThrown(error);
401
+ this.editorStore.applicationStore.logService.error(
402
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
403
+ error,
404
+ );
405
+ } finally {
406
+ this.isConvertingValidationLambdaObjects = false;
407
+ }
408
+ }
409
+ }
410
+
411
+ get bodyExpressionSequence(): RawLambda {
412
+ return new RawLambda(
413
+ this.validationElement.query.parameters.map((parameter) =>
414
+ this.editorStore.graphManagerState.graphManager.serializeRawValueSpecification(
415
+ parameter,
416
+ ),
417
+ ),
418
+ this.validationElement.query.body,
419
+ );
420
+ }
421
+
422
+ get hashCode(): string {
423
+ return hashArray([
424
+ DATA_QUALITY_HASH_STRUCTURE.DATA_QUALITY_RELATION_VALIDATION,
425
+ this.relationFunctionDefinitionEditorState,
426
+ hashArray(this.validationStates),
427
+ ]);
428
+ }
429
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DataQualityRelationValidation } from '../../graph/metamodel/pure/packageableElements/data-quality/DataQualityValidationConfiguration.js';
17
+ import type { EditorStore } from '@finos/legend-application-studio';
18
+ import { makeObservable, observable } from 'mobx';
19
+ import {
20
+ type GeneratorFn,
21
+ assertErrorThrown,
22
+ hashArray,
23
+ LogEvent,
24
+ } from '@finos/legend-shared';
25
+ import {
26
+ type RawLambda,
27
+ buildSourceInformationSourceId,
28
+ GRAPH_MANAGER_EVENT,
29
+ isStubbed_RawLambda,
30
+ ParserError,
31
+ stub_RawLambda,
32
+ } from '@finos/legend-graph';
33
+ import { LambdaEditorState } from '@finos/legend-query-builder';
34
+ import { VALIDATION_ROW_MAP_ID_LABEL } from './ConstraintState.js';
35
+ import { dataQualityRelationValidation_setRowMapFunction } from '../../graph-manager/DSL_DataQuality_GraphModifierHelper.js';
36
+ import { DATA_QUALITY_HASH_STRUCTURE } from '../../graph/metamodel/DSL_DataQuality_HashUtils.js';
37
+
38
+ export class DataQualityRelationValidationLambdaEditorState extends LambdaEditorState {
39
+ relationValidation: DataQualityRelationValidation;
40
+ editorStore: EditorStore;
41
+ constructor(
42
+ relationValidation: DataQualityRelationValidation,
43
+ editorStore: EditorStore,
44
+ ) {
45
+ super('true', '|');
46
+
47
+ makeObservable(this, {
48
+ relationValidation: observable,
49
+ editorStore: observable,
50
+ });
51
+
52
+ this.relationValidation = relationValidation;
53
+ this.editorStore = editorStore;
54
+ }
55
+
56
+ get lambdaId(): string {
57
+ return buildSourceInformationSourceId([
58
+ VALIDATION_ROW_MAP_ID_LABEL,
59
+ this.relationValidation.name,
60
+ this.uuid, // in case of duplications
61
+ ]);
62
+ }
63
+
64
+ *convertLambdaGrammarStringToObject(): GeneratorFn<void> {
65
+ const emptyFunctionDefinition = stub_RawLambda();
66
+ if (this.lambdaString) {
67
+ try {
68
+ const lambda =
69
+ (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda(
70
+ this.fullLambdaString,
71
+ this.lambdaId,
72
+ )) as RawLambda;
73
+ this.setParserError(undefined);
74
+ dataQualityRelationValidation_setRowMapFunction(
75
+ this.relationValidation,
76
+ lambda,
77
+ );
78
+ } catch (error) {
79
+ assertErrorThrown(error);
80
+ if (error instanceof ParserError) {
81
+ this.setParserError(error);
82
+ }
83
+ this.editorStore.applicationStore.logService.error(
84
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
85
+ error,
86
+ );
87
+ }
88
+ } else {
89
+ this.clearErrors();
90
+ dataQualityRelationValidation_setRowMapFunction(
91
+ this.relationValidation,
92
+ emptyFunctionDefinition,
93
+ );
94
+ }
95
+ }
96
+
97
+ *convertLambdaObjectToGrammarString(options?: {
98
+ pretty?: boolean | undefined;
99
+ preserveCompilationError?: boolean | undefined;
100
+ }): GeneratorFn<void> {
101
+ if (!isStubbed_RawLambda(this.relationValidation.rowMapFunction!)) {
102
+ try {
103
+ const lambdas = new Map<string, RawLambda>();
104
+ lambdas.set(this.lambdaId, this.relationValidation.rowMapFunction!);
105
+ const isolatedLambdas =
106
+ (yield this.editorStore.graphManagerState.graphManager.lambdasToPureCode(
107
+ lambdas,
108
+ options?.pretty,
109
+ )) as Map<string, string>;
110
+ const grammarText = isolatedLambdas.get(this.lambdaId);
111
+ this.setLambdaString(
112
+ grammarText !== undefined
113
+ ? this.extractLambdaString(grammarText)
114
+ : '',
115
+ );
116
+ this.clearErrors({
117
+ preserveCompilationError: options?.preserveCompilationError,
118
+ });
119
+ } catch (error) {
120
+ assertErrorThrown(error);
121
+ this.editorStore.applicationStore.logService.error(
122
+ LogEvent.create(GRAPH_MANAGER_EVENT.PARSING_FAILURE),
123
+ error,
124
+ );
125
+ }
126
+ } else {
127
+ this.clearErrors();
128
+ this.setLambdaString('');
129
+ }
130
+ }
131
+
132
+ get hashCode(): string {
133
+ return hashArray([
134
+ DATA_QUALITY_HASH_STRUCTURE.DATA_QUALITY_RELATION_VALIDATION,
135
+ this.lambdaString,
136
+ ]);
137
+ }
138
+ }