Skip to content

Commit

Permalink
support Relation Function class mapping (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-rpant1729 authored Jan 24, 2025
1 parent 2016ead commit a851990
Show file tree
Hide file tree
Showing 38 changed files with 964 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .changeset/tame-islands-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-application-studio': patch
'@finos/legend-graph': patch
---

Support Relation Function class mapping in Studio.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import {
DatabaseType,
RelationalDatabaseConnection,
type FunctionActivator,
GenericType,
} from '@finos/legend-graph';
import {
type ApplicationStore,
Expand All @@ -120,7 +121,7 @@ import {
} from '@finos/legend-lego/graph-editor';
import { getElementIcon } from '../../../ElementIconUtils.js';
import {
function_setReturnType,
function_setReturnGenericType,
function_setReturnMultiplicity,
function_addParameter,
function_deleteParameter,
Expand Down Expand Up @@ -502,29 +503,32 @@ const ReturnTypeEditor = observer(
editorStore.graphManagerState.usableClassPropertyTypes.map(
buildElementOption,
);
const typeName = getFunctionParameterType(returnType.value);
const typeName = getFunctionParameterType(returnType.value.rawType);
const filterOption = createFilter({
ignoreCase: true,
ignoreAccents: false,
stringify: (option: { data: PackageableElementOption<Type> }): string =>
option.data.value.path,
});
const selectedType = {
value: returnType.value,
label: returnType.value.name,
value: returnType.value.rawType,
label: returnType.value.rawType.name,
};
const changeType = (val: PackageableElementOption<Type>): void => {
function_setReturnType(functionElement, val.value);
function_setReturnGenericType(
functionElement,
new GenericType(val.value),
);
setIsEditingType(false);
updateFunctionName(editorStore, applicationStore, functionElement);
};

const openElement = (): void => {
if (!(returnType.value instanceof PrimitiveType)) {
if (!(returnType.value.rawType instanceof PrimitiveType)) {
editorStore.graphEditorMode.openElement(
returnType.value instanceof Unit
? returnType.value.measure
: returnType.value,
returnType.value.rawType instanceof Unit
? returnType.value.rawType.measure
: returnType.value.rawType,
);
}
};
Expand Down Expand Up @@ -597,11 +601,11 @@ const ReturnTypeEditor = observer(
>
{typeName !== FUNCTION_PARAMETER_TYPE.PRIMITIVE && (
<div className="property-basic-editor__type__abbr">
{getElementIcon(returnType.value, editorStore)}
{getElementIcon(returnType.value.rawType, editorStore)}
</div>
)}
<div className="property-basic-editor__type__label">
{returnType.value.name}
{returnType.value.rawType.name}
</div>
<div
className="property-basic-editor__type__label property-basic-editor__type__label--hover"
Expand Down Expand Up @@ -635,11 +639,11 @@ const ReturnTypeEditor = observer(
>
{typeName !== FUNCTION_PARAMETER_TYPE.PRIMITIVE && (
<div className="property-basic-editor__type__abbr">
{getElementIcon(returnType.value, editorStore)}
{getElementIcon(returnType.value.rawType, editorStore)}
</div>
)}
<div className="property-basic-editor__type__label">
{returnType.value.name}
{returnType.value.rawType.name}
</div>
{typeName !== FUNCTION_PARAMETER_TYPE.PRIMITIVE && (
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
ELEMENT_PATH_DELIMITER,
RawVariableExpression,
getFunctionSignature,
GenericTypeExplicitReference,
GenericType,
} from '@finos/legend-graph';
import {
type QueryBuilderState,
Expand Down Expand Up @@ -118,7 +120,7 @@ export const promoteQueryToFunction = async (
const returnType = queryBuilderState.getQueryReturnType();
const _function = new ConcreteFunctionDefinition(
functionName, // use functionName for now and it will be reset after composing _function.parameters and _function.returnType
PackageableElementExplicitReference.create(returnType),
GenericTypeExplicitReference.create(new GenericType(returnType)),
Multiplicity.ONE,
);
// we will copy the body of the query to the body of the function and extract the parameters out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ import {
generateIdentifiedConnectionId,
getMappingCompatibleRuntimes,
RuntimePointer,
GenericTypeExplicitReference,
GenericType,
} from '@finos/legend-graph';
import type { DSL_Mapping_LegendStudioApplicationPlugin_Extension } from '../extensions/DSL_Mapping_LegendStudioApplicationPlugin_Extension.js';
import {
Expand Down Expand Up @@ -949,7 +951,9 @@ export class NewElementState {
case PACKAGEABLE_ELEMENT_TYPE.FUNCTION: {
const fn = new ConcreteFunctionDefinition(
name,
PackageableElementExplicitReference.create(PrimitiveType.STRING),
GenericTypeExplicitReference.create(
new GenericType(PrimitiveType.STRING),
),
Multiplicity.ONE,
);
// default to empty string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export const createFunctionTest = (
} else {
const equalTo = new EqualTo();
equalTo.id = DEFAULT_TEST_ASSERTION_ID;
const type = functionDefinition.returnType.value;
const type = functionDefinition.returnType.value.rawType;
const valSpec = buildDefaultInstanceValue(
editorStore.graphManagerState.graph,
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
type Store,
ModelStore,
INTERNAL__UnknownSetImplementation,
RelationFunctionInstanceSetImplementation,
} from '@finos/legend-graph';
import type {
DSL_Mapping_LegendStudioApplicationPlugin_Extension,
Expand Down Expand Up @@ -312,6 +313,12 @@ export const getMappingElementSource = (
plugins,
);
}
// TODO: We could probably return the relation function used for the mapping here once we implement the form mode support for it
else if (
mappingElement instanceof RelationFunctionInstanceSetImplementation
) {
return undefined;
}
const extraMappingElementSourceExtractors = plugins.flatMap(
(plugin) =>
(
Expand Down Expand Up @@ -900,6 +907,12 @@ export class MappingEditorState extends ElementEditorState {
);
return;
}
if (mappingElement instanceof RelationFunctionInstanceSetImplementation) {
this.editorStore.applicationStore.notificationService.notifyUnsupportedFeature(
'Relation Function mapping editor',
);
return;
}
// Open mapping element from included mapping in another mapping editor tab
if (mappingElement._PARENT !== this.element) {
this.editorStore.graphEditorMode.openElement(mappingElement._PARENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
EnumerationMappingExplicitReference,
SetImplementationExplicitReference,
type INTERNAL__UnknownSetImplementation,
type RelationFunctionInstanceSetImplementation,
} from '@finos/legend-graph';
import type { EditorStore } from '../../../EditorStore.js';
import {
Expand Down Expand Up @@ -657,6 +658,12 @@ export class MappingElementDecorator implements SetImplementationVisitor<void> {
): void {
return;
}

visit_RelationFunctionInstanceSetImplementation(
setImplementation: RelationFunctionInstanceSetImplementation,
): void {
return;
}
}

/**
Expand Down Expand Up @@ -803,4 +810,10 @@ export class MappingElementDecorationCleaner
): void {
return;
}

visit_RelationFunctionInstanceSetImplementation(
setImplementation: RelationFunctionInstanceSetImplementation,
): void {
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
type GenericTypeReference,
type TaggedValue,
type StereotypeReference,
type Type,
type Multiplicity,
type Stereotype,
type Tag,
Expand Down Expand Up @@ -68,7 +67,6 @@ import {
observe_TaggedValue,
observe_Constraint,
observe_GenericType,
observe_Type,
observe_Unit,
observe_RawLambda,
isStubbed_PackageableElement,
Expand Down Expand Up @@ -365,9 +363,9 @@ export const function_addParameter = action(
addUniqueEntry(_func.parameters, observe_RawVariableExpression(val));
},
);
export const function_setReturnType = action(
(_func: ConcreteFunctionDefinition, val: Type): void => {
packageableElementReference_setValue(_func.returnType, observe_Type(val));
export const function_setReturnGenericType = action(
(_func: ConcreteFunctionDefinition, val: GenericType): void => {
setGenericTypeReferenceValue(_func.returnType, observe_GenericType(val));
},
);
export const function_setReturnMultiplicity = action(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ export const TEST_DATA__FunctionRoundtrip = [
genericType: {
rawType: {
_type: 'packageableType',
fullPath: 'tClass',
fullPath: 'test::tClass',
},
},
multiplicity: {
Expand All @@ -902,7 +902,7 @@ export const TEST_DATA__FunctionRoundtrip = [
genericType: {
rawType: {
_type: 'packageableType',
fullPath: 'tClass',
fullPath: 'test::tClass',
},
},
multiplicity: {
Expand All @@ -921,7 +921,7 @@ export const TEST_DATA__FunctionRoundtrip = [
returnGenericType: {
rawType: {
_type: 'packageableType',
fullPath: 'tClass',
fullPath: 'test::tClass',
},
},
stereotypes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ import type { INTERNAL__UnknownConnection } from '../../../graph/metamodel/pure/
import type { INTERNAL__UnknownPropertyMapping } from '../../../graph/metamodel/pure/packageableElements/mapping/INTERNAL__UnknownPropertyMapping.js';
import type { INTERNAL__UnknownSetImplementation } from '../../../graph/metamodel/pure/packageableElements/mapping/INTERNAL__UnknownSetImplementation.js';
import type { INTERNAL__UnknownStore } from '../../../graph/metamodel/pure/packageableElements/store/INTERNAL__UnknownStore.js';
import type { RelationFunctionInstanceSetImplementation } from '../../../graph/metamodel/pure/packageableElements/mapping/relationFunction/RelationFunctionInstanceSetImplementation.js';
import type { RelationFunctionPropertyMapping } from '../../../graph/metamodel/pure/packageableElements/mapping/relationFunction/RelationFunctionPropertyMapping.js';

// ------------------------------------- Store -------------------------------------

Expand Down Expand Up @@ -396,6 +398,12 @@ class PropertyMappingObserver implements PropertyMappingVisitor<void> {
visit_XStorePropertyMapping(propertyMapping: XStorePropertyMapping): void {
// TODO
}

visit_RelationFunctionPropertyMapping(
propertyMapping: RelationFunctionPropertyMapping,
): void {
// TODO
}
}

export const observe_PropertyMapping = (
Expand Down Expand Up @@ -636,6 +644,12 @@ class SetImplementationObserver implements SetImplementationVisitor<void> {
);
}

visit_RelationFunctionInstanceSetImplementation(
setImplementation: RelationFunctionInstanceSetImplementation,
): void {
// TODO
}

visit_AggregationAwareSetImplementation(
setImplementation: AggregationAwareSetImplementation,
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export const observe_ConcreteFunctionDefinition = skipObservedWithContext(
});

metamodel.parameters.forEach(observe_RawVariableExpression);
observe_PackageableElementReference(metamodel.returnType);
observe_GenericTypeReference(metamodel.returnType);
metamodel.stereotypes.forEach(observe_StereotypeReference);
metamodel.taggedValues.forEach(observe_TaggedValue);
metamodel.tests.forEach((t) => observe_FunctionTestSuite(t, context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { V1_PureInstanceClassMapping } from '../../../model/packageableElem
import type { V1_RootFlatDataClassMapping } from '../../../model/packageableElements/store/flatData/mapping/V1_RootFlatDataClassMapping.js';
import type { V1_MergeOperationClassMapping } from './V1_MergeOperationClassMapping.js';
import type { V1_INTERNAL__UnknownClassMapping } from './V1_INTERNAL__UnknownClassMapping.js';
import type { V1_RelationFunctionClassMapping } from './V1_RelationFunctionClassMapping.js';

export interface V1_ClassMappingVisitor<T> {
visit_ClassMapping(classMapping: V1_ClassMapping): T;
Expand All @@ -45,6 +46,9 @@ export interface V1_ClassMappingVisitor<T> {
visit_AggregationAwareClassMapping(
classMapping: V1_AggregationAwareClassMapping,
): T;
visit_RelationFunctionClassMapping(
classMapping: V1_RelationFunctionClassMapping,
): T;
}

export abstract class V1_ClassMapping implements Hashable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type { V1_EmbeddedFlatDataPropertyMapping } from '../../../model/packagea
import type { V1_XStorePropertyMapping } from './xStore/V1_XStorePropertyMapping.js';
import type { V1_FlatDataAssociationPropertyMapping } from '../../../model/packageableElements/store/flatData/mapping/V1_FlatDataAssociationPropertyMapping.js';
import type { V1_INTERNAL__UnknownPropertyMapping } from './V1_INTERNAL__UnknownPropertyMapping.js';
import type { V1_RelationFunctionPropertyMapping } from './V1_RelationFunctionPropertyMapping.js';

export interface V1_PropertyMappingVisitor<T> {
visit_PropertyMapping(propertyMapping: V1_PropertyMapping): T;
Expand Down Expand Up @@ -60,6 +61,9 @@ export interface V1_PropertyMappingVisitor<T> {
visit_FlatDataAssociationPropertyMapping(
propertyMapping: V1_FlatDataAssociationPropertyMapping,
): T;
visit_RelationFunctionPropertyMapping(
propertyMapping: V1_RelationFunctionPropertyMapping,
): T;
}

export abstract class V1_PropertyMapping implements Hashable {
Expand Down
Loading

0 comments on commit a851990

Please sign in to comment.