Search in sources :

Example 1 with ExternalFormatConnection

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection in project legend-engine by finos.

the class ExternalFormatConnectionCompilerExtension method getExtraConnectionSecondPassProcessors.

@Override
public List<Procedure3<Connection, org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Connection, CompileContext>> getExtraConnectionSecondPassProcessors() {
    return Collections.singletonList((connectionValue, pureConnection, context) -> {
        if (connectionValue instanceof ExternalFormatConnection) {
            ExternalFormatConnection externalFormatConnection = (ExternalFormatConnection) connectionValue;
            List<IExternalFormatCompilerExtension> extensions = IExternalFormatCompilerExtension.getExtensions(context);
            Root_meta_external_shared_format_executionPlan_ExternalFormatConnection connection = (Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) pureConnection;
            Store store = context.pureModel.getStore(connectionValue.element, connectionValue.elementSourceInformation);
            if (!(store instanceof Root_meta_external_shared_format_binding_Binding)) {
                throw new EngineException("Store for ExternalFormatConnection must be a Binding", connectionValue.sourceInformation, EngineErrorType.COMPILATION);
            }
            connection._element(store);
            Root_meta_external_shared_format_executionPlan_ExternalSource externalSource = IExternalFormatCompilerExtension.process(externalFormatConnection.externalSource, ListIterate.flatCollect(extensions, IExternalFormatCompilerExtension::getExtraExternalSourceSpecificationProcessors), context);
            connection._externalSource(externalSource);
        }
    });
}
Also used : Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Root_meta_external_shared_format_executionPlan_ExternalFormatConnection(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_external_shared_format_executionPlan_ExternalSource(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalSource) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) Root_meta_external_shared_format_executionPlan_ExternalFormatConnection(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection)

Example 2 with ExternalFormatConnection

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection in project legend-engine by finos.

the class TestExternalFormatConnectionCompilation method testPackageableExternalFormatConnection.

@Test
public void testPackageableExternalFormatConnection() {
    Pair<PureModelContextData, PureModel> compiledGraph = test("###Pure\n" + "Class meta::firm::Person\n" + "{\n" + "  fullName: String[1];\n" + "}\n" + "\n" + "###ExternalFormat\n" + "SchemaSet meta::firm::SchemaSet\n" + "{\n" + "  format: Example;\n" + "  schemas: [ { content: 'example'; } ];\n" + "}\n" + "\n" + "Binding meta::firm::Binding\n" + "{\n" + "  schemaSet: meta::firm::SchemaSet;\n" + "  contentType: 'text/example';\n" + "  modelIncludes: [\n" + "    meta::firm::Person\n" + "  ];\n" + "}\n" + "\n" + "###Connection\n" + "ExternalFormatConnection simple::Connection\n" + "{\n" + "  store: meta::firm::Binding;\n" + "  source: UrlStream\n" + "  {\n" + "    url: 'executor:default';\n" + "  };\n" + "}\n");
    Root_meta_external_shared_format_executionPlan_ExternalFormatConnection connection = (Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) compiledGraph.getTwo().getConnection("simple::Connection", SourceInformation.getUnknownSourceInformation());
    Assert.assertTrue(connection._externalSource() instanceof Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource);
    Assert.assertEquals("executor:default", ((Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource) connection._externalSource())._url());
}
Also used : Root_meta_external_shared_format_executionPlan_ExternalFormatConnection(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 3 with ExternalFormatConnection

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection in project legend-engine by finos.

the class ServiceTestGenerationHelper method getNullableTestConnection.

private static Optional<Connection> getNullableTestConnection(Connection connection, Runtime parentRuntime, String mappingPath, Pair<PureModelContextData, PureModel> pureModelPairs, StoreConnections parentStoreConnection, Function<String, String> testDataAccessor, String testData, String idTestDataAccessorResult) {
    if (connection instanceof ConnectionPointer) {
        String connectionFullPath = ((ConnectionPointer) connection).connection;
        PackageableElement found = Iterate.detect(pureModelPairs.getOne().getElements(), e -> connectionFullPath.equals(e.getPath()));
        if (!(found instanceof PackageableConnection)) {
            throw new RuntimeException("Can't find connection '" + connectionFullPath + "'");
        }
        connection = ((PackageableConnection) found).connectionValue;
    }
    if (connection instanceof JsonModelConnection) {
        JsonModelConnection conn = (JsonModelConnection) connection;
        JsonModelConnection testJsonModelConnection = new JsonModelConnection();
        testJsonModelConnection._class = conn._class;
        testJsonModelConnection.element = conn.element != null ? conn.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
        String executorId = conn.url.split(":")[1];
        String connectionTestData = resolveTestData(executorId, idTestDataAccessorResult, testDataAccessor, testData);
        if (idTestDataAccessorResult != null) {
            ((JsonModelConnection) connection).url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
        }
        testJsonModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_JSON + ";base64," + Base64.getEncoder().encodeToString(connectionTestData.getBytes(StandardCharsets.UTF_8));
        return Optional.of(conn);
    }
    if (connection instanceof XmlModelConnection) {
        XmlModelConnection conn = (XmlModelConnection) connection;
        XmlModelConnection testXmlModelConnection = new XmlModelConnection();
        testXmlModelConnection._class = conn._class;
        testXmlModelConnection.element = conn.element != null ? conn.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
        String executorId = conn.url.split(":")[1];
        String connectionTestData = resolveTestData(executorId, idTestDataAccessorResult, testDataAccessor, testData);
        if (idTestDataAccessorResult != null) {
            ((XmlModelConnection) connection).url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
        }
        testXmlModelConnection.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(connectionTestData.getBytes(StandardCharsets.UTF_8));
        return Optional.of(testXmlModelConnection);
    }
    if (connection instanceof ExternalFormatConnection) {
        ExternalFormatConnection conn = (ExternalFormatConnection) connection;
        ExternalFormatConnection testConn = new ExternalFormatConnection();
        testConn.element = conn.element;
        UrlStreamExternalSource source = new UrlStreamExternalSource();
        source.url = DataProtocolHandler.DATA_PROTOCOL_NAME + ":" + MediaType.APPLICATION_XML + ";base64," + Base64.getEncoder().encodeToString(idTestDataAccessorResult.getBytes(StandardCharsets.UTF_8));
        testConn.externalSource = source;
        return Optional.of(testConn);
    }
    if (connection instanceof ModelChainConnection) {
        return Optional.of(connection);
    }
    if (connection instanceof DatabaseConnection) {
        List<String> sql = getSql(parentRuntime, mappingPath, idTestDataAccessorResult, pureModelPairs.getTwo());
        return Optional.of(newRelationalConnection(connection, idTestDataAccessorResult, sql));
    }
    String element = connection.element != null ? connection.element : (parentStoreConnection.store != null ? parentStoreConnection.store.path : null);
    Connection testConnectionFromFactories = getTestConnectionFromFactories(connection, idTestDataAccessorResult == null ? testData : idTestDataAccessorResult, element);
    return testConnectionFromFactories != null ? Optional.of(testConnectionFromFactories) : Optional.empty();
}
Also used : JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) UrlStreamExternalSource(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection)

