Search in sources :

Example 1 with ModelUnit

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit 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 2 with ModelUnit

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit in project legend-engine by finos.

the class HelperRelationalBuilder method buildSemiStructuredPropertyMapping.

private static PropertyMapping buildSemiStructuredPropertyMapping(Property<?, ?> property, RelationalPropertyMapping propertyMapping, PropertyMappingsImplementation parent, RootRelationalInstanceSetImplementation topParent, MutableList<EmbeddedRelationalInstanceSetImplementation> embeddedRelationalPropertyMappings, MutableMap<String, TableAlias> aliasMap, CompileContext context) {
    Root_meta_external_shared_format_binding_Binding binding = HelperExternalFormat.getBinding(propertyMapping.bindingTransformer.binding, context);
    Type propertyType = property._genericType()._rawType();
    if (!"Class".equals(propertyType._classifierGenericType()._rawType()._name())) {
        throw new EngineException("Binding transformer can be used with complex properties only. Property '" + property._name() + "' return type is '" + propertyType._name() + "'", propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
    if (!core_pure_model_modelUnit.Root_meta_pure_model_unit_resolve_ModelUnit_1__ResolvedModelUnit_1_(binding._modelUnit(), context.getExecutionSupport()).classes(context.getExecutionSupport()).contains(propertyType)) {
        throw new EngineException("Class: " + platform_pure_corefunctions_meta.Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1_(propertyType, context.getExecutionSupport()) + " should be included in modelUnit for binding: " + propertyMapping.bindingTransformer.binding, propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
    ExternalFormatExtension<?, ?, ?> schemaExtension = HelperExternalFormat.getExternalFormatExtension(binding);
    Root_meta_external_shared_format_binding_validation_BindingDetail bindingDetail = schemaExtension.bindDetails(binding, context);
    if (bindingDetail instanceof Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) {
        RelationalOperationElement relationalOperationElement = processRelationalOperationElement(propertyMapping.relationalOperation, context, aliasMap, FastList.newList());
        Root_meta_external_shared_format_binding_BindingTransformer<?> bindingTransformer = new Root_meta_external_shared_format_binding_BindingTransformer_Impl<>("")._binding(binding)._class((Class<?>) propertyType);
        return buildSemiStructuredEmbeddedPropertyMapping(binding, (Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) bindingDetail, property, (Class<?>) propertyType, relationalOperationElement, parent, topParent, embeddedRelationalPropertyMappings, true, bindingTransformer, context);
    } else {
        throw new EngineException("External format content type: '" + binding._contentType() + "' not yet supported", propertyMapping.sourceInformation, EngineErrorType.COMPILATION);
    }
}
Also used : Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) DataType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.DataType) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_SuccessfulBindingDetail) Root_meta_external_shared_format_binding_BindingTransformer_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_BindingTransformer_Impl) RelationalOperationElement(org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.RelationalOperationElement) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_external_shared_format_binding_validation_BindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)

Example 3 with ModelUnit

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit in project legend-engine by finos.

the class ExternalFormatParseTreeWalker method visitBinding.

private Binding visitBinding(ExternalFormatParserGrammar.BindingContext ctx) {
    SourceInformation sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    Binding binding = new Binding();
    binding.sourceInformation = sourceInformation;
    binding.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
    binding._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
    // schemaSet
    ExternalFormatParserGrammar.SchemaSetReferenceContext schemaSetReferenceContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.schemaSetReference(), "schemaSet", sourceInformation);
    binding.schemaSet = schemaSetReferenceContext == null ? null : processQualifiedName(schemaSetReferenceContext.qualifiedName());
    // schemaId
    ExternalFormatParserGrammar.SchemaIdReferenceContext schemaIdReferenceContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.schemaIdReference(), "schemaId", sourceInformation);
    binding.schemaId = schemaIdReferenceContext == null ? null : PureGrammarParserUtility.fromIdentifier(schemaIdReferenceContext.identifier());
    // contentType
    ExternalFormatParserGrammar.ContentTypeContext contentTypeContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.contentType(), "contentType", sourceInformation);
    binding.contentType = PureGrammarParserUtility.fromGrammarString(contentTypeContext.STRING().getText(), true);
    // modelIncludes & modelExcludes
    ExternalFormatParserGrammar.ModelIncludesContext modelIncludesContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.modelIncludes(), "modelIncludes", sourceInformation);
    ExternalFormatParserGrammar.ModelExcludesContext modelExcludesContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.modelExcludes(), "modelExcludes", sourceInformation);
    ModelUnit modelUnit = new ModelUnit();
    modelUnit.packageableElementIncludes = modelIncludesContext.qualifiedName().stream().map(this::processQualifiedName).collect(Collectors.toList());
    if (modelExcludesContext != null) {
        modelUnit.packageableElementExcludes = modelExcludesContext.qualifiedName().stream().map(this::processQualifiedName).collect(Collectors.toList());
    }
    binding.modelUnit = modelUnit;
    return binding;
}
Also used : Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) ExternalFormatParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.ExternalFormatParserGrammar) ModelUnit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)

Example 4 with ModelUnit

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit in project legend-engine by finos.

the class TestExternalFormatGrammarComposer method testFreeSectionGrammarCompose.

