Search in sources :

Example 1 with ExternalFormatSchema

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

the class ExternalFormatParseTreeWalker method visitSchema.

private ExternalFormatSchema visitSchema(ExternalFormatParserGrammar.SchemaContext ctx) {
    SourceInformation sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    ExternalFormatSchema schema = new ExternalFormatSchema();
    schema.sourceInformation = sourceInformation;
    // id
    ExternalFormatParserGrammar.SchemaIdContext idContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.schemaId(), "id", sourceInformation);
    schema.id = idContext == null ? null : PureGrammarParserUtility.fromIdentifier(idContext.identifier());
    // location
    ExternalFormatParserGrammar.SchemaLocationContext locationContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.schemaLocation(), "location", sourceInformation);
    schema.location = locationContext == null ? null : PureGrammarParserUtility.fromGrammarString(locationContext.STRING().getText(), true);
    // content
    ExternalFormatParserGrammar.SchemaContentContext contentContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.schemaContent(), "content", sourceInformation);
    schema.content = PureGrammarParserUtility.fromGrammarString(contentContext.STRING().getText(), true);
    schema.contentSourceInformation = this.walkerSourceInformation.getSourceInformation(contentContext);
    return schema;
}
Also used : ExternalFormatParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.ExternalFormatParserGrammar) ExternalFormatSchema(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)

Example 2 with ExternalFormatSchema

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

the class ExternalFormatGrammarComposerExtension method renderSchemaSet.

private static String renderSchemaSet(ExternalFormatSchemaSet schemaSet) {
    StringBuilder builder = new StringBuilder().append("SchemaSet ").append(PureGrammarComposerUtility.convertPath(schemaSet.getPath())).append("\n{\n");
    PureGrammarComposerUtility.appendTabString(builder).append("format: ").append(schemaSet.format).append(";\n");
    PureGrammarComposerUtility.appendTabString(builder).append("schemas: [\n");
    for (int i = 0; i < schemaSet.schemas.size(); i++) {
        ExternalFormatSchema schema = schemaSet.schemas.get(i);
        PureGrammarComposerUtility.appendTabString(builder, 2).append("{\n");
        if (schema.id != null) {
            PureGrammarComposerUtility.appendTabString(builder, 3).append("id: ").append(PureGrammarComposerUtility.convertIdentifier(schema.id)).append(";\n");
        }
        if (schema.location != null) {
            PureGrammarComposerUtility.appendTabString(builder, 3).append("location: ").append(PureGrammarComposerUtility.convertString(schema.location, true)).append(";\n");
        }
        PureGrammarComposerUtility.appendTabString(builder, 3).append("content: ").append(PureGrammarComposerUtility.convertString(schema.content, true)).append(";\n");
        PureGrammarComposerUtility.appendTabString(builder, 2).append("}").append(i < schemaSet.schemas.size() - 1 ? ",\n" : "\n");
    }
    PureGrammarComposerUtility.appendTabString(builder).append("];\n}");
    return builder.toString();
}
Also used : ExternalFormatSchema(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema)

Example 3 with ExternalFormatSchema

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

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

the class SchemaSetCompiler method firstPass.

