From 5878257dfc8d4c2893b70421ef71c9d271f1645e Mon Sep 17 00:00:00 2001 From: Mohammed Ibrahim Date: Wed, 21 Jun 2023 14:44:48 -0400 Subject: [PATCH] uplift function activator interface --- .../api/FunctionActivatorAPI.java | 49 ++++++++++++++----- .../service/FunctionActivatorArtifact.java | 19 +++++++ .../service/FunctionActivatorService.java | 7 ++- .../api/SnowflakeAppArtifact.java | 30 ++++++++++++ .../snowflakeApp/api/SnowflakeAppService.java | 13 ++++- 5 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorArtifact.java create mode 100644 legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppArtifact.java diff --git a/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/api/FunctionActivatorAPI.java b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/api/FunctionActivatorAPI.java index 1e3901068b0..cbc91a8b6e4 100644 --- a/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/api/FunctionActivatorAPI.java +++ b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/api/FunctionActivatorAPI.java @@ -90,12 +90,8 @@ public Response validate(FunctionActivatorInput input, @ApiParam(hidden = true) String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion; PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null); Root_meta_external_functionActivator_FunctionActivator activator = (Root_meta_external_functionActivator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator); - FunctionActivatorService service = FunctionActivatorLoader.extensions().select(c -> c.supports(activator)).getFirst(); - if (service == null) - { - throw new RuntimeException(activator.getClass().getSimpleName() + "is not supported!"); - } - return Response.ok(objectMapper.writeValueAsString(service.validate(pureModel, activator, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build(); + FunctionActivatorService service = getActivatorService(activator, pureModel); + return Response.ok(objectMapper.writeValueAsString(service.validate(pureModel, activator, input.model, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build(); } catch (Exception ex) { @@ -117,12 +113,8 @@ public Response publishToSandbox(FunctionActivatorInput input, @ApiParam(hidden String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion; PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null); Root_meta_external_functionActivator_FunctionActivator activator = (Root_meta_external_functionActivator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator); - FunctionActivatorService service = FunctionActivatorLoader.extensions().select(c -> c.supports(activator)).getFirst(); - if (service == null) - { - throw new RuntimeException(activator.getClass().getSimpleName() + "is not supported!"); - } - return Response.ok(objectMapper.writeValueAsString(service.publishToSandbox(pureModel, activator, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build(); + FunctionActivatorService service = getActivatorService(activator,pureModel); + return Response.ok(objectMapper.writeValueAsString(service.publishToSandbox(pureModel, activator, input.model, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build(); } catch (Exception ex) { @@ -130,4 +122,37 @@ public Response publishToSandbox(FunctionActivatorInput input, @ApiParam(hidden return ExceptionTool.exceptionManager(ex, LoggingEventType.CATCH_ALL, profiles); } } + + @POST + @Path("renderArtifact") + @ApiOperation(value = "Display generated artifact as text where applicable") + @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) + @Produces(MediaType.APPLICATION_JSON) + public Response renderArtifact(FunctionActivatorInput input, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) + { + MutableList profiles = ProfileManagerHelper.extractProfiles(pm); + try + { + String clientVersion = input.clientVersion == null ? PureClientVersions.production : input.clientVersion; + PureModel pureModel = modelManager.loadModel(input.model, clientVersion, profiles, null); + Root_meta_external_functionActivator_FunctionActivator activator = (Root_meta_external_functionActivator_FunctionActivator) pureModel.getPackageableElement(input.functionActivator); + FunctionActivatorService service = getActivatorService(activator, pureModel); + return Response.ok(objectMapper.writeValueAsString(service.renderArtifact(pureModel, activator, input.model, routerExtensions))).type(MediaType.APPLICATION_JSON_TYPE).build(); + } + catch (Exception ex) + { + ex.printStackTrace(); + return ExceptionTool.exceptionManager(ex, LoggingEventType.CATCH_ALL, profiles); + } + } + + public FunctionActivatorService getActivatorService(Root_meta_external_functionActivator_FunctionActivator activator, PureModel pureModel) + { + FunctionActivatorService service = FunctionActivatorLoader.extensions().select(c -> c.supports(activator)).getFirst(); + if (service == null) + { + throw new RuntimeException(activator.getClass().getSimpleName() + "is not supported!"); + } + return service; + } } diff --git a/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorArtifact.java b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorArtifact.java new file mode 100644 index 00000000000..4b90b52334f --- /dev/null +++ b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorArtifact.java @@ -0,0 +1,19 @@ +// 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.service; + +public class FunctionActivatorArtifact +{ +} diff --git a/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorService.java b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorService.java index c3fc521581d..b65b709e124 100644 --- a/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorService.java +++ b/legend-engine-xt-functionActivator-api/src/main/java/org/finos/legend/engine/functionActivator/service/FunctionActivatorService.java @@ -19,6 +19,7 @@ import org.eclipse.collections.api.list.MutableList; import org.finos.legend.engine.functionActivator.api.output.FunctionActivatorInfo; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; import org.finos.legend.pure.generated.Root_meta_external_functionActivator_FunctionActivator; import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension; @@ -28,7 +29,9 @@ public interface FunctionActivatorService validate(PureModel pureModel, T functionActivator, Function> routerExtensions); + MutableList validate(PureModel pureModel, T functionActivator, PureModelContext inputModel, Function> routerExtensions); - MutableList publishToSandbox(PureModel pureModel, T functionActivator, Function> routerExtensions); + MutableList publishToSandbox(PureModel pureModel, T functionActivator, PureModelContext inputModel, Function> routerExtensions); + + FunctionActivatorArtifact renderArtifact(PureModel pureModel, T functionActivator, PureModelContext inputModel, Function> routerExtensions); } diff --git a/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppArtifact.java b/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppArtifact.java new file mode 100644 index 00000000000..f8992289f62 --- /dev/null +++ b/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppArtifact.java @@ -0,0 +1,30 @@ +// 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.language.snowflakeApp.api; + +import org.eclipse.collections.api.RichIterable; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.MutableList; +import org.finos.legend.engine.functionActivator.service.FunctionActivatorArtifact; + +public class SnowflakeAppArtifact extends FunctionActivatorArtifact +{ + RichIterable sqlExpressions = Lists.mutable.empty(); + + public SnowflakeAppArtifact(RichIterable sqlExpressions) + { + this.sqlExpressions = sqlExpressions; + } +} diff --git a/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppService.java b/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppService.java index df0f3395ed6..10c83b1a8b2 100644 --- a/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppService.java +++ b/legend-engine-xt-snowflakeApp-api/src/main/java/org/finos/legend/engine/language/snowflakeApp/api/SnowflakeAppService.java @@ -27,6 +27,7 @@ import org.finos.legend.engine.plan.execution.stores.relational.connection.manager.ConnectionManagerSelector; import org.finos.legend.engine.plan.generation.PlanGenerator; import org.finos.legend.engine.plan.platform.PlanPlatform; +import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext; import org.finos.legend.engine.protocol.snowflakeApp.metamodel.SnowflakeAppProtocolExtension; import org.finos.legend.pure.generated.Root_meta_external_functionActivator_FunctionActivator; import org.finos.legend.pure.generated.Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp; @@ -77,7 +78,7 @@ public boolean supports(Root_meta_external_functionActivator_FunctionActivator f } @Override - public MutableList validate(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, Function> routerExtensions) + public MutableList validate(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, PureModelContext inputModel, Function> routerExtensions) { RichIterable sqlExpressions = extractSQLExpressions(pureModel, activator, routerExtensions); return sqlExpressions.size() != 1 ? @@ -87,7 +88,7 @@ public MutableList validate(PureModel pureMode } @Override - public MutableList publishToSandbox(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, Function> routerExtensions) + public MutableList publishToSandbox(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, PureModelContext inputModel, Function> routerExtensions) { Object[] objects = this.extractSQLExpressionsAndConnectionMetadata(pureModel, activator, routerExtensions); RichIterable sqlExpressions = (RichIterable) objects[0]; @@ -108,6 +109,13 @@ public MutableList publishToSandbox(PureModel } } + @Override + public SnowflakeAppArtifact renderArtifact(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, PureModelContext inputModel, Function> routerExtensions) + { + RichIterable sqlExpressions = extractSQLExpressions(pureModel, activator, routerExtensions); + return new SnowflakeAppArtifact(sqlExpressions); + } + private RichIterable extractSQLExpressions(PureModel pureModel, Root_meta_external_functionActivator_snowflakeApp_SnowflakeApp activator, Function> routerExtensions) { PackageableFunction function = activator._function(); @@ -143,4 +151,5 @@ private RichIterable collectAllNodes { return Lists.mutable.with(node).withAll(node._executionNodes().flatCollect(this::collectAllNodes)); } + }