From a7a21a159f08b0d0668e6f57f7e316609d830628 Mon Sep 17 00:00:00 2001 From: Rafael Bey Date: Mon, 25 Nov 2024 18:25:32 -0500 Subject: [PATCH] Run converters on standard deserializer flow + during parsing --- .../pom.xml | 2 - .../pure/grammar/from/PureGrammarParser.java | 8 +- .../grammar/test/TestGrammarRoundtrip.java | 17 +- .../roundtrip/TestDomainGrammarRoundtrip.java | 78 ++++----- .../pure/v1/CorePureProtocolExtension.java | 164 +++++++++++------- .../v1/PureProtocolObjectMapperFactory.java | 8 +- .../v1/extension/PureProtocolExtension.java | 2 +- .../v1/model/valueSpecification/Variable.java | 8 +- .../application/AppliedFunction.java | 61 ------- .../shared/core/ObjectMapperFactory.java | 15 +- 10 files changed, 162 insertions(+), 201 deletions(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/pom.xml b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/pom.xml index 24f772691a6..c0b234701a5 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/pom.xml +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/pom.xml @@ -154,12 +154,10 @@ com.fasterxml.jackson.core jackson-databind - test com.fasterxml.jackson.core jackson-core - test diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/PureGrammarParser.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/PureGrammarParser.java index 01025cf72ab..2d908aaf024 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/PureGrammarParser.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/PureGrammarParser.java @@ -14,6 +14,7 @@ package org.finos.legend.engine.language.pure.grammar.from; +import com.fasterxml.jackson.databind.ObjectMapper; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.eclipse.collections.api.factory.Lists; @@ -37,6 +38,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.classInstance.graph.RootGraphFetchTree; +import org.finos.legend.engine.shared.core.ObjectMapperFactory; import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; import org.finos.legend.engine.shared.core.operational.logs.LogInfo; @@ -52,6 +54,7 @@ public class PureGrammarParser private final DEPRECATED_PureGrammarParserLibrary parsers; private final PureGrammarParserExtensions extensions; + private ObjectMapper converterMapper; private PureGrammarParser(PureGrammarParserExtensions extensions) { @@ -63,6 +66,7 @@ private PureGrammarParser(PureGrammarParserExtensions extensions) connectionParser, RuntimeParser.newInstance(connectionParser) )); + this.converterMapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports(); } public static PureGrammarParser newInstance(PureGrammarParserExtensions extensions) @@ -127,7 +131,9 @@ private PureModelContextData parse(String code, DEPRECATED_PureGrammarParserLibr sectionIndex.name = "SectionIndex"; sectionIndex._package = "__internal__"; sectionIndex.sections = ListIterate.collect(parser.definition().section(), sectionCtx -> this.visitSection(sectionCtx, parserLibrary, walkerSourceInformation, parserContext, builder::addElement, returnSourceInfo)); - return builder.withElement(sectionIndex).build(); + // tactically run parsed values thru converters to fix old/legacy code + PureModelContextData pmcd = builder.withElement(sectionIndex).build(); + return this.converterMapper.convertValue(pmcd, PureModelContextData.class); } private Section visitSection(CodeParserGrammar.SectionContext ctx, DEPRECATED_PureGrammarParserLibrary parserLibrary, ParseTreeWalkerSourceInformation walkerSourceInformation, PureGrammarParserContext parserContext, Consumer elementConsumer, boolean returnSourceInfo) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/TestGrammarRoundtrip.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/TestGrammarRoundtrip.java index 6b193a4dc12..c3c3d5b7f37 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/TestGrammarRoundtrip.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/TestGrammarRoundtrip.java @@ -120,17 +120,12 @@ private static void test(String code, String message, boolean keepSectionIndex) public static void testFormatWithSectionInfoPreserved(String code, String unformattedCode) { - testFormat(code, unformattedCode, false, false); + testFormat(code, unformattedCode, false); } public static void testFormat(String code, String unformattedCode) { - testFormat(code, unformattedCode, true, false); - } - - public static void testConvert(String code, String unformattedCode) - { - testFormat(code, unformattedCode, true, true); + testFormat(code, unformattedCode, true); } /** @@ -148,7 +143,7 @@ public static void testConvert(String code, String unformattedCode) * ... * // end of example */ - private static void testFormat(String code, String unformattedCode, boolean omitSectionIndex, boolean withConvert) + private static void testFormat(String code, String unformattedCode, boolean omitSectionIndex) { PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build()); // NOTE: no need to get source information @@ -158,12 +153,6 @@ private static void testFormat(String code, String unformattedCode, boolean omit parsedModel = PureModelContextData.newPureModelContextData(parsedModel.getSerializer(), parsedModel.getOrigin(), LazyIterate.reject(parsedModel.getElements(), e -> e instanceof SectionIndex)); } - if (withConvert) - { - // run json deserializer to apply protocol updates (migrate from old to new)... - parsedModel = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolConverterSupports().convertValue(parsedModel, PureModelContextData.class); - } - String formatted = grammarTransformer.renderPureModelContextData(parsedModel); Assert.assertEquals(code, formatted); // NOTE: do not remove the round-trip test for formatted code as this is a very good way to ensure that grammar <-> >protocol is bijective diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/roundtrip/TestDomainGrammarRoundtrip.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/roundtrip/TestDomainGrammarRoundtrip.java index 9af1f1935aa..fed2eb6e836 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/roundtrip/TestDomainGrammarRoundtrip.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/test/java/org/finos/legend/engine/language/pure/grammar/test/roundtrip/TestDomainGrammarRoundtrip.java @@ -527,7 +527,7 @@ public void testTypeArgumentsAreBackwardCompatibleForOldProtocolMissingIt() thro " {\n" + // ---------- type to construct, no type arguments " \"_type\": \"packageableElementPtr\",\n" + - " \"fullPath\": \"BasicColumnSpecification\"\n" + + " \"fullPath\": \"TdsOlapRank\"\n" + // ---------- type to construct, no type arguments " },\n" + " {\n" + @@ -608,7 +608,7 @@ public void testTypeArgumentsAreBackwardCompatibleForOldProtocolMissingIt() thro "}", "function test::new(): Any[1]\n" + "{\n" + - " ^BasicColumnSpecification(func=r: TDSRow[1]|1)\n" + + " meta::pure::tds::func(r: TDSRow[1]|1)\n" + "}\n"); testComposedGrammar("{\n" + @@ -667,58 +667,58 @@ public void testTypeArgumentsAreBackwardCompatibleForOldProtocolMissingIt() thro @Test public void testConvertBasicColumnSpecification() { - testConvert("function test::new(): Any[1]\n" + - "{\n" + - " meta::pure::tds::col(r: TDSRow[1]|1, 'hello')\n" + - "}\n", + testFormat("function test::new(): Any[1]\n" + + "{\n" + + " meta::pure::tds::col(r: TDSRow[1]|1, 'hello')\n" + + "}\n", "function test::new(): Any[1]\n" + - "{\n" + - " ^BasicColumnSpecification(func=r: TDSRow[1]|1, name='hello')\n" + - "}\n"); - - testConvert("function test::new(): Any[1]\n" + - "{\n" + - " meta::pure::tds::col(r: TDSRow[1]|1, 'hello', 'documentation here')\n" + - "}\n", + "{\n" + + " ^BasicColumnSpecification(func=r: TDSRow[1]|1, name='hello')\n" + + "}\n"); + + testFormat("function test::new(): Any[1]\n" + + "{\n" + + " meta::pure::tds::col(r: TDSRow[1]|1, 'hello', 'documentation here')\n" + + "}\n", "function test::new(): Any[1]\n" + - "{\n" + - " ^meta::pure::tds::BasicColumnSpecification(documentation='documentation here', func=r: TDSRow[1]|1, name='hello')\n" + - "}\n"); + "{\n" + + " ^meta::pure::tds::BasicColumnSpecification(documentation='documentation here', func=r: TDSRow[1]|1, name='hello')\n" + + "}\n"); } @Test public void testConvertTdsOlapRank() { - testConvert("function test::new(): Any[1]\n" + - "{\n" + - " meta::pure::tds::func(r: TDSRow[1]|1)\n" + - "}\n", + testFormat("function test::new(): Any[1]\n" + + "{\n" + + " meta::pure::tds::func(r: TDSRow[1]|1)\n" + + "}\n", "function test::new(): Any[1]\n" + - "{\n" + - " ^meta::pure::tds::TdsOlapRank(func=r: TDSRow[1]|1)\n" + - "}\n"); - - testConvert("function test::new(): Any[1]\n" + - "{\n" + - " meta::pure::tds::func(r: TDSRow[1]|1)\n" + - "}\n", + "{\n" + + " ^meta::pure::tds::TdsOlapRank(func=r: TDSRow[1]|1)\n" + + "}\n"); + + testFormat("function test::new(): Any[1]\n" + + "{\n" + + " meta::pure::tds::func(r: TDSRow[1]|1)\n" + + "}\n", "function test::new(): Any[1]\n" + - "{\n" + - " ^TdsOlapRank(func=r: TDSRow[1]|1)\n" + - "}\n"); + "{\n" + + " ^TdsOlapRank(func=r: TDSRow[1]|1)\n" + + "}\n"); } @Test public void testConvertResult() { - testConvert("function test::new(res: Result[1]): Any[1]\n" + - "{\n" + - " 1\n" + - "}\n", + testFormat("function test::new(res: Result[1]): Any[1]\n" + + "{\n" + + " 1\n" + + "}\n", "function test::new(res: Result[1]): Any[1]\n" + - "{\n" + - " 1\n" + - "}\n"); + "{\n" + + " 1\n" + + "}\n"); } @Test diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/CorePureProtocolExtension.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/CorePureProtocolExtension.java index 0c7faa0d09c..0323e631578 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/CorePureProtocolExtension.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/CorePureProtocolExtension.java @@ -19,6 +19,8 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.collections.api.block.function.Function0; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Maps; @@ -89,6 +91,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.datatype.CString; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.GenericTypeInstance; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.PackageableElementPtr; public class CorePureProtocolExtension implements PureProtocolExtension { @@ -197,7 +200,7 @@ public Map, String> getExtraProtoc } @Override - public List> getConverterDeserializers() + public List> getProtocolConverters() { return Lists.fixedSize.with( new ProtocolConverter<>(new ResultVariableWithMissingTypeConverter()), @@ -208,6 +211,10 @@ public List> getConverterDeserializers() ); } + /** + * Converts/fix variables of type Result to ensure they have the type and multiplicity + * Result[1] -> Result<Any|*>[1] + */ private static class ResultVariableWithMissingTypeConverter extends StdConverter { @Override @@ -226,6 +233,10 @@ public Variable convert(Variable variable) } } + /** + * Convert the usage of BasicColumnSpecification to the equivalent function + * ^BasicColumnSpecification(...) == col(...) + */ private static class BasicColumnSpecificationToColFunctionConverter extends StdConverter { @Override @@ -233,52 +244,61 @@ public AppliedFunction convert(AppliedFunction appliedFunction) { if (appliedFunction.function.equals("new")) { - GenericTypeInstance typeInstance = (GenericTypeInstance) appliedFunction.parameters.get(0); - if (typeInstance.genericType.typeArguments.size() >= 1 && typeInstance.genericType.typeArguments.get(0).rawType instanceof PackageableType) - { - PackageableType type = (PackageableType) typeInstance.genericType.typeArguments.get(0).rawType; - - Set classesThatNeedTypeFixing = Sets.fixedSize.of( - "meta::pure::tds::BasicColumnSpecification", - "BasicColumnSpecification" - ); + PackageableElementPtr type; - if (classesThatNeedTypeFixing.contains(type.fullPath)) + if (appliedFunction.parameters.get(0) instanceof GenericTypeInstance) + { + GenericTypeInstance typeInstance = (GenericTypeInstance) appliedFunction.parameters.get(0); + if (typeInstance.genericType.typeArguments.size() >= 1 && typeInstance.genericType.typeArguments.get(0).rawType instanceof PackageableType) { - Collection collection = (Collection) appliedFunction.parameters.get(2); - Optional func = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("func")) - .map(KeyExpression.class::cast) - .map(x -> x.expression) - .filter(Lambda.class::isInstance) - .map(Lambda.class::cast); + type = (PackageableType) typeInstance.genericType.typeArguments.get(0).rawType; + } + else + { + return appliedFunction; + } + } + else if (appliedFunction.parameters.get(0) instanceof PackageableElementPtr) + { + type = (PackageableElementPtr) appliedFunction.parameters.get(0); + } + else + { + return appliedFunction; + } - Optional name = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("name")) - .map(KeyExpression.class::cast) - .map(x -> x.expression) - .filter(CString.class::isInstance) - .map(CString.class::cast); + Set classesThatNeedTypeFixing = Sets.fixedSize.of( + "meta::pure::tds::BasicColumnSpecification", + "BasicColumnSpecification" + ); - Optional doc = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("documentation")) - .map(KeyExpression.class::cast) - .map(x -> x.expression) - .filter(CString.class::isInstance) - .map(CString.class::cast); + if (classesThatNeedTypeFixing.contains(type.fullPath)) + { + Collection collection = (Collection) appliedFunction.parameters.get(2); + Optional func = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("func")) + .map(KeyExpression.class::cast) + .map(x -> x.expression) + .filter(Lambda.class::isInstance) + .map(Lambda.class::cast); + + Optional name = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("name")) + .map(KeyExpression.class::cast) + .map(x -> x.expression) + .filter(CString.class::isInstance) + .map(CString.class::cast); - if (func.isPresent() && name.isPresent()) - { - appliedFunction.function = "meta::pure::tds::col"; - appliedFunction.parameters = Lists.mutable.with(func.get(), name.get()); + Optional doc = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("documentation")) + .map(KeyExpression.class::cast) + .map(x -> x.expression) + .filter(CString.class::isInstance) + .map(CString.class::cast); - if (doc.isPresent()) - { - appliedFunction.fControl = "meta::pure::tds::col_Function_1__String_1__String_1__BasicColumnSpecification_1_"; - appliedFunction.parameters.add(doc.get()); - } - else - { - appliedFunction.fControl = "meta::pure::tds::col_Function_1__String_1__BasicColumnSpecification_1_"; - } - } + appliedFunction.function = "meta::pure::tds::col"; + appliedFunction.fControl = "meta::pure::tds::col_Function_1__String_1__BasicColumnSpecification_1_"; + appliedFunction.parameters = Stream.of(func, name, doc).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); + if (appliedFunction.parameters.size() == 3) + { + appliedFunction.fControl = "meta::pure::tds::col_Function_1__String_1__String_1__BasicColumnSpecification_1_"; } } } @@ -286,6 +306,10 @@ public AppliedFunction convert(AppliedFunction appliedFunction) } } + /** + * Convert the usage of TdsOlapRank to the equivalent function + * ^TdsOlapRank(...) == func(...) + */ private static class TdsOlapRankToColFunctionConverter extends StdConverter { @Override @@ -293,32 +317,46 @@ public AppliedFunction convert(AppliedFunction appliedFunction) { if (appliedFunction.function.equals("new")) { - GenericTypeInstance typeInstance = (GenericTypeInstance) appliedFunction.parameters.get(0); - if (typeInstance.genericType.typeArguments.size() >= 1 && typeInstance.genericType.typeArguments.get(0).rawType instanceof PackageableType) + PackageableElementPtr type; + + if (appliedFunction.parameters.get(0) instanceof GenericTypeInstance) + { + GenericTypeInstance typeInstance = (GenericTypeInstance) appliedFunction.parameters.get(0); + if (typeInstance.genericType.typeArguments.size() >= 1 && typeInstance.genericType.typeArguments.get(0).rawType instanceof PackageableType) + { + type = (PackageableType) typeInstance.genericType.typeArguments.get(0).rawType; + } + else + { + return appliedFunction; + } + } + else if (appliedFunction.parameters.get(0) instanceof PackageableElementPtr) { - PackageableType type = (PackageableType) typeInstance.genericType.typeArguments.get(0).rawType; + type = (PackageableElementPtr) appliedFunction.parameters.get(0); + } + else + { + return appliedFunction; + } - Set classesThatNeedTypeFixing = Sets.fixedSize.of( - "meta::pure::tds::TdsOlapRank", - "TdsOlapRank" - ); + Set classesThatNeedTypeFixing = Sets.fixedSize.of( + "meta::pure::tds::TdsOlapRank", + "TdsOlapRank" + ); - if (classesThatNeedTypeFixing.contains(type.fullPath)) - { - Collection collection = (Collection) appliedFunction.parameters.get(2); - Optional func = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("func")) - .map(KeyExpression.class::cast) - .map(x -> x.expression) - .filter(Lambda.class::isInstance) - .map(Lambda.class::cast); + if (classesThatNeedTypeFixing.contains(type.fullPath)) + { + Collection collection = (Collection) appliedFunction.parameters.get(2); + Optional func = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("func")) + .map(KeyExpression.class::cast) + .map(x -> x.expression) + .filter(Lambda.class::isInstance) + .map(Lambda.class::cast); - if (func.isPresent()) - { - appliedFunction.function = "meta::pure::tds::func"; - appliedFunction.fControl = "meta::pure::tds::func_FunctionDefinition_1__TdsOlapRank_1_"; - appliedFunction.parameters = Lists.mutable.with(func.get()); - } - } + appliedFunction.function = "meta::pure::tds::func"; + appliedFunction.fControl = "meta::pure::tds::func_FunctionDefinition_1__TdsOlapRank_1_"; + appliedFunction.parameters = Stream.of(func).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()); } } return appliedFunction; diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/PureProtocolObjectMapperFactory.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/PureProtocolObjectMapperFactory.java index 5d6c11c0474..cd1b3ff22f0 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/PureProtocolObjectMapperFactory.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/PureProtocolObjectMapperFactory.java @@ -183,24 +183,22 @@ public static ObjectMapper getNewObjectMapper(Set excludedSubTypes) public static ObjectMapper withPureProtocolConverter(ObjectMapper objectMapper) { - ObjectMapper withPureProtocolExtensions = withPureProtocolExtensions(objectMapper); - List> protocolConverters = PureProtocolExtensionLoader.extensions().stream() - .map(PureProtocolExtension::getConverterDeserializers) + .map(PureProtocolExtension::getProtocolConverters) .filter(Objects::nonNull) .flatMap(List::stream) .collect(Collectors.toList()); FastListMultimap> converterByType = ListIterate.groupBy(protocolConverters, x -> x.getInputType(TypeFactory.defaultInstance())); - DeserializationConfig deserializationConfig = withPureProtocolExtensions + DeserializationConfig deserializationConfig = objectMapper .getDeserializationConfig() .with(new ConverterHandlerInstantiator(converterByType)); SimpleModule module = new SimpleModule("protocol converters"); module.setDeserializerModifier(new ConverterBeanDeserializerModifier(converterByType)); - return withPureProtocolExtensions.setConfig(deserializationConfig).registerModule(module); + return objectMapper.setConfig(deserializationConfig).registerModule(module); } private static class ConverterHandlerInstantiator extends HandlerInstantiator diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/extension/PureProtocolExtension.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/extension/PureProtocolExtension.java index 3ca9aab7f8a..5ecb50e8f62 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/extension/PureProtocolExtension.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/extension/PureProtocolExtension.java @@ -48,7 +48,7 @@ default Map getExtraClassInstanceTypeMappings() return Maps.mutable.empty(); } - default List> getConverterDeserializers() + default List> getProtocolConverters() { return Lists.fixedSize.empty(); } diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/Variable.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/Variable.java index e97a3ead7ce..86f53709d91 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/Variable.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/Variable.java @@ -77,13 +77,7 @@ public ValueSpecification deserialize(JsonParser jsonParser, DeserializationCont if (node.get("class") != null) { String _class = node.get("class").asText(); - GenericType genericType = new GenericType(new PackageableType(_class)); - if ("meta::pure::mapping::Result".equals(_class) || "Result".equals(_class)) - { - genericType.typeArguments = Lists.mutable.of(new GenericType(new PackageableType("meta::pure::metamodel::type::Any"))); - genericType.multiplicityArguments = Lists.mutable.of(Multiplicity.PURE_MANY); - } - variable.genericType = genericType; + variable.genericType = new GenericType(new PackageableType(_class)); } // Backward compatibility - old protocol ------------------------------------------------------------------- diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/application/AppliedFunction.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/application/AppliedFunction.java index 9356bcdc45b..94f7b1570f4 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/application/AppliedFunction.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-protocol-pure/src/main/java/org/finos/legend/engine/protocol/pure/v1/model/valueSpecification/application/AppliedFunction.java @@ -14,27 +14,11 @@ package org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.util.StdConverter; import java.util.Collections; import java.util.List; -import java.util.Optional; -import java.util.Set; -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.factory.Sets; -import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.engine.protocol.pure.v1.model.type.GenericType; -import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.KeyExpression; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.datatype.CString; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.GenericTypeInstance; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.PackageableElementPtr; -@JsonDeserialize(converter = AppliedFunction.AppliedFunctionConverter.class) public class AppliedFunction extends AbstractAppliedFunction { public String function; @@ -46,49 +30,4 @@ public T accept(ValueSpecificationVisitor visitor) { return visitor.visit(this); } - - public static class AppliedFunctionConverter extends StdConverter - { - @Override - public AppliedFunction convert(AppliedFunction appliedFunction) - { - if (appliedFunction.function.equals("new")) - { - // Backward compatibility - old protocol ------------------------------------------------------------------- - if (appliedFunction.parameters.get(0) instanceof PackageableElementPtr) - { - PackageableElementPtr packageableElementPtr = (PackageableElementPtr) appliedFunction.parameters.get(0); - - Set classesThatNeedTypeFixing = Sets.fixedSize.of( - "meta::pure::tds::BasicColumnSpecification", - "BasicColumnSpecification", - "meta::pure::tds::TdsOlapRank", - "TdsOlapRank" - ); - if (classesThatNeedTypeFixing.contains(packageableElementPtr.fullPath)) - { - Collection collection = (Collection) appliedFunction.parameters.get(2); - Optional func = ListIterate.detectOptional(collection.values, x -> ((CString) ((KeyExpression) x).key).value.equals("func")) - .map(KeyExpression.class::cast) - .map(x -> x.expression) - .filter(Lambda.class::isInstance) - .map(Lambda.class::cast) - .filter(x -> x.parameters.size() == 1); - - if (func.isPresent()) - { - Lambda l = func.get(); - PackageableType rawType = new PackageableType(packageableElementPtr.fullPath); - rawType.sourceInformation = packageableElementPtr.sourceInformation; - List classType = Lists.mutable.of(new GenericType(rawType, Lists.mutable.with(l.parameters.get(0).genericType))); - GenericTypeInstance generic = new GenericTypeInstance(new GenericType(new PackageableType("meta::pure::metamodel::type::Class"), classType)); - appliedFunction.parameters.set(0, generic); - } - } - } - // Backward compatibility ------------------------------------------------------------------- - } - return appliedFunction; - } - } } diff --git a/legend-engine-core/legend-engine-core-shared/legend-engine-shared-core/src/main/java/org/finos/legend/engine/shared/core/ObjectMapperFactory.java b/legend-engine-core/legend-engine-core-shared/legend-engine-shared-core/src/main/java/org/finos/legend/engine/shared/core/ObjectMapperFactory.java index ba623662613..1f9b99853cc 100644 --- a/legend-engine-core/legend-engine-core-shared/legend-engine-shared-core/src/main/java/org/finos/legend/engine/shared/core/ObjectMapperFactory.java +++ b/legend-engine-core/legend-engine-core-shared/legend-engine-shared-core/src/main/java/org/finos/legend/engine/shared/core/ObjectMapperFactory.java @@ -19,9 +19,8 @@ import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory; - import java.util.TimeZone; +import org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory; public class ObjectMapperFactory { @@ -44,11 +43,11 @@ public static ObjectMapper getNewStandardObjectMapper() public static ObjectMapper getNewStandardObjectMapperWithPureProtocolExtensionSupports() { - return withStandardConfigurations(PureProtocolObjectMapperFactory.withPureProtocolExtensions(new ObjectMapper())); - } - - public static ObjectMapper getNewStandardObjectMapperWithPureProtocolConverterSupports() - { - return withStandardConfigurations(PureProtocolObjectMapperFactory.withPureProtocolConverter(new ObjectMapper())); + return withStandardConfigurations( + // Tactically we will run converters as part of the standard flow + PureProtocolObjectMapperFactory.withPureProtocolConverter( + PureProtocolObjectMapperFactory.withPureProtocolExtensions(new ObjectMapper()) + ) + ); } }