Example 4 with ExternalFormatConnection

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection in project legend-engine by finos.

the class TestExternalFormatConnectionCompilation method testExternalFormatConnectionInPackageableRuntime.

@Test
public void testExternalFormatConnectionInPackageableRuntime() {
    Pair<PureModelContextData, PureModel> compiledGraph = test("###Pure\n" + "Class meta::firm::Person\n" + "{\n" + "  fullName: String[1];\n" + "}\n" + "\n" + "###ExternalFormat\n" + "SchemaSet meta::firm::SchemaSet\n" + "{\n" + "  format: Example;\n" + "  schemas: [ { content: 'example'; } ];\n" + "}\n" + "\n" + "Binding meta::firm::Binding\n" + "{\n" + "  schemaSet: meta::firm::SchemaSet;\n" + "  contentType: 'text/example';\n" + "  modelIncludes: [\n" + "    meta::firm::Person\n" + "  ];\n" + "}\n" + "\n" + "###Mapping\n" + "Mapping test::Mapping\n" + "(\n" + "  meta::firm::Person: Pure\n" + "  {\n" + "    ~src meta::firm::Person\n" + "    fullName: $src.fullName\n" + "  }\n" + ")\n" + "###Runtime\n" + "Runtime test::runtime\n" + "{\n" + "  mappings:\n" + "  [\n" + "    test::Mapping\n" + "  ];\n" + "  connections:\n" + "  [\n" + "    meta::firm::Binding:\n" + "    [\n" + "      c1:\n" + "      #{\n" + "        ExternalFormatConnection\n" + "        {\n" + "          source: UrlStream\n" + "          {\n" + "            url: 'executor:default';\n" + "          };\n" + "        }\n" + "      }#\n" + "    ]\n" + "  ];\n" + "}\n");
    Runtime runtime = compiledGraph.getTwo().getRuntime("test::runtime");
    Root_meta_external_shared_format_executionPlan_ExternalFormatConnection connection = (Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) runtime._connections().toList().get(0);
    Assert.assertTrue(connection._externalSource() instanceof Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource);
    Assert.assertEquals("executor:default", ((Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource) connection._externalSource())._url());
}
Also used : Runtime(org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime) Root_meta_external_shared_format_executionPlan_ExternalFormatConnection(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalFormatConnection) Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource(org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Aggregations

Root_meta_external_shared_format_executionPlan_ExternalFormatConnection (org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalFormatConnection)3 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)2 ExternalFormatConnection (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection)2 Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource (org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_UrlStreamExternalSource)2 Test (org.junit.Test)2 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)1 Connection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection)1 ConnectionPointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer)1 PackageableConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection)1 IdentifiedConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)1 JsonModelConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection)1 ModelChainConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection)1 XmlModelConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection)1 DatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection)1 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)1 UrlStreamExternalSource (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource)1 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)1 Root_meta_external_shared_format_executionPlan_ExternalSource (org.finos.legend.pure.generated.Root_meta_external_shared_format_executionPlan_ExternalSource)1