use of org.finos.legend.engine.shared.core.operational.errorManagement.EngineException in project legend-sdlc by finos.
the class ModelGenerationFactory method generate.
public PureModelContextData generate() throws Exception {
if ((this.generationSpecification._package == null) || this.generationSpecification._package.isEmpty()) {
throw new RuntimeException("Invalid generation specifications, missing path '" + this.generationSpecification.name);
}
LOGGER.info("Generation generation specification '" + generationSpecification.getPath() + "'");
List<GenerationTreeNode> nodes = this.generationSpecification.generationNodes;
for (GenerationTreeNode node : nodes) {
LOGGER.info("Start generating generation model element '" + node.generationElement + "'");
List<Function3<String, SourceInformation, CompileContext, org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement>> extraModelGenerationSpecificationResolvers = ListIterate.flatCollect(HelperGenerationSpecificationBuilder.getGenerationCompilerExtensions(this.pureModel.getContext()), GenerationCompilerExtension::getExtraModelGenerationSpecificationResolvers);
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement generationElement = extraModelGenerationSpecificationResolvers.stream().map(resolver -> resolver.value(node.generationElement, node.sourceInformation, this.pureModel.getContext())).filter(Objects::nonNull).findFirst().orElseThrow(() -> new EngineException("Can't find generation element '" + node.generationElement + "'", node.sourceInformation, EngineErrorType.COMPILATION));
ModelGenerator modelGenerator = ModelGenerator.newGenerator(generationElement, this.pureModel);
processModelGenerator(modelGenerator);
}
return validateAndBuildGeneratedModel();
}
use of org.finos.legend.engine.shared.core.operational.errorManagement.EngineException in project legend-sdlc by finos.
the class TestModelGenerationFactory method testCompileError.
@Test
public void testCompileError() {
GenerationSpecification generationSpecification = this.getTestGenerationSpecification();
PureModelContextData.Builder builder = PureModelContextData.newBuilder();
builder.addElement(generationSpecification);
ModelGenerationFactory factory = ModelGenerationFactory.newFactory(generationSpecification, builder.build());
EngineException compileEngineException = Assert.assertThrows(EngineException.class, () -> factory.processModelGenerator(classDependedOnSimpleClassGenerator));
Assert.assertEquals("Error in 'model::MyComplexClass': Can't find type 'model::MyClass'", compileEngineException.getMessage());
}
use of org.finos.legend.engine.shared.core.operational.errorManagement.EngineException in project legend-sdlc by finos.
the class PureDomainDeserializer method deserialize.
@Override
public Entity deserialize(String content) throws IOException {
PureModelContextData pureModelContextData;
try {
pureModelContextData = this.pureParser.parseModel(content);
} catch (EngineException e) {
throw new RuntimeException(EngineException.buildPrettyErrorMessage(e.getMessage(), e.getSourceInformation(), e.getErrorType()), e);
}
List<PackageableElement> elements = pureModelContextData.getElements();
if ((elements.size() != 2) || Iterate.noneSatisfy(elements, e -> e instanceof SectionIndex)) {
throw new RuntimeException("Unexpected parsing result (element count: " + elements.size() + ", SectionIndex present: " + Iterate.anySatisfy(elements, e -> e instanceof SectionIndex) + ")");
}
PackageableElement element = elements.get((elements.get(0) instanceof SectionIndex) ? 1 : 0);
String classifierPath = getClassifierPath(element);
String intermediateJson = this.jsonMapper.writeValueAsString(element);
Map<String, Object> entityContent = this.jsonMapper.readValue(intermediateJson, this.jsonMapper.getTypeFactory().constructMapType(Map.class, String.class, Object.class));
return Entity.newEntity(element.getPath(), classifierPath, entityContent);
}
use of org.finos.legend.engine.shared.core.operational.errorManagement.EngineException in project legend-engine by finos.
the class ConfigBuilder method setConfigurationProperty.
public static void setConfigurationProperty(FileGenerationSpecification fileGeneration, ConfigurationProperty configurationProperty, GenerationConfiguration generationConfiguration) {
Class<?> clazz = generationConfiguration.getClass();
String paramName = configurationProperty.name;
Object value = configurationProperty.value;
Field field;
try {
Object fieldValue = value;
field = clazz.getField(paramName);
if (field.getType().isEnum()) {
fieldValue = Enum.valueOf((Class<Enum>) field.getType(), (String) fieldValue);
}
Assert.assertTrue(field.getType().isAssignableFrom(fieldValue.getClass()), () -> "Type '" + value.getClass().getSimpleName() + "' not assignable to type '" + field.getType().getSimpleName() + "' for config property '" + paramName + "'");
field.setAccessible(true);
field.set(generationConfiguration, fieldValue);
} catch (Exception e) {
String setMethodName = "set" + StringUtils.capitalize(paramName);
try {
Method m = clazz.getMethod(setMethodName, value.getClass());
m.invoke(generationConfiguration, value);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException error) {
throw new EngineException("Configuration property '" + paramName + "' not found in '" + fileGeneration.type + "' config");
}
}
}
use of org.finos.legend.engine.shared.core.operational.errorManagement.EngineException in project legend-engine by finos.
the class FileGenerationParseTreeWalker method visitConfigurationProperty.
private ConfigurationProperty visitConfigurationProperty(FileGenerationParserGrammar.ConfigPropertyContext configPropertyContext, FileGenerationSpecification fileGeneration) {
ConfigurationProperty configurationProperty = new ConfigurationProperty();
configurationProperty.sourceInformation = walkerSourceInformation.getSourceInformation(configPropertyContext);
if (configPropertyContext.configPropertyValue() != null) {
configurationProperty.name = configPropertyContext.configPropertyName().getText();
if ("generationOutputPath".equals(configurationProperty.name) || "scopeElements".equals(configurationProperty.name)) {
throw new EngineException("Can't have config property with reserved name '" + configurationProperty.name + "'", fileGeneration.sourceInformation, EngineErrorType.PARSER);
}
configurationProperty.value = this.visitConfigPropertyValue(configPropertyContext.configPropertyValue());
}
return configurationProperty;
}
Aggregations