Skip to content

Commit

Permalink
improve support for extensions in tests (#2414)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Jul 10, 2023
1 parent e4cfe7a commit f764ced
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .changeset/tricky-donkeys-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
'@finos/legend-extension-store-service-store': patch
'@finos/legend-application-studio': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ const StoreTestDataEditor = observer(
if (isUsingReference) {
const newBare = returnUndefOnError(() =>
currentData.accept_EmbeddedDataVisitor(
new EmbeddedDataCreatorFromEmbeddedData(),
new EmbeddedDataCreatorFromEmbeddedData(
mappingTestState.editorStore,
),
),
);
if (newBare) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class MappingTestSuiteState extends TestableTestSuiteEditorState {
firstData.store.value,
);
storeTestData.data = firstData.data.accept_EmbeddedDataVisitor(
new EmbeddedDataCreatorFromEmbeddedData(),
new EmbeddedDataCreatorFromEmbeddedData(this.editorStore),
);
return storeTestData;
} else if (targetClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
assertTrue,
guaranteeNonNullable,
} from '@finos/legend-shared';
import type { DSL_Data_LegendStudioApplicationPlugin_Extension } from '../../../../../extensions/DSL_Data_LegendStudioApplicationPlugin_Extension.js';

export const createGraphFetchRawLambda = (
mainClass: Class,
Expand Down Expand Up @@ -137,6 +138,20 @@ export const generateStoreTestDataFromSetImpl = (
return createStoreBareModelStoreData(srcClass.value, editorStore);
}
}
const extraStoreDataCreators = editorStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) =>
(
plugin as DSL_Data_LegendStudioApplicationPlugin_Extension
).getExtraStoreTestDataCreators?.() ?? [],
);
for (const creator of extraStoreDataCreators) {
const embeddedData = creator(setImpl);
if (embeddedData) {
return embeddedData;
}
}
return undefined;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
import { EmbeddedDataType } from '../editor-state/ExternalFormatState.js';
import type { EditorStore } from '../EditorStore.js';
import { createMockDataForMappingElementSource } from './MockDataUtils.js';
import type { DSL_Data_LegendStudioApplicationPlugin_Extension } from '../../extensions/DSL_Data_LegendStudioApplicationPlugin_Extension.js';

export const DEFAULT_TEST_ASSERTION_ID = 'assertion_1';
export const DEFAULT_TEST_ID = 'test_1';
Expand Down Expand Up @@ -127,8 +128,28 @@ export const createBareModelStoreData = (
export class EmbeddedDataCreatorFromEmbeddedData
implements EmbeddedDataVisitor<EmbeddedData>
{
editorStore: EditorStore;
constructor(editorStore: EditorStore) {
this.editorStore = editorStore;
}
visit_EmbeddedData(data: EmbeddedData): EmbeddedData {
throw new Error('Method not implemented.');
const extraEmbeddedDataCloners = this.editorStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) =>
(
plugin as DSL_Data_LegendStudioApplicationPlugin_Extension
).getExtraEmbeddedDataCloners?.() ?? [],
);
for (const creator of extraEmbeddedDataCloners) {
const embeddedData = creator(data);
if (embeddedData) {
return embeddedData;
}
}
throw new UnsupportedOperationError(
`Unsupported embedded data${data.toString()}`,
);
}
visit_INTERNAL__UnknownEmbeddedData(
data: INTERNAL__UnknownEmbeddedData,
Expand All @@ -149,7 +170,7 @@ export class EmbeddedDataCreatorFromEmbeddedData
const v = new ModelEmbeddedData();
v.model = PackageableElementExplicitReference.create(e.model.value);
v.data = e.data.accept_EmbeddedDataVisitor(
new EmbeddedDataCreatorFromEmbeddedData(),
new EmbeddedDataCreatorFromEmbeddedData(this.editorStore),
);
return v;
}
Expand All @@ -160,7 +181,7 @@ export class EmbeddedDataCreatorFromEmbeddedData
}
visit_DataElementReference(data: DataElementReference): EmbeddedData {
return data.dataElement.value.data.accept_EmbeddedDataVisitor(
new EmbeddedDataCreatorFromEmbeddedData(),
new EmbeddedDataCreatorFromEmbeddedData(this.editorStore),
);
}
visit_RelationalCSVData(data: RelationalCSVData): EmbeddedData {
Expand Down Expand Up @@ -224,6 +245,20 @@ export class EmbeddedDataConnectionTypeVisitor
}

