use of org.finos.legend.engine.external.shared.format.model.toModel.SchemaToModelGenerator in project legend-engine by finos.
the class SchemaToModelGenerationTest method generateModel.
public static PureModelContextData generateModel(String schemaCode, SchemaToModelConfiguration config) {
PureModelContextData modelData = null;
PureModel pureModel = null;
try {
modelData = PureGrammarParser.newInstance().parseModel(schemaCode);
pureModel = Compiler.compile(modelData, DeploymentMode.TEST, null);
} catch (Exception e) {
Assert.fail("The schema code cannot be compiled: " + e.getMessage());
}
PureModelContextData generated = new SchemaToModelGenerator(pureModel, "vX_X_X").generate(config);
PureModelContextData combined = modelData.combine(generated);
try {
Compiler.compile(combined, DeploymentMode.TEST, null);
} catch (Exception e) {
Assert.fail("The generated model cannot be compiled: " + e.getMessage());
}
return generated;
}
use of org.finos.legend.engine.external.shared.format.model.toModel.SchemaToModelGenerator 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);
}
}
Aggregations