Search in sources :

Example 1 with PackageableElementPointer

use of org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer in project legend-engine by finos.

the class ServiceTestGenerationHelper method buildRelationalTestRuntime.

private static Runtime buildRelationalTestRuntime(Runtime runtime, String mappingPath, String testDataCsv, List<String> sql) {
    if (runtime instanceof LegacyRuntime) {
        LegacyRuntime newRuntime = new LegacyRuntime();
        newRuntime.connections = ListIterate.collect(((LegacyRuntime) runtime).connections, c -> newRelationalConnection(c, testDataCsv, sql));
        return newRuntime;
    }
    if (runtime instanceof EngineRuntime) {
        EngineRuntime testRuntime = new EngineRuntime();
        PackageableElementPointer mappingPointer = new PackageableElementPointer();
        mappingPointer.type = PackageableElementType.MAPPING;
        mappingPointer.path = mappingPath;
        testRuntime.mappings.add(mappingPointer);
        testRuntime.connections = ListIterate.collect(((EngineRuntime) runtime).connections, c -> "ModelStore".equals(c.store.path) ? c : newRelationalStoreConnections(c, testDataCsv, sql));
        return testRuntime;
    }
    if (runtime instanceof RuntimePointer) {
        return runtime;
    }
    throw new UnsupportedOperationException("Unsupported runtime type: " + runtime.getClass().getName());
}
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) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)

Example 2 with PackageableElementPointer

use of org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer in project legend-engine by finos.

the class GenerationSpecificationParseTreeWalker method visitFileGeneration.

private PackageableElementPointer visitFileGeneration(GenerationSpecificationParserGrammar.QualifiedNameContext ctx) {
    PackageableElementPointer packageableElementPointer = new PackageableElementPointer();
    packageableElementPointer.type = PackageableElementType.FILE_GENERATION;
    packageableElementPointer.path = PureGrammarParserUtility.fromQualifiedName(ctx.packagePath() == null ? Collections.emptyList() : ctx.packagePath().identifier(), ctx.identifier());
    packageableElementPointer.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    return packageableElementPointer;
}
Also used : PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)

Example 3 with PackageableElementPointer

use of org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer in project legend-engine by finos.

the class DataSpaceParseTreeWalker method visitDataSpaceExecutionContext.

private DataSpaceExecutionContext visitDataSpaceExecutionContext(DataSpaceParserGrammar.ExecutionContextContext ctx, SourceInformation dataSpaceSourceInformation) {
    DataSpaceExecutionContext executionContext = new DataSpaceExecutionContext();
    // Name
    DataSpaceParserGrammar.ExecutionContextNameContext executionContextNameContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.executionContextName(), "name", dataSpaceSourceInformation);
    executionContext.name = PureGrammarParserUtility.fromGrammarString(executionContextNameContext.STRING().getText(), true);
    // Description (optional)
    DataSpaceParserGrammar.DescriptionContext descriptionContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.description(), "description", dataSpaceSourceInformation);
    executionContext.description = descriptionContext != null ? PureGrammarParserUtility.fromGrammarString(descriptionContext.STRING().getText(), true) : null;
    // Mapping
    DataSpaceParserGrammar.MappingContext mappingContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.mapping(), "mapping", dataSpaceSourceInformation);
    executionContext.mapping = new PackageableElementPointer(PackageableElementType.MAPPING, PureGrammarParserUtility.fromQualifiedName(mappingContext.qualifiedName().packagePath() == null ? Collections.emptyList() : mappingContext.qualifiedName().packagePath().identifier(), mappingContext.qualifiedName().identifier()));
    executionContext.mapping.sourceInformation = walkerSourceInformation.getSourceInformation(mappingContext);
    // Runtime
    DataSpaceParserGrammar.DefaultRuntimeContext defaultRuntimeContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.defaultRuntime(), "defaultRuntime", dataSpaceSourceInformation);
    executionContext.defaultRuntime = new PackageableElementPointer(PackageableElementType.RUNTIME, PureGrammarParserUtility.fromQualifiedName(defaultRuntimeContext.qualifiedName().packagePath() == null ? Collections.emptyList() : defaultRuntimeContext.qualifiedName().packagePath().identifier(), defaultRuntimeContext.qualifiedName().identifier()));
    executionContext.defaultRuntime.sourceInformation = walkerSourceInformation.getSourceInformation(defaultRuntimeContext);
    return executionContext;
}
Also used : DataSpaceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceParserGrammar) DataSpaceExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpaceExecutionContext) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)

Example 4 with PackageableElementPointer

use of org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer in project legend-engine by finos.

the class DataSpaceParseTreeWalker method visitDataSpace.

