Search in sources :

Example 1 with ExternalFormatExtension

use of org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension in project legend-engine by finos.

the class BindingCompiler method fourthPass.

// Fourth pass - ensure correlation using the extension
private void fourthPass(Binding srcBinding, CompileContext context) {
    String path = context.pureModel.buildPackageString(srcBinding._package, srcBinding.name);
    Root_meta_external_shared_format_binding_Binding compiled = bindingIndex.get(path);
    ExternalFormatExtension schemaExtension = getExtension(compiled, srcBinding);
    Root_meta_external_shared_format_binding_validation_BindingDetail bindingDetail = schemaExtension.bindDetails(compiled, context);
    if (bindingDetail instanceof Root_meta_external_shared_format_binding_validation_FailedBindingDetail) {
        Root_meta_external_shared_format_binding_validation_FailedBindingDetail failed = (Root_meta_external_shared_format_binding_validation_FailedBindingDetail) bindingDetail;
        throw new EngineException("Model and schema are mismatched:\n" + failed._errorMessages().makeString("\n"), srcBinding.sourceInformation, EngineErrorType.COMPILATION);
    }
}
Also used : Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Root_meta_external_shared_format_binding_validation_FailedBindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_FailedBindingDetail) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension) Root_meta_external_shared_format_binding_validation_BindingDetail(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)

Example 2 with ExternalFormatExtension

use of org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension in project legend-engine by finos.

the class BindingCompiler method thirdPass.

// Third pass - validation
private void thirdPass(Binding srcBinding, CompileContext context) {
    String path = context.pureModel.buildPackageString(srcBinding._package, srcBinding.name);
    Root_meta_external_shared_format_binding_Binding compiled = bindingIndex.get(path);
    if (compiled._schemaId() != null && compiled._schemaSet()._schemas().noneSatisfy(s -> compiled._schemaId().equals(s._id()))) {
        throw new EngineException("ID '" + compiled._schemaId() + "' does not exist in SchemaSet '" + srcBinding.schemaSet + "'", srcBinding.sourceInformation, EngineErrorType.COMPILATION);
    }
    ExternalFormatExtension schemaExtension = getExtension(compiled, srcBinding);
    if (compiled._schemaSet() != null && !schemaExtension.getFormat().equals(compiled._schemaSet()._format())) {
        throw new EngineException("Content type and SchemaSet format do not match", srcBinding.sourceInformation, EngineErrorType.COMPILATION);
    }
}
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_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)

Example 3 with ExternalFormatExtension

use of org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension 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 4 with ExternalFormatExtension

use of org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension in project legend-engine by finos.

the class ExternalFormats method generateModel.

@POST
@Path("generateModel")
@ApiOperation(value = "Generates a model from a schema for the external format")
@Consumes({ MediaType.APPLICATION_JSON, APPLICATION_ZLIB })
public Response generateModel(GenerateModelInput generateModelInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm) {
    MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
    boolean interactive = generateModelInput.model instanceof PureModelContextData;
    try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Model From External Format Schema").startActive(true)) {
        long start = System.currentTimeMillis();
        LOGGER.info(new LogInfo(profiles, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_INTERACTIVE_START : LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_START).toString());
        ExternalFormatExtension extension = extensions.get(generateModelInput.config.format);
        if (!extension.supportsModelGeneration()) {
            throw new UnsupportedOperationException("Model generation not supported for " + extension.getFormat());
        }
        PureModel pureModel = this.modelManager.loadModel(generateModelInput.model, generateModelInput.clientVersion, profiles, null);
        SchemaToModelGenerator generator = new SchemaToModelGenerator(pureModel, generateModelInput.clientVersion);
        PureModelContextData generated = generator.generate(generateModelInput.config);
        LOGGER.info(new LogInfo(profiles, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_INTERACTIVE_STOP : LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_STOP, (double) System.currentTimeMillis() - start).toString());
        return ManageConstantResult.manageResult(profiles, generated, objectMapper);
    } catch (Exception ex) {
        return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_INTERACTIVE_ERROR : LoggingEventType.GENERATE_EXTERNAL_FORMAT_MODEL_ERROR, profiles);
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) Scope(io.opentracing.Scope) CommonProfile(org.pac4j.core.profile.CommonProfile) SchemaToModelGenerator(org.finos.legend.engine.external.shared.format.model.toModel.SchemaToModelGenerator) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with ExternalFormatExtension

use of org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension in project legend-engine by finos.

the class ExternalFormats method generateSchema.

@POST
@Path("generateSchema")
@ApiOperation(value = "Generates a schema in an external format from a model")
@Consumes({ MediaType.APPLICATION_JSON, APPLICATION_ZLIB })
public Response generateSchema(GenerateSchemaInput generateSchemaInput, @ApiParam(hidden = true) @Pac4JProfileManager ProfileManager<CommonProfile> pm) {
    MutableList<CommonProfile> profiles = ProfileManagerHelper.extractProfiles(pm);
    boolean interactive = generateSchemaInput.model instanceof PureModelContextData;
    try (Scope scope = GlobalTracer.get().buildSpan("Service: Generate Model From External Format Schema").startActive(true)) {
        long start = System.currentTimeMillis();
        LOGGER.info(new LogInfo(profiles, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_INTERACTIVE_START : LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_START).toString());
        ExternalFormatExtension extension = extensions.get(generateSchemaInput.config.format);
        if (!extension.supportsModelGeneration()) {
            throw new UnsupportedOperationException("Model generation not supported for " + extension.getFormat());
        }
        PureModel pureModel = this.modelManager.loadModel(generateSchemaInput.model, generateSchemaInput.clientVersion, profiles, null);
        ModelToSchemaGenerator generator = new ModelToSchemaGenerator(pureModel);
        PureModelContextData generated = generator.generate(generateSchemaInput.config);
        LOGGER.info(new LogInfo(profiles, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_INTERACTIVE_STOP : LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_STOP, (double) System.currentTimeMillis() - start).toString());
        return ManageConstantResult.manageResult(profiles, generated, objectMapper);
    } catch (Exception ex) {
        return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_INTERACTIVE_ERROR : LoggingEventType.GENERATE_EXTERNAL_FORMAT_SCHEMA_ERROR, profiles);
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) ModelToSchemaGenerator(org.finos.legend.engine.external.shared.format.model.fromModel.ModelToSchemaGenerator) Scope(io.opentracing.Scope) CommonProfile(org.pac4j.core.profile.CommonProfile) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) ExternalFormatExtension(org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)9 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)5 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)3 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)3 Root_meta_external_shared_format_metamodel_SchemaSet (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet)3 Scope (io.opentracing.Scope)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 ExternalFormatSchemaSet (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet)2 LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)2 Root_meta_external_shared_format_binding_validation_BindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_BindingDetail)2 Root_meta_external_shared_format_binding_validation_FailedBindingDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_validation_FailedBindingDetail)2 CommonProfile (org.pac4j.core.profile.CommonProfile)2 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