Search in sources :

Example 1 with ProcessingContext

use of org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext in project legend-engine by finos.

the class ServiceTestGenerationHelper method generateJavaForAsserts.

// Java
public static String generateJavaForAsserts(List<TestContainer> asserts, Service service, PureModel pureModel, String packageName, String className) {
    CompileContext compileContext = pureModel.getContext(service);
    ProcessorSupport processorSupport = pureModel.getExecutionSupport().getProcessorSupport();
    ProcessorContext processorContext = new ProcessorContext(processorSupport, false);
    processorContext.setInLineAllLambda(true);
    return "package " + packageName + ";\n" + "\n" + "import org.eclipse.collections.api.RichIterable;\n" + "import org.eclipse.collections.api.list.ListIterable;\n" + "import org.eclipse.collections.impl.factory.Lists;\n" + "import org.eclipse.collections.api.map.MutableMap;\n" + "import org.eclipse.collections.impl.map.mutable.UnifiedMap;\n" + "import org.eclipse.collections.impl.factory.Maps;\n" + "import org.finos.legend.pure.generated.*;\n" + "import org.finos.legend.pure.m3.execution.ExecutionSupport;\n" + "import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.CompiledSupport;\n" + "import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.function.*;\n" + "import java.util.Map;" + "" + "public class " + className + "\n" + "{\n" + "    private static Map localLambdas = UnifiedMap.newMap();\n" + LazyIterate.collect(asserts, tc -> (InstanceValue) tc._assert.accept(new ValueSpecificationBuilder(compileContext, Lists.mutable.empty(), new ProcessingContext("")))).collect(vs -> ValueSpecificationProcessor.createFunctionForLambda(null, (CoreInstance) vs._values().getAny(), processorSupport, processorContext)).zipWithIndex().collect(tuple -> "    public static boolean " + getAssertMethodName(tuple.getTwo()) + "(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result _res, ExecutionSupport es)\n" + "    {\n" + "        return " + tuple.getOne() + ".value(_res, es);\n" + "    }\n").makeString("", "\n", "}");
}
Also used : DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) MutableList(org.eclipse.collections.api.list.MutableList) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) MediaType(javax.ws.rs.core.MediaType) RichIterable(org.eclipse.collections.api.RichIterable) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) ProcessingContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext) ServiceLoader(java.util.ServiceLoader) Iterate(org.eclipse.collections.impl.utility.Iterate) StandardCharsets(java.nio.charset.StandardCharsets) PackageableElementType(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) Base64(java.util.Base64) List(java.util.List) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) Lists(org.eclipse.collections.impl.factory.Lists) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) Optional(java.util.Optional) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) UrlStreamExternalSource(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource) Function(java.util.function.Function) ConnectionFactoryExtension(org.finos.legend.engine.protocol.pure.v1.extension.ConnectionFactoryExtension) HelperRuntimeBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder) Pair(org.eclipse.collections.api.tuple.Pair) TestDatabaseAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.TestDatabaseAuthenticationStrategy) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder) ListIterate(org.eclipse.collections.impl.utility.ListIterate) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) DataProtocolHandler(org.finos.legend.engine.shared.core.url.DataProtocolHandler) org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions(org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) ValueSpecificationProcessor(org.finos.legend.pure.runtime.java.compiled.generation.processors.valuespecification.ValueSpecificationProcessor) ProcessingContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Base64 (java.util.Base64)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ServiceLoader (java.util.ServiceLoader)1 Function (java.util.function.Function)1 MediaType (javax.ws.rs.core.MediaType)1 RichIterable (org.eclipse.collections.api.RichIterable)1 MutableList (org.eclipse.collections.api.list.MutableList)1 Pair (org.eclipse.collections.api.tuple.Pair)1 Lists (org.eclipse.collections.impl.factory.Lists)1 Tuples (org.eclipse.collections.impl.tuple.Tuples)1 Iterate (org.eclipse.collections.impl.utility.Iterate)1 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 CompileContext (org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext)1 HelperRuntimeBuilder (org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder)1