visit_Connection(connection: Connection): string {
const extraEmbeddedDataCreator = this.editorStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) =>
(
plugin as DSL_Data_LegendStudioApplicationPlugin_Extension
).getExtraEmbeddedDataTypeFromConnectionMatchers?.() ?? [],
);
for (const creator of extraEmbeddedDataCreator) {
const embeddedData = creator(connection);
if (embeddedData) {
return embeddedData;
}
}
return EmbeddedDataType.EXTERNAL_FORMAT_DATA;
}
visit_INTERNAL__UnknownConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import type { EmbeddedData } from '@finos/legend-graph';
import type {
Connection,
EmbeddedData,
SetImplementation,
StoreTestData,
} from '@finos/legend-graph';
import type { EmbeddedDataTypeOption } from '../editor/editor-state/element-editor-state/data/DataEditorState.js';
import type { EmbeddedDataState } from '../editor/editor-state/element-editor-state/data/EmbeddedDataState.js';
import type { EditorStore } from '../editor/EditorStore.js';
Expand All @@ -35,6 +40,18 @@ export type EmbeddedDataCreator = (
embeddedDataType: string,
) => EmbeddedData | undefined;

export type EmbeddedDataCloner = (
embeddedData: EmbeddedData,
) => EmbeddedData | undefined;

export type StoreTestDataCreators = (
setImp: SetImplementation,
) => StoreTestData | undefined;

export type EmbeddedDataTypeFromConnectionMatcher = (
connection: Connection,
) => string | undefined;

/**
* NOTE: The tab-stop index of the snippet must start from 2
*/
Expand Down Expand Up @@ -67,4 +84,19 @@ export interface DSL_Data_LegendStudioApplicationPlugin_Extension
* Get the list of embedded data creators
*/
getExtraEmbeddedDataCreators?(): EmbeddedDataCreator[];

/**
* Get the list of embedded data type from connection matchers
*/
getExtraEmbeddedDataTypeFromConnectionMatchers?(): EmbeddedDataTypeFromConnectionMatcher[];

/**
* Get the list of store test data creators
*/
getExtraStoreTestDataCreators?(): StoreTestDataCreators[];

/**
* Get the list of embedded data cloners
*/
getExtraEmbeddedDataCloners?(): EmbeddedDataCloner[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ import {
type MappingElementSource,
type ConnectionTypeOption,
type PureGrammarConnectionLabeler,
type EmbeddedDataTypeFromConnectionMatcher,
type StoreTestDataCreators,
type EmbeddedDataCloner,
} from '@finos/legend-application-studio';
import { SwaggerIcon } from '@finos/legend-art';
import {
type Connection,
type EmbeddedData,
type PackageableElement,
type Store,
type SetImplementation,
PackageableElementExplicitReference,
StoreTestData,
} from '@finos/legend-graph';
import { ServiceStore } from '../../graph/metamodel/pure/model/packageableElements/store/serviceStore/model/STO_ServiceStore_ServiceStore.js';
import { RootServiceInstanceSetImplementation } from '../../graph/metamodel/pure/model/packageableElements/store/serviceStore/mapping/STO_ServiceStore_RootServiceInstanceSetImplementation.js';
Expand Down Expand Up @@ -488,4 +493,47 @@ export class STO_ServiceStore_LegendStudioApplicationPlugin
},
];
}

getExtraEmbeddedDataCloners(): EmbeddedDataCloner[] {
return [
(embeddedData: EmbeddedData): EmbeddedData | undefined => {
if (embeddedData instanceof ServiceStoreEmbeddedData) {
const serviceStoreEmbeddedData = new ServiceStoreEmbeddedData();
// TODO walk embedded data and clone
return serviceStoreEmbeddedData;
}
return undefined;
},
];
}

getExtraEmbeddedDataTypeFromConnectionMatchers(): EmbeddedDataTypeFromConnectionMatcher[] {
return [
(connection: Connection): string | undefined => {
if (connection instanceof ServiceStoreConnection) {
return SERVICE_STORE_EMBEDDED_DATA_TYPE;
}
return undefined;
},
];
}

getExtraStoreTestDataCreators(): StoreTestDataCreators[] {
return [
(setImpl: SetImplementation): StoreTestData | undefined => {
if (setImpl instanceof RootServiceInstanceSetImplementation) {
const storeTestData = new StoreTestData();
storeTestData.data = new ServiceStoreEmbeddedData();
const serviceMapping = setImpl.servicesMapping[0];
if (serviceMapping) {
storeTestData.store = PackageableElementExplicitReference.create(
serviceMapping.service.owner,
);
}
return storeTestData;
}
return undefined;
},
];
}
}

0 comments on commit f764ced

Please sign in to comment.