Skip to content

Commit

Permalink
Ensure all protocol PackageableElement have a classifier mapped to it (
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey authored Jun 28, 2024
1 parent 0b98e56 commit d4d645d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -112,6 +116,7 @@
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;

public class TestExtensions
Expand Down Expand Up @@ -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<PureProtocolExtension> extensions = PureProtocolExtensionLoader.extensions();

MutableSet<? extends Class<?>> 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<Class<? extends PackageableElement>> 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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> 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)
Expand All @@ -65,6 +63,9 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> getExtraProtocolSubTypeInfo
@Override
public Map<Class<? extends PackageableElement>, 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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> 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)
Expand All @@ -58,6 +56,9 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> getExtraProtocolSubTypeInfo
@Override
public Map<Class<? extends PackageableElement>, 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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public List<Function0<List<ProtocolSubTypeInfo<?>>>> getExtraProtocolSubTypeInfo
@Override
public Map<Class<? extends PackageableElement>, 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"
);
}
}

0 comments on commit d4d645d

Please sign in to comment.