// First pass - create and index schemas
private PackageableElement firstPass(ExternalFormatSchemaSet srcSchemaSet, CompileContext context) {
    if (externalFormatExtensions.get(srcSchemaSet.format) == null) {
        throw new EngineException("Unknown schema format: " + srcSchemaSet.format, srcSchemaSet.formatSourceInformation, EngineErrorType.COMPILATION);
    }
    Root_meta_external_shared_format_metamodel_SchemaSet schemaSet = new Root_meta_external_shared_format_metamodel_SchemaSet_Impl(srcSchemaSet.name)._name(srcSchemaSet.name)._classifierGenericType(new Root_meta_pure_metamodel_type_generics_GenericType_Impl("")._rawType(context.pureModel.getType("meta::external::shared::format::metamodel::SchemaSet")))._format(srcSchemaSet.format);
    Set<String> ids = Sets.mutable.empty();
    Set<String> locations = Sets.mutable.empty();
    for (ExternalFormatSchema srcSchema : srcSchemaSet.schemas) {
        if (srcSchema.id != null) {
            if (!ids.add(srcSchema.id)) {
                throw new EngineException("Schema id '" + srcSchema.id + "' is duplicated", srcSchema.sourceInformation, EngineErrorType.COMPILATION);
            }
        }
        if (srcSchema.location != null) {
            if (!locations.add(srcSchema.location)) {
                throw new EngineException("Schema location '" + srcSchema.location + "' is duplicated", srcSchema.sourceInformation, EngineErrorType.COMPILATION);
            }
        }
        Root_meta_external_shared_format_metamodel_Schema schema = new Root_meta_external_shared_format_metamodel_Schema_Impl("")._id(srcSchema.id)._location(srcSchema.location);
        schemaSet._schemasAdd(schema);
    }
    String path = context.pureModel.buildPackageString(srcSchemaSet._package, srcSchemaSet.name);
    this.schemaSetIndex.put(path, schemaSet);
    return schemaSet;
}
Also used : ExternalFormatSchema(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema) 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_Schema(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema) Root_meta_external_shared_format_metamodel_SchemaSet(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet) Root_meta_external_shared_format_metamodel_SchemaSet_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet_Impl) Root_meta_external_shared_format_metamodel_Schema_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema_Impl)

Example 5 with ExternalFormatSchema

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

the class SchemaSetCompiler method secondPass.

// Second pass - compile external schemas using extension
private void secondPass(ExternalFormatSchemaSet srcSchemaSet, CompileContext context) {
    String path = context.pureModel.buildPackageString(srcSchemaSet._package, srcSchemaSet.name);
    Root_meta_external_shared_format_metamodel_SchemaSet compiled = schemaSetIndex.get(path);
    ExternalFormatExtension schemaExtension = externalFormatExtensions.get(srcSchemaSet.format);
    compiled._schemas(Lists.mutable.empty());
    for (ExternalFormatSchema srcSchema : srcSchemaSet.schemas) {
        try {
            Root_meta_external_shared_format_metamodel_SchemaDetail detail = schemaExtension.compileSchema(new SchemaCompileContext(srcSchema, srcSchemaSet, context));
            Root_meta_external_shared_format_metamodel_Schema schema = new Root_meta_external_shared_format_metamodel_Schema_Impl("")._id(srcSchema.id)._location(srcSchema.location)._detail(detail);
            compiled._schemasAdd(schema);
        } catch (ExternalFormatSchemaException e) {
            throw new EngineException(e.getMessage(), srcSchema.contentSourceInformation, EngineErrorType.COMPILATION, e);
        }
    }
}
Also used : ExternalFormatSchema(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema) ExternalSchemaCompileContext(org.finos.legend.engine.external.shared.format.model.ExternalSchemaCompileContext) Root_meta_external_shared_format_metamodel_Schema(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema) 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_external_shared_format_metamodel_Schema_Impl(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema_Impl) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension) ExternalFormatSchemaException(org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException) Root_meta_external_shared_format_metamodel_SchemaDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaDetail)

Aggregations

ExternalFormatSchema (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema)6 Root_meta_external_shared_format_metamodel_Schema (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema)3 ExternalFormatSchemaSet (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2 Root_meta_external_shared_format_metamodel_SchemaSet (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet)2 Root_meta_external_shared_format_metamodel_Schema_Impl (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema_Impl)2 ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)1 ExternalSchemaCompileContext (org.finos.legend.engine.external.shared.format.model.ExternalSchemaCompileContext)1 ExternalFormatSchemaException (org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException)1 ExternalFormatParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.ExternalFormatParserGrammar)1 PureGrammarComposer (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer)1 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 ModelUnit (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ModelUnit)1 Binding (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding)1 Root_meta_external_shared_format_metamodel_SchemaDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaDetail)1 Root_meta_external_shared_format_metamodel_SchemaSet_Impl (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet_Impl)1 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)1 Test (org.junit.Test)1