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