diff --git a/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml b/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml index 9751dee422d..57e642c5567 100644 --- a/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml +++ b/legend-engine-config/legend-engine-extensions-collection-generation/pom.xml @@ -479,6 +479,13 @@ + + + org.finos.legend.engine + legend-engine-xt-functionActivator-generation + + + org.finos.legend.engine 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 e8c1be13786..b3a956abf38 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 @@ -25,6 +25,7 @@ import org.finos.legend.engine.external.format.flatdata.driver.spi.FlatDataDriverDescription; import org.finos.legend.engine.external.shared.format.extension.GenerationExtension; import org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension; +import org.finos.legend.engine.functionActivator.generation.FunctionActivatorArtifactGenerationExtension; import org.finos.legend.engine.generation.DataSpaceAnalyticsArtifactGenerationExtension; import org.finos.legend.engine.generation.OpenApiArtifactGenerationExtension; import org.finos.legend.engine.generation.SearchDocumentArtifactGenerationExtension; @@ -472,7 +473,8 @@ protected Iterable> getEx .with(SearchDocumentArtifactGenerationExtension.class) .with(OpenApiArtifactGenerationExtension.class) .with(SnowflakeAppArtifactGenerationExtension.class) - .with(HostedServiceArtifactGenerationExtension.class); + .with(HostedServiceArtifactGenerationExtension.class) + .with(FunctionActivatorArtifactGenerationExtension.class); } protected Iterable> getExpectedEntitlementServiceExtensions() diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml new file mode 100644 index 00000000000..54880ccc1c9 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/pom.xml @@ -0,0 +1,112 @@ + + + + + + org.finos.legend.engine + legend-engine-xts-functionActivator + 4.42.1-SNAPSHOT + + 4.0.0 + + legend-engine-xt-functionActivator-generation + jar + Legend Engine - XT - Function Activator - Generation + + + + + org.finos.legend.pure + legend-pure-m3-core + + + + + + org.finos.legend.engine + legend-engine-pure-platform-java + + + org.finos.legend.engine + legend-engine-shared-core + + + org.finos.legend.engine + legend-engine-protocol-pure + + + org.finos.legend.engine + legend-engine-language-pure-compiler + + + + org.finos.legend.engine + legend-engine-xt-functionActivator-pure + + + + + + + org.eclipse.collections + eclipse-collections-api + + + org.eclipse.collections + eclipse-collections + + + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.slf4j + slf4j-api + + + + + + junit + junit + test + + + log4j + log4j + test + + + org.finos.legend.engine + legend-engine-xt-functionActivator-protocol + + + org.finos.legend.engine + legend-engine-language-pure-dsl-generation + + + org.finos.legend.engine + legend-engine-language-pure-dsl-generation + + + + + diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorArtifactGenerationExtension.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorArtifactGenerationExtension.java new file mode 100644 index 00000000000..492adf33be9 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorArtifactGenerationExtension.java @@ -0,0 +1,105 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.engine.functionActivator.generation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.MutableList; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.language.pure.dsl.generation.extension.Artifact; +import org.finos.legend.engine.language.pure.dsl.generation.extension.ArtifactGenerationExtension; +import org.finos.legend.engine.protocol.functionActivator.metamodel.DeploymentOwner; +import org.finos.legend.engine.protocol.functionActivator.metamodel.FunctionActivator; +import org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC; +import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; +import org.finos.legend.engine.shared.core.ObjectMapperFactory; +import org.finos.legend.pure.generated.Root_meta_external_function_activator_FunctionActivator; +import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement; +import org.slf4j.Logger; + +import java.util.List; + +import static org.finos.legend.pure.generated.platform_pure_basics_meta_elementToPath.Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_; + +public class FunctionActivatorArtifactGenerationExtension implements ArtifactGenerationExtension +{ + private static final ObjectMapper mapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports(); + + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(FunctionActivatorArtifactGenerationExtension.class); + + public final String ROOT_PATH = "Function-Activator-Artifact-Generation"; + + private static final String FILE_NAME = "functionActivatorMetadata.json"; + + @Override + public MutableList group() + { + return org.eclipse.collections.impl.factory.Lists.mutable.with("Function_Activator"); + } + + @Override + public String getKey() + { + return ROOT_PATH; + } + + @Override + public boolean canGenerate(PackageableElement element) + { + return element instanceof Root_meta_external_function_activator_FunctionActivator; + } + + + @Override + public List generate(PackageableElement element, PureModel pureModel, PureModelContextData data, String clientVersion) + { + List result = Lists.mutable.empty(); + Root_meta_external_function_activator_FunctionActivator activator = (Root_meta_external_function_activator_FunctionActivator) element; + try + { + PureModelContextData activatorProtocol = fetchActivator(activator, data, pureModel); + AlloySDLC activatorCoordinates = (AlloySDLC) activatorProtocol.origin.sdlcInfo; + FunctionActivator activatorElement = (FunctionActivator) activatorProtocol.getElements().get(0); + FunctionActivatorMetadata metadata = new FunctionActivatorMetadata(activatorElement.name, activatorElement._package, + ((DeploymentOwner)activatorElement.ownership).id, activatorCoordinates.version, activatorCoordinates.groupId, activatorCoordinates.artifactId); + String content = mapper.writeValueAsString(metadata); + result.add(new Artifact(content, FILE_NAME, "json")); + } + catch (Exception e) + { + LOGGER.error("Error generating Activator Metadata ", e); + } + return result; + } + + public static PureModelContextData fetchActivator(Root_meta_external_function_activator_FunctionActivator activator, PureModelContextData data, PureModel pureModel) + { + return PureModelContextData.newBuilder() + .withElements(org.eclipse.collections.api.factory.Lists.mutable.withAll(data.getElements()).select(e -> e instanceof FunctionActivator && elementToPath(activator, pureModel).equals(elementName((FunctionActivator)e)))) + .withOrigin(data.origin).build(); + } + + public static String elementToPath(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement element, PureModel pureModel) + { + return Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_(element, pureModel.getExecutionSupport()); + } + + public static String elementName(FunctionActivator activator) + { + return activator._package + "::" + activator.name; + } + + +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorMetadata.java b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorMetadata.java new file mode 100644 index 00000000000..9bdcfb99243 --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/java/org/finos/legend/engine/functionActivator/generation/FunctionActivatorMetadata.java @@ -0,0 +1,41 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.engine.functionActivator.generation; + +public class FunctionActivatorMetadata +{ + + public String name; + public String packagePath; + public String ownerIdentifier; + public String version; + public String groupId; + public String artifactId; + + public FunctionActivatorMetadata() + { + //Jackson + } + + public FunctionActivatorMetadata(String name, String packagePath, String ownerIdentifier, String version, String groupId, String artifactId) + { + this.name = name; + this.packagePath = packagePath; + this.ownerIdentifier = ownerIdentifier; + this.version = version; + this.groupId = groupId; + this.artifactId = artifactId; + } +} diff --git a/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.dsl.generation.extension.ArtifactGenerationExtension b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.dsl.generation.extension.ArtifactGenerationExtension new file mode 100644 index 00000000000..2c0f21a543d --- /dev/null +++ b/legend-engine-xts-functionActivator/legend-engine-xt-functionActivator-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.pure.dsl.generation.extension.ArtifactGenerationExtension @@ -0,0 +1 @@ +org.finos.legend.engine.functionActivator.generation.FunctionActivatorArtifactGenerationExtension \ No newline at end of file diff --git a/legend-engine-xts-functionActivator/pom.xml b/legend-engine-xts-functionActivator/pom.xml index e55a35dbd4d..3105f99c1a2 100644 --- a/legend-engine-xts-functionActivator/pom.xml +++ b/legend-engine-xts-functionActivator/pom.xml @@ -33,5 +33,7 @@ legend-engine-xt-functionActivator-deployment legend-engine-xt-functionActivator-protocol legend-engine-xt-functionActivator-pure + legend-engine-xt-functionActivator-generation + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1a6cc973be8..a481e988ab4 100644 --- a/pom.xml +++ b/pom.xml @@ -613,7 +613,11 @@ legend-engine-xt-functionActivator-deployment ${project.version} - + + org.finos.legend.engine + legend-engine-xt-functionActivator-generation + ${project.version} +