@Test
public void testFreeSectionGrammarCompose() {
    ExternalFormatSchema one = new ExternalFormatSchema();
    one.id = "one";
    one.location = "first.place";
    one.content = "Example one";
    ExternalFormatSchema two = new ExternalFormatSchema();
    two.id = "two";
    two.location = "second.place";
    two.content = "Example two";
    ExternalFormatSchemaSet set = new ExternalFormatSchemaSet();
    set._package = "test.grammar";
    set.name = "ExampleSet";
    set.format = "Example";
    set.schemas = Arrays.asList(one, two);
    ModelUnit modelUnit = new ModelUnit();
    modelUnit.packageableElementIncludes = Collections.singletonList("test.grammar.AClass");
    Binding binding = new Binding();
    binding._package = "test.grammar";
    binding.name = "ExampleBinding";
    binding.contentType = "test/example";
    binding.schemaSet = "test.grammar.ExampleSet";
    binding.schemaId = "one";
    binding.modelUnit = modelUnit;
    PureModelContextData context = PureModelContextData.newBuilder().withElement(set).withElement(binding).build();
    PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
    String formatted = grammarTransformer.renderPureModelContextData(context);
    String expected = "###ExternalFormat\n" + "SchemaSet 'test.grammar'::ExampleSet\n" + "{\n" + "  format: Example;\n" + "  schemas: [\n" + "    {\n" + "      id: one;\n" + "      location: 'first.place';\n" + "      content: 'Example one';\n" + "    },\n" + "    {\n" + "      id: two;\n" + "      location: 'second.place';\n" + "      content: 'Example two';\n" + "    }\n" + "  ];\n" + "}\n" + "\n" + "Binding 'test.grammar'::ExampleBinding\n" + "{\n" + "  schemaSet: 'test.grammar.ExampleSet';\n" + "  schemaId: one;\n" + "  contentType: 'test/example';\n" + "  modelIncludes: [\n" + "    'test.grammar.AClass'\n" + "  ];\n" + "}\n";
    Assert.assertEquals(expected, formatted);
}
Also used : Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) ExternalFormatSchema(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema) ModelUnit(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit) ExternalFormatSchemaSet(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) PureGrammarComposer(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer) Test(org.junit.Test)

Example 5 with ModelUnit

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit in project legend-engine by finos.

the class BindingCompiler method secondPass.

// Second pass - resolve schemas and model elements
private void secondPass(Binding srcBinding, CompileContext context) {
    String path = context.pureModel.buildPackageString(srcBinding._package, srcBinding.name);
    Root_meta_external_shared_format_binding_Binding compiled = bindingIndex.get(path);
    compiled._contentType(srcBinding.contentType);
    if (srcBinding.schemaSet != null) {
        Root_meta_external_shared_format_metamodel_SchemaSet schemaSet = HelperExternalFormat.getSchemaSet(srcBinding.schemaSet, srcBinding.sourceInformation, context);
        if (srcBinding.schemaId != null && schemaSet._schemas().noneSatisfy(s -> srcBinding.schemaId.equals(s._id()))) {
            throw new EngineException("ID '" + srcBinding.schemaId + "' does not exist in SchemaSet '" + srcBinding.schemaSet + "'", srcBinding.sourceInformation, EngineErrorType.COMPILATION);
        }
        compiled._schemaSet(schemaSet)._schemaId(srcBinding.schemaId);
    }
    Root_meta_pure_model_unit_ModelUnit modelUnit = new Root_meta_pure_model_unit_ModelUnit_Impl("")._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::pure::model::unit::ModelUnit")))._packageableElementIncludes(ListIterate.collect(srcBinding.modelUnit.packageableElementIncludes, pe -> context.pureModel.getPackageableElement(pe, srcBinding.sourceInformation)))._packageableElementExcludes(ListIterate.collect(srcBinding.modelUnit.packageableElementExcludes, pe -> context.pureModel.getPackageableElement(pe, srcBinding.sourceInformation)));
    compiled._modelUnit(modelUnit);
}
Also used : Root_meta_external_shared_format_binding_validation_FailedBindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_FailedBindingDetail) Root_meta_pure_metamodel_type_generics_GenericType_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) Root_meta_external_shared_format_metamodel_SchemaSet(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Root_meta_pure_model_unit_ModelUnit(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ModelUnit) Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Root_meta_pure_model_unit_ModelUnit_Impl(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ModelUnit_Impl) Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) Maps(org.eclipse.collections.api.factory.Maps) Root_meta_external_shared_format_binding_validation_BindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail) ExternalFormatSchemaSet(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet) MutableMap(org.eclipse.collections.api.map.MutableMap) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) Processor(org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.Processor) Map(java.util.Map) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_external_shared_format_binding_Binding_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding_Impl) Collections(java.util.Collections) Root_meta_pure_model_unit_ModelUnit(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ModelUnit) Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Root_meta_pure_metamodel_type_generics_GenericType_Impl(org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Root_meta_external_shared_format_metamodel_SchemaSet(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet) Root_meta_pure_model_unit_ModelUnit_Impl(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ModelUnit_Impl)

Aggregations

Binding (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding)5 ModelUnit (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit)4 ExternalFormatSchemaSet (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet)3 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)3 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)2 ExternalFormatSchema (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2 Root_meta_external_shared_format_binding_validation_BindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)2 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)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 Maps (org.eclipse.collections.api.factory.Maps)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 Pair (org.eclipse.collections.api.tuple.Pair)1 Tuples (org.eclipse.collections.impl.tuple.Tuples)1