Search in sources :

Example 1 with InputData

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.

the class MappingTestRunner method buildTestConnection.

private void buildTestConnection(Consumer<? super Connection> connectionRegistrar) {
    if (this.mappingTest.inputData.size() != 1) {
        throw new RuntimeException("Only tests with one input data set are currently supported; " + mappingTest.inputData.size() + " supplied");
    }
    InputData input = this.mappingTest.inputData.get(0);
    if (input instanceof ObjectInputData) {
        ObjectInputData objectInputData = ((ObjectInputData) input);
        if (ObjectInputType.JSON.equals(objectInputData.inputType)) {
            JsonModelConnection jsonModelConnection = new JsonModelConnection();
            jsonModelConnection._class = objectInputData.sourceClass;
            jsonModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(objectInputData.data.getBytes(StandardCharsets.UTF_8));
            connectionRegistrar.accept(jsonModelConnection);
        } else if (ObjectInputType.XML.equals(objectInputData.inputType)) {
            XmlModelConnection xmlModelConnection = new XmlModelConnection();
            xmlModelConnection._class = objectInputData.sourceClass;
            xmlModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(objectInputData.data.getBytes(StandardCharsets.UTF_8));
            connectionRegistrar.accept(xmlModelConnection);
        } else {
            throw new UnsupportedOperationException("Unsupported Pure mapping test input data type '" + objectInputData.inputType + '"');
        }
    } else {
        connectionRegistrar.accept(getTestConnectionFromFactories(input));
    }
}
Also used : ObjectInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.ObjectInputData) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) InputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData) ObjectInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.ObjectInputData)

Example 2 with InputData

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.

the class RelationalConnectionFactory method tryBuildFromInputData.

@Override
public Optional<Connection> tryBuildFromInputData(InputData inputData) {
    if (inputData instanceof RelationalInputData) {
        RelationalInputData relationalInputData = (RelationalInputData) inputData;
        RelationalDatabaseConnection connection = new RelationalDatabaseConnection();
        connection.databaseType = DatabaseType.H2;
        connection.type = DatabaseType.H2;
        connection.element = relationalInputData.database;
        connection.authenticationStrategy = new TestDatabaseAuthenticationStrategy();
        LocalH2DatasourceSpecification localH2DatasourceSpecification = new LocalH2DatasourceSpecification();
        if (relationalInputData.inputType == RelationalInputType.SQL) {
            localH2DatasourceSpecification.testDataSetupSqls = Lists.mutable.of(relationalInputData.data.split("(?<!\\\\);")).collect(r -> r.replace("\\;", ";") + ";");
        } else if (relationalInputData.inputType == RelationalInputType.CSV) {
            localH2DatasourceSpecification.testDataSetupCsv = relationalInputData.data;
        } else {
            throw new RuntimeException(relationalInputData.inputType + " is not supported");
        }
        connection.datasourceSpecification = localH2DatasourceSpecification;
        return Optional.of(connection);
    }
    return Optional.empty();
}
Also used : InputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) ConnectionFactoryExtension(org.finos.legend.engine.protocol.pure.v1.extension.ConnectionFactoryExtension) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) TestDatabaseAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.TestDatabaseAuthenticationStrategy) Lists(org.eclipse.collections.api.factory.Lists) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) Optional(java.util.Optional) RelationalInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputData) RelationalInputType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputType) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) RelationalInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputData) TestDatabaseAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.TestDatabaseAuthenticationStrategy) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification)

Example 3 with InputData

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.

the class RelationalGrammarComposerExtension method getExtraMappingTestInputDataComposers.

