Search in sources :

Example 1 with Binding

use of org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding 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 Binding

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

the class SchemaToModelGenerator method toPureModelContextData.

private PureModelContextData toPureModelContextData(Root_meta_external_shared_format_binding_Binding binding) {
    PureModelContextData.Builder builder = PureModelContextData.newBuilder().withSerializer(new Protocol("pure", pureVersion));
    Root_meta_pure_model_unit_ResolvedModelUnit resolved = core_pure_model_modelUnit.Root_meta_pure_model_unit_resolve_ModelUnit_1__ResolvedModelUnit_1_(binding._modelUnit(), pureModel.getExecutionSupport());
    LazyIterate.collect(resolved._packageableElements(), e -> {
        if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) {
            return transformClass((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) e);
        } else if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) {
            return transformAssociation((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) e);
        } else if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) {
            return transformEnumeration((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration<?>) e);
        } else {
            return null;
        }
    }).select(Objects::nonNull).forEach(builder::addElement);
    builder.addElement(transformBinding(binding));
    return builder.build();
}
Also used : Root_meta_pure_model_unit_ResolvedModelUnit(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ResolvedModelUnit) Protocol(org.finos.legend.engine.protocol.Protocol) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)

Example 3 with Binding

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

the class Generator method transformBinding.

protected Binding transformBinding(Root_meta_external_shared_format_binding_Binding binding) {
    ModelUnit modelUnit = new ModelUnit();
    modelUnit.packageableElementIncludes = binding._modelUnit()._packageableElementIncludes().collect(this::elementToPath).toList();
    modelUnit.packageableElementExcludes = binding._modelUnit()._packageableElementExcludes().collect(this::elementToPath).toList();
    Binding result = new Binding();
    result.name = binding._name();
    result._package = elementToPath(binding._package());
    result.schemaSet = elementToPath(binding._schemaSet());
    result.schemaId = binding._schemaId();
    result.contentType = binding._contentType();
    result.modelUnit = modelUnit;
    return result;
}
Also used : Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) ModelUnit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit)

Example 4 with Binding

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

the class RelationalParseTreeWalker method buildBindingTransformer.

private BindingTransformer buildBindingTransformer(RelationalParserGrammar.BindingTransformerContext ctx) {
    String binding = PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath() == null ? Collections.emptyList() : ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier());
    BindingTransformer bindingTransformer = new BindingTransformer();
    bindingTransformer.binding = binding;
    return bindingTransformer;
}
Also used : BindingTransformer(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.BindingTransformer)

Example 5 with Binding

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

the class TestModelToFlatDataGeneration method testSimpleCsv.

@Test
public void testSimpleCsv() {
    String modelCode = "Class test::gen::Data\n" + "{\n" + "  name        : String[1];\n" + "  employed    : Boolean[0..1];\n" + "  iq          : Integer[0..1];\n" + "  weightKg    : Float[0..1];\n" + "  heightM     : Decimal[1];\n" + "  dateOfBirth : StrictDate[1];\n" + "  timeOfDeath : DateTime[1];\n" + "}";
    PureModelContextData generated = generateSchema(modelCode, config("test::gen"));
    Binding binding = generated.getElementsOfType(Binding.class).stream().findFirst().get();
    Assert.assertEquals("test::gen::TestBinding", binding.getPath());
    Assert.assertEquals("test::gen::TestSchemaSet", binding.schemaSet);
    Assert.assertEquals(Collections.singletonList("test::gen::Data"), binding.modelUnit.packageableElementIncludes);
    ExternalFormatSchemaSet schemaSet = generated.getElementsOfType(ExternalFormatSchemaSet.class).stream().findFirst().get();
    String expectedDefiniiton = "section Data: DelimitedWithHeadings\n" + "{\n" + "  scope.untilEof;\n" + "  delimiter: ',';\n" + "\n" + "  Record\n" + "  {\n" + "    name: STRING;\n" + "    employed: BOOLEAN(optional);\n" + "    iq: INTEGER(optional);\n" + "    weightKg: DECIMAL(optional);\n" + "    heightM: DECIMAL;\n" + "    dateOfBirth: DATE;\n" + "    timeOfDeath: DATETIME;\n" + "  }\n" + "}";
    Assert.assertEquals(expectedDefiniiton, schemaSet.schemas.get(0).content);
}
Also used : Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) ExternalFormatSchemaSet(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) ModelToSchemaGenerationTest(org.finos.legend.engine.external.shared.format.model.test.ModelToSchemaGenerationTest) Test(org.junit.Test)

Aggregations

PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)12 Binding (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding)11 Test (org.junit.Test)10 ExternalFormatSchemaSet (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet)9 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)9 ModelToSchemaGenerationTest (org.finos.legend.engine.external.shared.format.model.test.ModelToSchemaGenerationTest)5 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)5 ListIterate (org.eclipse.collections.impl.utility.ListIterate)4 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)4 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)4 ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)3 ModelUnit (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit)3 Root_meta_external_shared_format_binding_validation_BindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Maps (org.eclipse.collections.api.factory.Maps)2 MutableMap (org.eclipse.collections.api.map.MutableMap)2 Processor (org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.Processor)2