Search in sources :

Example 1 with Root_meta_external_shared_format_metamodel_SchemaSet

use of org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet in project legend-engine by finos.

the class HelperExternalFormat method getSchemaSet.

public static Root_meta_external_shared_format_metamodel_SchemaSet getSchemaSet(String fullPath, SourceInformation sourceInformation, CompileContext context) {
    Root_meta_external_shared_format_metamodel_SchemaSet schemaSet = getExternalFormatCompilerExtension(context).schemaSetCompiler.getCompiledSchemaSet(fullPath);
    Assert.assertTrue(schemaSet != null, () -> "Can't find SchemaSet '" + fullPath + "'", sourceInformation, EngineErrorType.COMPILATION);
    return schemaSet;
}
Also used : Root_meta_external_shared_format_metamodel_SchemaSet(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet)

Example 2 with Root_meta_external_shared_format_metamodel_SchemaSet

use of org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet 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)

Example 3 with Root_meta_external_shared_format_metamodel_SchemaSet

use of org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet 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 4 with Root_meta_external_shared_format_metamodel_SchemaSet

use of org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet 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)

Example 5 with Root_meta_external_shared_format_metamodel_SchemaSet

use of org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet in project legend-engine by finos.

the class SchemaToModelGenerator method generate.

public PureModelContextData generate(SchemaToModelConfiguration configuration) {
    Root_meta_external_shared_format_metamodel_SchemaSet schemaSet = HelperExternalFormat.getSchemaSet(configuration.sourceSchemaSet, pureModel.getContext());
    ExternalFormatExtension schemaExtension = schemaExtensions.get(schemaSet._format());
    if (schemaExtension == null) {
        throw new IllegalArgumentException("Unknown schema format: " + schemaSet._format());
    }
    Class<?> configClass = (Class<?>) ((ParameterizedType) schemaExtension.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[1];
    if (!configClass.isInstance(configuration)) {
        throw new IllegalArgumentException("Invalid configuration for " + schemaSet._format() + " model generation: " + configuration.getClass().getSimpleName());
    }
    return toPureModelContextData(schemaExtension.generateModel(schemaSet, configuration, pureModel));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Root_meta_external_shared_format_metamodel_SchemaSet(org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)

Aggregations

Root_meta_external_shared_format_metamodel_SchemaSet (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet)6 ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)3 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)3 ExternalFormatSchema (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema)2 Root_meta_external_shared_format_metamodel_Schema (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema)2 Root_meta_external_shared_format_metamodel_Schema_Impl (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema_Impl)2 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Maps (org.eclipse.collections.api.factory.Maps)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 ExternalSchemaCompileContext (org.finos.legend.engine.external.shared.format.model.ExternalSchemaCompileContext)1 ExternalFormatSchemaException (org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException)1 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)1 Processor (org.finos.legend.engine.language.pure.compiler.toPureGraph.extension.Processor)1 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 Binding (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding)1