private DataSpace visitDataSpace(DataSpaceParserGrammar.DataSpaceElementContext ctx) {
    DataSpace dataSpace = new DataSpace();
    dataSpace.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
    dataSpace._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
    dataSpace.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    dataSpace.stereotypes = ctx.stereotypes() == null ? Lists.mutable.empty() : this.visitStereotypes(ctx.stereotypes());
    dataSpace.taggedValues = ctx.taggedValues() == null ? Lists.mutable.empty() : this.visitTaggedValues(ctx.taggedValues());
    // Group ID
    DataSpaceParserGrammar.GroupIdContext groupIdContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.groupId(), "groupId", dataSpace.sourceInformation);
    dataSpace.groupId = PureGrammarParserUtility.fromGrammarString(groupIdContext.STRING().getText(), true);
    // Artifact ID
    DataSpaceParserGrammar.ArtifactIdContext artifactIdContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.artifactId(), "artifactId", dataSpace.sourceInformation);
    dataSpace.artifactId = PureGrammarParserUtility.fromGrammarString(artifactIdContext.STRING().getText(), true);
    // Version ID
    DataSpaceParserGrammar.VersionIdContext versionIdContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.versionId(), "versionId", dataSpace.sourceInformation);
    dataSpace.versionId = PureGrammarParserUtility.fromGrammarString(versionIdContext.STRING().getText(), true);
    // Execution contexts
    DataSpaceParserGrammar.ExecutionContextsContext executionContextsContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.executionContexts(), "executionContexts", dataSpace.sourceInformation);
    dataSpace.executionContexts = ListIterate.collect(executionContextsContext.executionContext(), executionContext -> this.visitDataSpaceExecutionContext(executionContext, dataSpace.sourceInformation));
    // Default execution context
    DataSpaceParserGrammar.DefaultExecutionContextContext defaultExecutionContextContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.defaultExecutionContext(), "defaultExecutionContext", dataSpace.sourceInformation);
    dataSpace.defaultExecutionContext = PureGrammarParserUtility.fromGrammarString(defaultExecutionContextContext.STRING().getText(), true);
    // Description (optional)
    DataSpaceParserGrammar.DescriptionContext descriptionContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.description(), "description", dataSpace.sourceInformation);
    dataSpace.description = descriptionContext != null ? PureGrammarParserUtility.fromGrammarString(descriptionContext.STRING().getText(), true) : null;
    // Featured diagrams (optional)
    DataSpaceParserGrammar.FeaturedDiagramsContext featuredDiagramsContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.featuredDiagrams(), "featuredDiagrams", dataSpace.sourceInformation);
    dataSpace.featuredDiagrams = featuredDiagramsContext != null ? ListIterate.collect(featuredDiagramsContext.qualifiedName(), diagramPathContext -> {
        PackageableElementPointer pointer = new PackageableElementPointer(PackageableElementType.DIAGRAM, PureGrammarParserUtility.fromQualifiedName(diagramPathContext.packagePath() == null ? Collections.emptyList() : diagramPathContext.packagePath().identifier(), diagramPathContext.identifier()));
        pointer.sourceInformation = walkerSourceInformation.getSourceInformation(diagramPathContext);
        return pointer;
    }) : null;
    // Support info (optional)
    DataSpaceParserGrammar.SupportInfoContext supportInfoContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.supportInfo(), "supportInfo", dataSpace.sourceInformation);
    dataSpace.supportInfo = supportInfoContext != null ? this.visitDataSpaceSupportInfo(supportInfoContext, dataSpace.sourceInformation) : null;
    return dataSpace;
}
Also used : PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) DataSpaceSupportEmail(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpaceSupportEmail) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) TaggedValue(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.TaggedValue) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) DataSpaceExecutionContext(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpaceExecutionContext) Consumer(java.util.function.Consumer) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) PackageableElementType(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType) List(java.util.List) Lists(org.eclipse.collections.impl.factory.Lists) DataSpaceSupportInfo(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpaceSupportInfo) PureGrammarParserUtility(org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility) StereotypePtr(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.StereotypePtr) DataSpace(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpace) Collections(java.util.Collections) DataSpaceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceParserGrammar) TagPtr(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.TagPtr) DefaultCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection) DataSpace(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.dataSpace.DataSpace) DataSpaceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceParserGrammar) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)

Example 5 with PackageableElementPointer

use of org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer in project legend-engine by finos.

the class LegacyRuntime method toEngineRuntime.

@JsonIgnore
public EngineRuntime toEngineRuntime() {
    EngineRuntime engineRuntime = new EngineRuntime();
    AtomicInteger counter = new AtomicInteger(1);
    engineRuntime.mappings = this.mappings;
    ListIterate.forEach(this.connections, connection -> {
        IdentifiedConnection identifiedConnection = new IdentifiedConnection();
        // adhoc connection id creation
        identifiedConnection.id = "connection_" + counter;
        identifiedConnection.connection = connection;
        counter.getAndIncrement();
        // find the current connections by store and update
        if (engineRuntime.getStoreConnections(connection.element) != null) {
            engineRuntime.getStoreConnections(connection.element).storeConnections.add(identifiedConnection);
        } else {
            StoreConnections storeConnections = new StoreConnections();
            storeConnections.storeConnections.add(identifiedConnection);
            PackageableElementPointer storePointer = new PackageableElementPointer();
            storePointer.type = PackageableElementType.STORE;
            storePointer.path = connection.element;
            storeConnections.store = storePointer;
            engineRuntime.connections.add(storeConnections);
        }
    });
    return engineRuntime;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Aggregations

PackageableElementPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)12 ListIterate (org.eclipse.collections.impl.utility.ListIterate)5 PackageableElementType (org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType)5 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)5 ConnectionPointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer)5 EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)5 IdentifiedConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)5 StoreConnections (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections)5 List (java.util.List)4 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)4 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)4 PackageableRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Consumer (java.util.function.Consumer)3 Lists (org.eclipse.collections.impl.factory.Lists)3 PureGrammarParserUtility (org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 StandardCharsets (java.nio.charset.StandardCharsets)2