diff --git a/legend-engine-xts-avro/legend-engine-xt-avro-api/pom.xml b/legend-engine-xts-avro/legend-engine-xt-avro-api/pom.xml index 2a13f5cf67d..798ff0363c0 100644 --- a/legend-engine-xts-avro/legend-engine-xt-avro-api/pom.xml +++ b/legend-engine-xts-avro/legend-engine-xt-avro-api/pom.xml @@ -46,6 +46,14 @@ + + + com.fasterxml.jackson.core + jackson-databind + + + + io.swagger @@ -92,6 +100,28 @@ pac4j-core + + + + junit + junit + test + + + org.finos.legend.engine + legend-engine-language-pure-compiler + test-jar + test + + + org.glassfish.jersey.core + jersey-common + ${jersey.version} + test + + + + diff --git a/legend-engine-xts-avro/legend-engine-xt-avro/src/test/java/org/finos/legend/engine/external/format/avro/tests/TestAvroGeneration.java b/legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/java/org/finos/legend/engine/external/format/avro/schema/generations/api/TestAvroGeneration.java similarity index 96% rename from legend-engine-xts-avro/legend-engine-xt-avro/src/test/java/org/finos/legend/engine/external/format/avro/tests/TestAvroGeneration.java rename to legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/java/org/finos/legend/engine/external/format/avro/schema/generations/api/TestAvroGeneration.java index 8fa85e180e6..653174ed458 100644 --- a/legend-engine-xts-avro/legend-engine-xt-avro/src/test/java/org/finos/legend/engine/external/format/avro/tests/TestAvroGeneration.java +++ b/legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/java/org/finos/legend/engine/external/format/avro/schema/generations/api/TestAvroGeneration.java @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.finos.legend.engine.external.format.avro.tests; +package org.finos.legend.engine.external.format.avro.schema.generations.api; import com.fasterxml.jackson.databind.ObjectMapper; import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationInput; -import org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationService; import org.finos.legend.engine.language.pure.modelManager.ModelManager; import org.finos.legend.engine.shared.core.ObjectMapperFactory; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; diff --git a/legend-engine-xts-avro/legend-engine-xt-avro/src/test/resources/org/finos/legend/engine/external/format/avro/tests/avroInputNoConfig.json b/legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/resources/org/finos/legend/engine/external/format/avro/schema/generations/api/avroInputNoConfig.json similarity index 100% rename from legend-engine-xts-avro/legend-engine-xt-avro/src/test/resources/org/finos/legend/engine/external/format/avro/tests/avroInputNoConfig.json rename to legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/resources/org/finos/legend/engine/external/format/avro/schema/generations/api/avroInputNoConfig.json diff --git a/legend-engine-xts-avro/legend-engine-xt-avro/src/test/resources/org/finos/legend/engine/external/format/avro/tests/avroInputWithNameSpaceConfig.json b/legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/resources/org/finos/legend/engine/external/format/avro/schema/generations/api/avroInputWithNameSpaceConfig.json similarity index 100% rename from legend-engine-xts-avro/legend-engine-xt-avro/src/test/resources/org/finos/legend/engine/external/format/avro/tests/avroInputWithNameSpaceConfig.json rename to legend-engine-xts-avro/legend-engine-xt-avro-api/src/test/resources/org/finos/legend/engine/external/format/avro/schema/generations/api/avroInputWithNameSpaceConfig.json diff --git a/legend-engine-xts-avro/legend-engine-xt-avro/pom.xml b/legend-engine-xts-avro/legend-engine-xt-avro/pom.xml index 71bcdd4760d..904930c5639 100644 --- a/legend-engine-xts-avro/legend-engine-xt-avro/pom.xml +++ b/legend-engine-xts-avro/legend-engine-xt-avro/pom.xml @@ -55,10 +55,6 @@ org.finos.legend.engine legend-engine-protocol-pure - - org.finos.legend.engine - legend-engine-language-pure-modelManager - org.finos.legend.engine legend-engine-language-pure-compiler @@ -77,16 +73,6 @@ - - - io.swagger - swagger-annotations - - - javax.ws.rs - javax.ws.rs-api - - @@ -114,35 +100,6 @@ - - - io.opentracing - opentracing-util - - - io.opentracing - opentracing-api - - - - - - org.slf4j - slf4j-api - - - - - - org.pac4j.jax-rs - core - - - org.pac4j - pac4j-core - - - junit diff --git a/legend-engine-xts-avro/legend-engine-xt-avro/src/main/java/org/finos/legend/engine/external/format/avro/schema/generations/AvroGenerationService.java b/legend-engine-xts-avro/legend-engine-xt-avro/src/main/java/org/finos/legend/engine/external/format/avro/schema/generations/AvroGenerationService.java deleted file mode 100644 index 420795d2591..00000000000 --- a/legend-engine-xts-avro/legend-engine-xt-avro/src/main/java/org/finos/legend/engine/external/format/avro/schema/generations/AvroGenerationService.java +++ /dev/null @@ -1,105 +0,0 @@ -// 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. - -package org.finos.legend.engine.external.format.avro.schema.generations; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput; -import org.finos.legend.pure.generated.core_external_format_avro_transformation_transformation_avroSchemaGenerator; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Deprecated -@Api(tags = "Z - Deprecated - Generation - Schema") -@Path("pure/v1/schemaGeneration") -@Produces(MediaType.APPLICATION_JSON) -public class AvroGenerationService -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(AvroGenerationService.class); - private final ModelManager modelManager; - - public AvroGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @Deprecated - @POST - @Path("avro") - @ApiOperation(value = "Generates Avro schema for a given class and transitive dependencies") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateAvro(AvroGenerationInput generateAvroInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateAvroInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Avro").startActive(true)) - { - return exec(generateAvroInput.config != null ? generateAvroInput.config : new AvroGenerationConfig(), - () -> this.modelManager.loadModelAndData(generateAvroInput.model, generateAvroInput.clientVersion, identity, null).getTwo(), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_AVRO_CODE_ERROR, identity.getName()); - } - } - - private Response exec(AvroGenerationConfig avroConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - long start = System.currentTimeMillis(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_START : LoggingEventType.GENERATE_AVRO_CODE_START).toString()); - PureModel pureModel = pureModelFunc.value(); - RichIterable output = core_external_format_avro_transformation_transformation_avroSchemaGenerator.Root_meta_external_format_avro_generation_generateAvroFromPureWithScope_AvroConfig_1__AvroOutput_MANY_(avroConfig.process(pureModel), pureModel.getExecutionSupport()); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_STOP : LoggingEventType.GENERATE_AVRO_CODE_STOP, (double) System.currentTimeMillis() - start).toString()); - return ManageConstantResult.manageResult(identity.getName(), output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList()); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_AVRO_CODE_ERROR, identity.getName()); - } - } -} diff --git a/legend-engine-xts-daml/legend-engine-xt-daml-api/src/main/java/org/finos/legend/engine/external/format/daml/generation/api/DAMLGenerationService.java b/legend-engine-xts-daml/legend-engine-xt-daml-api/src/main/java/org/finos/legend/engine/external/format/daml/generation/api/DAMLGenerationService.java index a58e965ca33..f0451fa38a3 100644 --- a/legend-engine-xts-daml/legend-engine-xt-daml-api/src/main/java/org/finos/legend/engine/external/format/daml/generation/api/DAMLGenerationService.java +++ b/legend-engine-xts-daml/legend-engine-xt-daml-api/src/main/java/org/finos/legend/engine/external/format/daml/generation/api/DAMLGenerationService.java @@ -57,7 +57,7 @@ @Deprecated public class DAMLGenerationService { - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(org.finos.legend.engine.external.format.daml.generation.DAMLGenerationService.class); + private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(org.finos.legend.engine.external.format.daml.generation.api.DAMLGenerationService.class); private final ModelManager modelManager; public DAMLGenerationService(ModelManager modelManager) diff --git a/legend-engine-xts-daml/legend-engine-xt-daml-model/pom.xml b/legend-engine-xts-daml/legend-engine-xt-daml-model/pom.xml index ee2a2db4140..c05abce4ac4 100644 --- a/legend-engine-xts-daml/legend-engine-xt-daml-model/pom.xml +++ b/legend-engine-xts-daml/legend-engine-xt-daml-model/pom.xml @@ -38,39 +38,6 @@ - - org.pac4j.jax-rs - core - - - org.pac4j - pac4j-core - - - - javax.ws.rs - javax.ws.rs-api - - - - io.opentracing - opentracing-util - - - - org.slf4j - slf4j-api - - - - io.swagger - swagger-annotations - - - - io.opentracing - opentracing-api - org.finos.legend.pure @@ -82,10 +49,6 @@ org.finos.legend.engine legend-engine-language-pure-compiler - - org.finos.legend.engine - legend-engine-language-pure-modelManager - org.finos.legend.engine legend-engine-shared-core diff --git a/legend-engine-xts-daml/legend-engine-xt-daml-model/src/main/java/org/finos/legend/engine/external/format/daml/generation/DAMLGenerationService.java b/legend-engine-xts-daml/legend-engine-xt-daml-model/src/main/java/org/finos/legend/engine/external/format/daml/generation/DAMLGenerationService.java deleted file mode 100644 index cb5c0102c8d..00000000000 --- a/legend-engine-xts-daml/legend-engine-xt-daml-model/src/main/java/org/finos/legend/engine/external/format/daml/generation/DAMLGenerationService.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2022 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.external.format.daml.generation; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput; -import org.finos.legend.pure.generated.core_external_language_daml_deprecated_generation; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Api(tags = "Z - Deprecated - Generation - Schema") -@Path("pure/v1/schemaGeneration") -@Produces(MediaType.APPLICATION_JSON) -@Deprecated -public class DAMLGenerationService -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(DAMLGenerationService.class); - private final ModelManager modelManager; - - public DAMLGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @Deprecated - @POST - @Path("daml") - @ApiOperation(value = "Generates DAML schema for a given class and transitive dependencies") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateDAML(DAMLGenerationInput generateDAMLInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateDAMLInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate DAML").startActive(true)) - { - return exec(generateDAMLInput.config != null ? generateDAMLInput.config : new DAMLGenerationConfig(), - () -> this.modelManager.loadModelAndData(generateDAMLInput.model, generateDAMLInput.clientVersion, identity, null).getTwo(), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, LoggingEventType.GENERATE_DAML_CODE_ERROR, identity.getName()); - } - } - - private Response exec(DAMLGenerationConfig damlConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - long start = System.currentTimeMillis(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_DAML_CODE_START : LoggingEventType.GENERATE_DAML_CODE_START).toString()); - PureModel pureModel = pureModelFunc.value(); - RichIterable output = core_external_language_daml_deprecated_generation.Root_meta_external_language_daml_generation_generateDAML_DAMLConfig_1__DAMLOutput_MANY_(damlConfig.process(pureModel), pureModel.getExecutionSupport()); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_DAML_CODE_STOP : LoggingEventType.GENERATE_DAML_CODE_STOP, (double) System.currentTimeMillis() - start).toString()); - return ManageConstantResult.manageResult(identity.getName(), output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList()); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, LoggingEventType.GENERATE_DAML_CODE_ERROR, identity.getName()); - } - } - -} diff --git a/legend-engine-xts-generation/legend-engine-external-shared/src/main/java/org/finos/legend/engine/external/shared/format/extension/GenerationExtension.java b/legend-engine-xts-generation/legend-engine-external-shared/src/main/java/org/finos/legend/engine/external/shared/format/extension/GenerationExtension.java index cd512b1892e..6b1ad9f3f34 100644 --- a/legend-engine-xts-generation/legend-engine-external-shared/src/main/java/org/finos/legend/engine/external/shared/format/extension/GenerationExtension.java +++ b/legend-engine-xts-generation/legend-engine-external-shared/src/main/java/org/finos/legend/engine/external/shared/format/extension/GenerationExtension.java @@ -15,9 +15,7 @@ package org.finos.legend.engine.external.shared.format.extension; import org.finos.legend.engine.external.shared.format.generations.description.GenerationConfigurationDescription; -import org.finos.legend.engine.external.shared.format.imports.description.ImportConfigurationDescription; import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement; import org.finos.legend.engine.shared.core.extension.LegendGenerationExtension; import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationConfiguration; @@ -41,20 +39,7 @@ default String type() GenerationConfigurationDescription getGenerationDescription(); - /** - * TO REMOVE - */ - default ImportConfigurationDescription getImportDescription() - { - return null; - } - Root_meta_pure_generation_metamodel_GenerationConfiguration defaultConfig(CompileContext context); - default Object getService(ModelManager modelManager) - { - return null; - } - List generateFromElement(PackageableElement element, CompileContext compileContext); } diff --git a/legend-engine-xts-graphQL/legend-engine-xt-graphQL-query/src/main/java/org/finos/legend/engine/query/graphQL/api/format/generation/GraphQLGenerationService.java b/legend-engine-xts-graphQL/legend-engine-xt-graphQL-query/src/main/java/org/finos/legend/engine/query/graphQL/api/format/generation/GraphQLGenerationService.java deleted file mode 100644 index 1c720f992f3..00000000000 --- a/legend-engine-xts-graphQL/legend-engine-xt-graphQL-query/src/main/java/org/finos/legend/engine/query/graphQL/api/format/generation/GraphQLGenerationService.java +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2022 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.query.graphQL.api.format.generation; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput; -import org.finos.legend.pure.generated.core_external_query_graphql_deprecated_generation; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Deprecated -@Api(tags = "Z - Deprecated - Generation - Schema") -@Path("pure/v1/schemaGeneration") -@Produces(MediaType.APPLICATION_JSON) -public class GraphQLGenerationService -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(GraphQLGenerationService.class); - private final ModelManager modelManager; - - public GraphQLGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @Deprecated - @POST - @Path("graphql") - @ApiOperation(value = "Generates GraphQL schema for a given class and transitive dependencies") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateGraphQL(GraphQLGenerationInput generateGraphQLInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateGraphQLInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate GraphQL").startActive(true)) - { - return exec(generateGraphQLInput.config != null ? generateGraphQLInput.config : new GraphQLGenerationConfig(), - () -> this.modelManager.loadModelAndData(generateGraphQLInput.model, generateGraphQLInput.clientVersion, identity, null).getTwo(), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_GRAPHQL_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_GRAPHQL_CODE_ERROR, identity.getName()); - } - } - - private Response exec(GraphQLGenerationConfig graphQLConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - long start = System.currentTimeMillis(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_GRAPHQL_CODE_INTERACTIVE_START : LoggingEventType.GENERATE_GRAPHQL_CODE_START).toString()); - PureModel pureModel = pureModelFunc.value(); - RichIterable output = core_external_query_graphql_deprecated_generation.Root_meta_external_query_graphQL_generation_generateGraphQL_GraphQLConfig_1__GraphQLOutput_MANY_(graphQLConfig.process(pureModel), pureModel.getExecutionSupport()); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_GRAPHQL_CODE_INTERACTIVE_STOP : LoggingEventType.GENERATE_GRAPHQL_CODE_STOP, (double) System.currentTimeMillis() - start).toString()); - return ManageConstantResult.manageResult(identity.getName(), output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList()); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_GRAPHQL_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_GRAPHQL_CODE_ERROR, identity.getName()); - } - } -} \ No newline at end of file diff --git a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/pom.xml b/legend-engine-xts-json/legend-engine-external-format-jsonSchema/pom.xml index 2bc5e02627e..258e5572ff5 100644 --- a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/pom.xml +++ b/legend-engine-xts-json/legend-engine-external-format-jsonSchema/pom.xml @@ -56,10 +56,6 @@ org.finos.legend.engine legend-engine-protocol-pure - - org.finos.legend.engine - legend-engine-language-pure-modelManager - org.finos.legend.engine legend-engine-language-pure-compiler @@ -74,35 +70,6 @@ - - - io.swagger - swagger-annotations - - - javax.ws.rs - javax.ws.rs-api - - - javax.inject - javax.inject - - - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.core - jackson-core - - @@ -115,34 +82,12 @@ - - - io.opentracing - opentracing-util - - - io.opentracing - opentracing-api - - - - - - org.slf4j - slf4j-api - - - - - - org.pac4j.jax-rs - core - + - org.pac4j - pac4j-core + com.fasterxml.jackson.core + jackson-annotations - + diff --git a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/main/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/JSONSchemaGenerationService.java b/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/main/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/JSONSchemaGenerationService.java deleted file mode 100644 index 6862e57169b..00000000000 --- a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/main/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/JSONSchemaGenerationService.java +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2021 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.external.format.jsonSchema.schema.generations; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.core_external_format_json_transformation_toBeRefactored_jsonSchema; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.List; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Deprecated -@Api(tags = "Z - Deprecated - Generation - Schema") -@Path("pure/v1/schemaGeneration") -@Produces(MediaType.APPLICATION_JSON) -@Singleton -public class JSONSchemaGenerationService -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(JSONSchemaGenerationService.class); - private final ModelManager modelManager; - - @Inject - public JSONSchemaGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @Deprecated - @POST - @Path("jsonSchema") - @ApiOperation(value = "Generates JSON schema for a given class and transitive dependencies") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateJSONSchema(GenerateJSONSchemaInput generateJSONSchemaInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateJSONSchemaInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate JSON Schema").startActive(true)) - { - return exec(generateJSONSchemaInput.config != null ? generateJSONSchemaInput.config : new JSONSchemaConfig(), - () -> this.modelManager.loadModel(generateJSONSchemaInput.model, generateJSONSchemaInput.clientVersion, identity, null), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_JSONSCHEMA_INTERACTIVE_ERROR : LoggingEventType.GENERATE_JSONSCHEMA_ERROR, identity.getName()); - } - } - - public static List generate(JSONSchemaConfig jsonSchemaConfig, PureModel pureModel) - { - return core_external_format_json_transformation_toBeRefactored_jsonSchema.Root_meta_external_format_json_schema_generation_generateJsonSchemaFromPureWithScope_JSONSchemaConfig_1__JSONSchemaOutput_MANY_(jsonSchemaConfig.process(pureModel), pureModel.getExecutionSupport()).collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList(); - } - - private Response exec(JSONSchemaConfig jsonSchemaConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - long start = System.currentTimeMillis(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_JSONSCHEMA_INTERACTIVE_START : LoggingEventType.GENERATE_JSONSCHEMA_START).toString()); - PureModel pureModel = pureModelFunc.value(); - List result = generate(jsonSchemaConfig, pureModel); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_JSONSCHEMA_INTERACTIVE_STOP : LoggingEventType.GENERATE_JSONSCHEMA_START, (double) System.currentTimeMillis() - start).toString()); - return ManageConstantResult.manageResult(identity.getName(), result); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_JSONSCHEMA_INTERACTIVE_ERROR : LoggingEventType.GENERATE_JSONSCHEMA_ERROR, identity.getName()); - } - } -} - diff --git a/legend-engine-xts-json/legend-engine-xt-json-api/pom.xml b/legend-engine-xts-json/legend-engine-xt-json-api/pom.xml index 1084d86746d..12b5e8de5d3 100644 --- a/legend-engine-xts-json/legend-engine-xt-json-api/pom.xml +++ b/legend-engine-xts-json/legend-engine-xt-json-api/pom.xml @@ -17,6 +17,10 @@ org.finos.legend.engine legend-engine-external-shared + + org.finos.legend.engine + legend-engine-language-pure-dsl-generation + org.finos.legend.engine legend-engine-xt-json-pure @@ -93,6 +97,28 @@ pac4j-core + + + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + + + junit + junit + test + + + + \ No newline at end of file diff --git a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/test/java/org/finos/legend/engine/external/format/jsonSchema/TestJSONSchemaFileGeneration.java b/legend-engine-xts-json/legend-engine-xt-json-api/src/test/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/api/TestJSONSchemaFileGeneration.java similarity index 92% rename from legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/test/java/org/finos/legend/engine/external/format/jsonSchema/TestJSONSchemaFileGeneration.java rename to legend-engine-xts-json/legend-engine-xt-json-api/src/test/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/api/TestJSONSchemaFileGeneration.java index 7617f8a9d4d..4d3674b1312 100644 --- a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/test/java/org/finos/legend/engine/external/format/jsonSchema/TestJSONSchemaFileGeneration.java +++ b/legend-engine-xts-json/legend-engine-xt-json-api/src/test/java/org/finos/legend/engine/external/format/jsonSchema/schema/generations/api/TestJSONSchemaFileGeneration.java @@ -1,4 +1,4 @@ -// Copyright 2021 Goldman Sachs +// Copyright 2024 Goldman Sachs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,11 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.finos.legend.engine.external.format.jsonSchema; +package org.finos.legend.engine.external.format.jsonSchema.schema.generations.api; import org.finos.legend.engine.external.format.jsonSchema.extension.JSONSchemaGenerationConfigBuilder; import org.finos.legend.engine.external.format.jsonSchema.schema.generations.JSONSchemaConfig; -import org.finos.legend.engine.external.format.jsonSchema.schema.generations.JSONSchemaGenerationService; import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; import com.fasterxml.jackson.core.JsonProcessingException; @@ -25,7 +24,6 @@ import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.fileGeneration.FileGenerationSpecification; import org.finos.legend.engine.shared.core.ObjectMapperFactory; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; -import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.engine.shared.core.identity.factory.*; import org.junit.Assert; import org.junit.Test; diff --git a/legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/test/resources/org/finos/legend/engine/external/format/jsonSchema/simpleFileGeneration.json b/legend-engine-xts-json/legend-engine-xt-json-api/src/test/resources/org/finos/legend/engine/external/format/jsonSchema/schema/generations/api/simpleFileGeneration.json similarity index 100% rename from legend-engine-xts-json/legend-engine-external-format-jsonSchema/src/test/resources/org/finos/legend/engine/external/format/jsonSchema/simpleFileGeneration.json rename to legend-engine-xts-json/legend-engine-xt-json-api/src/test/resources/org/finos/legend/engine/external/format/jsonSchema/schema/generations/api/simpleFileGeneration.json diff --git a/legend-engine-xts-morphir/legend-engine-xt-morphir/pom.xml b/legend-engine-xts-morphir/legend-engine-xt-morphir/pom.xml index 4dd69fc9043..f5caf85a9e4 100644 --- a/legend-engine-xts-morphir/legend-engine-xt-morphir/pom.xml +++ b/legend-engine-xts-morphir/legend-engine-xt-morphir/pom.xml @@ -55,10 +55,6 @@ org.finos.legend.engine legend-engine-protocol-pure - - org.finos.legend.engine - legend-engine-language-pure-modelManager - org.finos.legend.engine legend-engine-language-pure-compiler @@ -73,17 +69,6 @@ - - - io.swagger - swagger-annotations - - - javax.ws.rs - javax.ws.rs-api - - - org.eclipse.collections @@ -102,35 +87,6 @@ - - - io.opentracing - opentracing-util - - - io.opentracing - opentracing-api - - - - - - org.slf4j - slf4j-api - - - - - - org.pac4j.jax-rs - core - - - org.pac4j - pac4j-core - - - junit diff --git a/legend-engine-xts-morphir/legend-engine-xt-morphir/src/main/java/org/finos/legend/engine/external/language/morphir/MorphirGenerationService.java b/legend-engine-xts-morphir/legend-engine-xt-morphir/src/main/java/org/finos/legend/engine/external/language/morphir/MorphirGenerationService.java deleted file mode 100644 index 02f12e1f3b2..00000000000 --- a/legend-engine-xts-morphir/legend-engine-xt-morphir/src/main/java/org/finos/legend/engine/external/language/morphir/MorphirGenerationService.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2021 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.external.language.morphir; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.language.morphir.model.MorphirGenerationConfig; -import org.finos.legend.engine.external.language.morphir.model.MorphirGenerationInput; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput; -import org.finos.legend.pure.generated.core_external_language_morphir_transformation_integration; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Api(tags = "External - Generation - Code") -@Path("pure/v1/codeGeneration") -@Produces(MediaType.APPLICATION_JSON) -public class MorphirGenerationService -{ - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(MorphirGenerationService.class); - private final ModelManager modelManager; - - public MorphirGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @POST - @Path("morphir") - @ApiOperation(value = "Generates Morphir IR from PureModel") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateMorphirIR(MorphirGenerationInput generateMorphirIRInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateMorphirIRInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Morphir IR").startActive(true)) - { - return exec( - generateMorphirIRInput.config != null ? generateMorphirIRInput.config : new MorphirGenerationConfig(), - () -> this.modelManager.loadModelAndData(generateMorphirIRInput.model, generateMorphirIRInput.clientVersion, identity, null).getTwo(), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_ERROR : LoggingEventType.GENERATE_MORPHIR_ERROR, identity.getName()); - } - } - - private Response exec(MorphirGenerationConfig morphirGenerationConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_START : LoggingEventType.GENERATE_MORPHIR_START).toString()); - PureModel pureModel = pureModelFunc.value(); - RichIterable output = core_external_language_morphir_transformation_integration.Root_meta_external_language_morphir_generation_generateMorphirIRFromPureWithScope_MorphirConfig_1__GenerationOutput_MANY_(morphirGenerationConfig.process(pureModel), pureModel.getExecutionSupport()); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_STOP : LoggingEventType.GENERATE_MORPHIR_STOP).toString()); - return ManageConstantResult.manageResult(identity.getName(), output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList()); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_ERROR : LoggingEventType.GENERATE_MORPHIR_ERROR, identity.getName()); - } - } -} - diff --git a/legend-engine-xts-protobuf/legend-engine-xt-protobuf/pom.xml b/legend-engine-xts-protobuf/legend-engine-xt-protobuf/pom.xml index 02810b45394..ee2e484ba9c 100644 --- a/legend-engine-xts-protobuf/legend-engine-xt-protobuf/pom.xml +++ b/legend-engine-xts-protobuf/legend-engine-xt-protobuf/pom.xml @@ -119,10 +119,6 @@ org.finos.legend.engine legend-engine-protocol-pure - - org.finos.legend.engine - legend-engine-language-pure-modelManager - org.finos.legend.engine legend-engine-language-pure-compiler @@ -149,17 +145,6 @@ - - - io.swagger - swagger-annotations - - - javax.ws.rs - javax.ws.rs-api - - - com.fasterxml.jackson.core @@ -193,35 +178,6 @@ - - - io.opentracing - opentracing-util - - - io.opentracing - opentracing-api - - - - - - org.slf4j - slf4j-api - - - - - - org.pac4j.jax-rs - core - - - org.pac4j - pac4j-core - - - junit @@ -250,6 +206,16 @@ test-jar test + + org.finos.legend.engine + legend-engine-language-pure-modelManager + test + + + javax.ws.rs + javax.ws.rs-api + test + \ No newline at end of file diff --git a/legend-engine-xts-protobuf/legend-engine-xt-protobuf/src/main/java/org/finos/legend/engine/external/format/protobuf/deprecated/generation/ProtobufGenerationService.java b/legend-engine-xts-protobuf/legend-engine-xt-protobuf/src/main/java/org/finos/legend/engine/external/format/protobuf/deprecated/generation/ProtobufGenerationService.java deleted file mode 100644 index b9e87febeb5..00000000000 --- a/legend-engine-xts-protobuf/legend-engine-xt-protobuf/src/main/java/org/finos/legend/engine/external/format/protobuf/deprecated/generation/ProtobufGenerationService.java +++ /dev/null @@ -1,106 +0,0 @@ -// 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. - -package org.finos.legend.engine.external.format.protobuf.deprecated.generation; - -import io.opentracing.Scope; -import io.opentracing.util.GlobalTracer; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.eclipse.collections.api.block.function.Function0; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.external.format.protobuf.deprecated.generation.configuration.ProtobufGenerationConfig; -import org.finos.legend.engine.external.format.protobuf.deprecated.generation.configuration.ProtobufGenerationInput; -import org.finos.legend.engine.external.shared.format.generations.GenerationOutput; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.modelManager.ModelManager; -import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; -import org.finos.legend.engine.shared.core.api.result.ManageConstantResult; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.factory.IdentityFactoryProvider; -import org.finos.legend.engine.shared.core.kerberos.ProfileManagerHelper; -import org.finos.legend.engine.shared.core.operational.errorManagement.ExceptionTool; -import org.finos.legend.engine.shared.core.operational.logs.LogInfo; -import org.finos.legend.engine.shared.core.operational.logs.LoggingEventType; -import org.finos.legend.pure.generated.core_external_format_protobuf_deprecated; -import org.pac4j.core.profile.CommonProfile; -import org.pac4j.core.profile.ProfileManager; -import org.pac4j.jax.rs.annotations.Pac4JProfileManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import static org.finos.legend.engine.shared.core.operational.http.InflateInterceptor.APPLICATION_ZLIB; - -@Deprecated -@Api(tags = "Z - Deprecated - Generation - Schema") -@Path("pure/v1/schemaGeneration") -@Produces(MediaType.APPLICATION_JSON) -public class ProtobufGenerationService -{ - private static final Logger LOGGER = LoggerFactory.getLogger(ProtobufGenerationService.class); - private final ModelManager modelManager; - - public ProtobufGenerationService(ModelManager modelManager) - { - this.modelManager = modelManager; - } - - @Deprecated - @POST - @Path("protobuf") - @ApiOperation(value = "Generates Protobuf for a given class and transitive dependencies") - @Consumes({MediaType.APPLICATION_JSON, APPLICATION_ZLIB}) - public Response generateProtobuf(ProtobufGenerationInput generateProtobufInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager pm) - { - MutableList profiles = ProfileManagerHelper.extractProfiles(pm); - Identity identity = IdentityFactoryProvider.getInstance().makeIdentity(profiles); - boolean interactive = generateProtobufInput.model instanceof PureModelContextData; - try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Protobuf").startActive(true)) - { - return exec(generateProtobufInput.config != null ? generateProtobufInput.config : new ProtobufGenerationConfig(), - () -> this.modelManager.loadModelAndData(generateProtobufInput.model, generateProtobufInput.clientVersion, identity, null).getTwo(), - interactive, - identity); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_PROTOBUF_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_PROTOBUF_CODE_ERROR, identity.getName()); - } - } - - private Response exec(ProtobufGenerationConfig protobufConfig, Function0 pureModelFunc, boolean interactive, Identity identity) - { - try - { - long start = System.currentTimeMillis(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_PROTOBUF_CODE_INTERACTIVE_START : LoggingEventType.GENERATE_PROTOBUF_CODE_START).toString()); - PureModel pureModel = pureModelFunc.value(); - Object result = core_external_format_protobuf_deprecated.Root_meta_external_format_protobuf_deprecated_generation_internal_transform_ProtobufConfig_1__GenerationOutput_MANY_(protobufConfig.transformToPure(pureModel), pureModel.getExecutionSupport()).collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList(); - LOGGER.info(new LogInfo(identity.getName(), interactive ? LoggingEventType.GENERATE_PROTOBUF_CODE_INTERACTIVE_STOP : LoggingEventType.GENERATE_PROTOBUF_CODE_STOP, (double)System.currentTimeMillis() - start).toString()); - return ManageConstantResult.manageResult(identity.getName(), result); - } - catch (Exception ex) - { - return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_PROTOBUF_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_PROTOBUF_CODE_ERROR, identity.getName()); - } - } -}