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