@Override
public List<Function2<InputData, PureGrammarComposerContext, String>> getExtraMappingTestInputDataComposers() {
    return Lists.mutable.with((inputData, context) -> {
        if (inputData instanceof RelationalInputData) {
            RelationalInputData relationalInputData = (RelationalInputData) inputData;
            String data;
            if (relationalInputData.inputType == RelationalInputType.SQL) {
                MutableList<String> lines = org.eclipse.collections.api.factory.Lists.mutable.of(relationalInputData.data.replace("\r", "").replace("\n", "").split("(?<!\\\\);"));
                data = "\n" + lines.collect(l -> getTabString(5) + convertString(l + ";\n", true).replace("\\\\;", "\\;")).makeString("+\n");
            } else if (relationalInputData.inputType == RelationalInputType.CSV) {
                MutableList<String> lines = org.eclipse.collections.api.factory.Lists.mutable.of(relationalInputData.data.split("\\n"));
                lines.add("\n\n");
                data = "\n" + lines.collect(l -> getTabString(5) + convertString(l + "\n", true)).makeString("+\n");
            } else {
                data = relationalInputData.data;
            }
            return "<Relational, " + relationalInputData.inputType + ", " + relationalInputData.database + ", " + data + "\n" + getTabString(4) + ">";
        }
        return null;
    });
}
Also used : InputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData) Milestoning(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.milestoning.Milestoning) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) AuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.AuthenticationStrategy) Schema(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema) AssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.AssociationMapping) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) RelationalOperationElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.RelationalOperationElement) PureGrammarComposerUtility(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility) DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.DatasourceSpecification) RootRelationalClassMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RootRelationalClassMapping) Function3(org.eclipse.collections.api.block.function.Function3) Function2(org.eclipse.collections.api.block.function.Function2) RelationalGrammarParserExtension(org.finos.legend.engine.language.pure.grammar.from.RelationalGrammarParserExtension) RelationalAssociationMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.RelationalAssociationMapping) TablePtr(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.TablePtr) Database(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Database) Tuples(org.eclipse.collections.impl.tuple.Tuples) RelationalInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputData) Pair(org.eclipse.collections.api.tuple.Pair) PostProcessor(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.postprocessor.PostProcessor) ListIterate(org.eclipse.collections.impl.utility.ListIterate) RelationalInputType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputType) PureGrammarComposerExtension(org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) List(java.util.List) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) ClassMapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.ClassMapping) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) Lists(org.eclipse.collections.impl.factory.Lists) MapperPostProcessor(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.postprocessor.MapperPostProcessor) MutableList(org.eclipse.collections.api.list.MutableList) RelationalInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputData)

Example 4 with InputData

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.

the class HelperMappingBuilder method processMappingTestInputData.

public static void processMappingTestInputData(InputData inputData, CompileContext context) {
    if (inputData instanceof ObjectInputData) {
        ObjectInputData objectInputData = (ObjectInputData) inputData;
        if (objectInputData.inputType == null) {
            throw new EngineException("Object input data does not have a format type", objectInputData.sourceInformation, EngineErrorType.COMPILATION);
        }
        context.resolveClass(objectInputData.sourceClass, objectInputData.sourceInformation);
    } else {
        context.getCompilerExtensions().getExtraMappingTestInputDataProcessors().forEach(processor -> processor.value(inputData, context));
    }
}
Also used : ObjectInputData(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.ObjectInputData) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)

Example 5 with InputData

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData in project legend-engine by finos.

the class MappingParseTreeWalker method visitMappingTestInputData.

private InputData visitMappingTestInputData(MappingParserGrammar.TestInputElementContext ctx) {
    SourceInformation testInputDataSourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    String inputDataType = ctx.testInputType().getText();
    MappingTestInputDataParser mappingTestInputDataParser = this.extensions.getExtraMappingTestInputDataParser(inputDataType);
    if (mappingTestInputDataParser == null) {
        throw new EngineException("Unsupported mapping test input data type '" + inputDataType + "'", testInputDataSourceInformation, EngineErrorType.PARSER);
    }
    return mappingTestInputDataParser.parse(ctx, this.walkerSourceInformation);
}
Also used : MappingTestInputDataParser(org.finos.legend.engine.language.pure.grammar.from.extension.MappingTestInputDataParser) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)

Aggregations

EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)4 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)3 InputData (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.InputData)3 ObjectInputData (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.mapping.ObjectInputData)3 RelationalInputData (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputData)3 Connection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection)2 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)2 RelationalInputType (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.mapping.mappingTest.RelationalInputType)2 List (java.util.List)1 Optional (java.util.Optional)1 Function2 (org.eclipse.collections.api.block.function.Function2)1 Function3 (org.eclipse.collections.api.block.function.Function3)1 Lists (org.eclipse.collections.api.factory.Lists)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 FastList (org.eclipse.collections.impl.list.mutable.FastList)1 Tuples (org.eclipse.collections.impl.tuple.Tuples)1 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1