Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Artifact Generator for FunctionActivator Metadata #2729

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,13 @@
</dependency>
<!-- Dataspace -->

<!-- FunctionActivator -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-generation</artifactId>
</dependency>
<!-- FunctionActivator -->

<!-- Snowflake App -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -472,7 +473,8 @@ protected Iterable<? extends Class<? extends ArtifactGenerationExtension>> getEx
.with(SearchDocumentArtifactGenerationExtension.class)
.with(OpenApiArtifactGenerationExtension.class)
.with(SnowflakeAppArtifactGenerationExtension.class)
.with(HostedServiceArtifactGenerationExtension.class);
.with(HostedServiceArtifactGenerationExtension.class)
.with(FunctionActivatorArtifactGenerationExtension.class);
}

protected Iterable<? extends Class<? extends EntitlementServiceExtension>> getExpectedEntitlementServiceExtensions()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2020 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xts-functionActivator</artifactId>
<version>4.42.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>legend-engine-xt-functionActivator-generation</artifactId>
<packaging>jar</packaging>
<name>Legend Engine - XT - Function Activator - Generation</name>

<dependencies>
<!-- Pure -->
<dependency>
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-m3-core</artifactId>
</dependency>
<!-- Pure -->

<!-- ENGINE -->
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-pure-platform-java</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-shared-core</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-protocol-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-compiler</artifactId>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-pure</artifactId>
</dependency>

<!-- ENGINE -->

<!-- ECLIPSE COLLECTIONS -->
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
</dependency>
<!-- ECLIPSE COLLECTIONS -->

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- LOG -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- LOG -->

<!-- TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-dsl-generation</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-dsl-generation</artifactId>
</dependency>

<!-- TEST -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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<String> 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<Artifact> generate(PackageableElement element, PureModel pureModel, PureModelContextData data, String clientVersion)
{
List<Artifact> 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;
}


}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.finos.legend.engine.functionActivator.generation.FunctionActivatorArtifactGenerationExtension
2 changes: 2 additions & 0 deletions legend-engine-xts-functionActivator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
<module>legend-engine-xt-functionActivator-deployment</module>
<module>legend-engine-xt-functionActivator-protocol</module>
<module>legend-engine-xt-functionActivator-pure</module>
<module>legend-engine-xt-functionActivator-generation</module>

</modules>
</project>
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@
<artifactId>legend-engine-xt-functionActivator-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-xt-functionActivator-generation</artifactId>
<version>${project.version}</version>
</dependency>

<!-- ENGINE -->
<dependency>
Expand Down
Loading