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);
}
});
}
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();
}
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;
}
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;
}
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);
}
Aggregations