From d4d645d285a6bff927cf98e49a8cb83296de3c76 Mon Sep 17 00:00:00 2001 From: Rafael Bey <24432403+rafaelbey@users.noreply.github.com> Date: Fri, 28 Jun 2024 08:07:14 -0400 Subject: [PATCH] Ensure all protocol PackageableElement have a classifier mapped to it (#2937) --- .../collection/generation/TestExtensions.java | 26 ++++++++++++++++++- .../BigQueryFunctionProtocolExtension.java | 7 ++--- .../MemSqlFunctionProtocolExtension.java | 7 ++--- .../pure/v1/ServiceProtocolExtension.java | 5 +++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java b/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java index 220ab9834de..de34c3cc6de 100644 --- a/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java +++ b/legend-engine-config/legend-engine-extensions-collection-generation/src/test/java/org/finos/legend/engine/extensions/collection/generation/TestExtensions.java @@ -14,11 +14,14 @@ package org.finos.legend.engine.extensions.collection.generation; +import org.eclipse.collections.api.block.function.Function0; import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.MutableSet; +import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.utility.Iterate; +import org.eclipse.collections.impl.utility.LazyIterate; import org.finos.legend.engine.entitlement.services.EntitlementServiceExtension; import org.finos.legend.engine.entitlement.services.EntitlementServiceExtensionLoader; import org.finos.legend.engine.entitlement.services.RelationalDatabaseEntitlementServiceExtension; @@ -89,8 +92,9 @@ import org.finos.legend.engine.protocol.bigqueryFunction.metamodel.BigQueryFunctionProtocolExtension; import org.finos.legend.engine.protocol.hostedService.metamodel.HostedServiceProtocolExtension; import org.finos.legend.engine.protocol.memsqlFunction.metamodel.MemSqlFunctionProtocolExtension; +import org.finos.legend.engine.protocol.pure.v1.extension.ProtocolSubTypeInfo; +import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement; import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.*; import org.finos.legend.pure.code.core.ElasticsearchLegendPureCoreExtension; import org.finos.legend.engine.language.stores.elasticsearch.v7.to.ElasticsearchGrammarComposerExtension; import org.finos.legend.engine.protocol.pure.v1.extension.PureProtocolExtension; @@ -112,6 +116,7 @@ import org.junit.Test; import java.util.Collections; +import java.util.List; import java.util.ServiceLoader; public class TestExtensions @@ -207,6 +212,25 @@ public void testMetadataDeserializer() expectedClassifiers.reject(cl -> deserializer.hasInstance("meta::pure::metamodel::type::Class", "Root::" + cl), Lists.mutable.empty())); } + @Test + public void testPackageableElementProtocolDefineClassifier() + { + List extensions = PureProtocolExtensionLoader.extensions(); + + MutableSet> packageableElementProtocolClasses = Iterate.flatCollect(extensions, extension -> + LazyIterate.flatCollect(extension.getExtraProtocolSubTypeInfoCollectors(), Function0::value) + .select(info -> info.getSuperType().equals(PackageableElement.class)) + .flatCollect(ProtocolSubTypeInfo::getSubTypes) + .collect(Pair::getOne), Sets.mutable.empty()); + + MutableSet> classesWithClassifiers = Iterate.flatCollect(extensions, ext -> ext.getExtraProtocolToClassifierPathMap().keySet(), Sets.mutable.empty()); + + for (Class packageableElementProtocolClass : packageableElementProtocolClasses) + { + Assert.assertTrue(packageableElementProtocolClass.getName() + " does not have entry on protocolToClassifierPathMap", classesWithClassifiers.remove(packageableElementProtocolClass)); + } + } + @Test public void testMetadata() { diff --git a/legend-engine-xts-bigqueryFunction/legend-engine-xt-bigqueryFunction-protocol/src/main/java/org/finos/legend/engine/protocol/bigqueryFunction/metamodel/BigQueryFunctionProtocolExtension.java b/legend-engine-xts-bigqueryFunction/legend-engine-xt-bigqueryFunction-protocol/src/main/java/org/finos/legend/engine/protocol/bigqueryFunction/metamodel/BigQueryFunctionProtocolExtension.java index c9f8cff0a0b..908a3a78d5b 100644 --- a/legend-engine-xts-bigqueryFunction/legend-engine-xt-bigqueryFunction-protocol/src/main/java/org/finos/legend/engine/protocol/bigqueryFunction/metamodel/BigQueryFunctionProtocolExtension.java +++ b/legend-engine-xts-bigqueryFunction/legend-engine-xt-bigqueryFunction-protocol/src/main/java/org/finos/legend/engine/protocol/bigqueryFunction/metamodel/BigQueryFunctionProtocolExtension.java @@ -46,8 +46,6 @@ public List>>> getExtraProtocolSubTypeInfo return Lists.fixedSize.with(() -> Lists.mutable.with( ProtocolSubTypeInfo.newBuilder(PackageableElement.class) .withSubtype(BigQueryFunction.class, packageJSONType) - .build(), - ProtocolSubTypeInfo.newBuilder(PackageableElement.class) .withSubtype(BigQueryFunctionDeploymentConfiguration.class, packageJSONType + "Config") .build(), ProtocolSubTypeInfo.newBuilder(FunctionActivatorDeploymentConfiguration.class) @@ -65,6 +63,9 @@ public List>>> getExtraProtocolSubTypeInfo @Override public Map, String> getExtraProtocolToClassifierPathMap() { - return Maps.mutable.with(BigQueryFunction.class, "meta::external::function::activator::bigQueryFunction::BigQueryFunction"); + return Maps.mutable.with( + BigQueryFunction.class, "meta::external::function::activator::bigQueryFunction::BigQueryFunction", + BigQueryFunctionDeploymentConfiguration.class, "meta::external::function::activator::bigQueryFunction::BigQueryFunctionDeploymentConfiguration" + ); } } diff --git a/legend-engine-xts-memsqlFunction/legend-engine-xt-memsqlFunction-protocol/src/main/java/org/finos/legend/engine/protocol/memsqlFunction/metamodel/MemSqlFunctionProtocolExtension.java b/legend-engine-xts-memsqlFunction/legend-engine-xt-memsqlFunction-protocol/src/main/java/org/finos/legend/engine/protocol/memsqlFunction/metamodel/MemSqlFunctionProtocolExtension.java index a1ebced60fe..86b68256d23 100644 --- a/legend-engine-xts-memsqlFunction/legend-engine-xt-memsqlFunction-protocol/src/main/java/org/finos/legend/engine/protocol/memsqlFunction/metamodel/MemSqlFunctionProtocolExtension.java +++ b/legend-engine-xts-memsqlFunction/legend-engine-xt-memsqlFunction-protocol/src/main/java/org/finos/legend/engine/protocol/memsqlFunction/metamodel/MemSqlFunctionProtocolExtension.java @@ -39,8 +39,6 @@ public List>>> getExtraProtocolSubTypeInfo return Lists.fixedSize.with(() -> Lists.mutable.with( ProtocolSubTypeInfo.newBuilder(PackageableElement.class) .withSubtype(MemSqlFunction.class, packageJSONType) - .build(), - ProtocolSubTypeInfo.newBuilder(PackageableElement.class) .withSubtype(MemSqlFunctionDeploymentConfiguration.class, packageJSONType + "Config") .build(), ProtocolSubTypeInfo.newBuilder(FunctionActivatorDeploymentConfiguration.class) @@ -58,6 +56,9 @@ public List>>> getExtraProtocolSubTypeInfo @Override public Map, String> getExtraProtocolToClassifierPathMap() { - return Maps.mutable.with(MemSqlFunction.class, "meta::external::function::activator::memSqlFunction::MemSqlFunction"); + return Maps.mutable.with( + MemSqlFunction.class, "meta::external::function::activator::memSqlFunction::MemSqlFunction", + MemSqlFunctionDeploymentConfiguration.class, "meta::external::function::activator::memSqlFunction::MemSqlFunctionDeploymentConfiguration" + ); } } diff --git a/legend-engine-xts-service/legend-engine-language-pure-dsl-service/src/main/java/org/finos/legend/engine/protocol/pure/v1/ServiceProtocolExtension.java b/legend-engine-xts-service/legend-engine-language-pure-dsl-service/src/main/java/org/finos/legend/engine/protocol/pure/v1/ServiceProtocolExtension.java index ebf8f48c169..71648edae2b 100644 --- a/legend-engine-xts-service/legend-engine-language-pure-dsl-service/src/main/java/org/finos/legend/engine/protocol/pure/v1/ServiceProtocolExtension.java +++ b/legend-engine-xts-service/legend-engine-language-pure-dsl-service/src/main/java/org/finos/legend/engine/protocol/pure/v1/ServiceProtocolExtension.java @@ -92,6 +92,9 @@ public List>>> getExtraProtocolSubTypeInfo @Override public Map, String> getExtraProtocolToClassifierPathMap() { - return Maps.mutable.with(Service.class, SERVICE_CLASSIFIER_PATH); + return Maps.mutable.with( + Service.class, SERVICE_CLASSIFIER_PATH, + ExecutionEnvironmentInstance.class, "meta::legend::service::metamodel::ExecutionEnvironmentInstance" + ); } }