Search in sources :

Example 1 with EngineException

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();
}
Also used : PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) Logger(org.slf4j.Logger) GenerationCompilerExtension(org.finos.legend.engine.language.pure.dsl.generation.compiler.toPureGraph.GenerationCompilerExtension) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) GenerationSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationSpecification) Iterate(org.eclipse.collections.impl.utility.Iterate) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) Objects(java.util.Objects) Function3(org.eclipse.collections.api.block.function.Function3) List(java.util.List) MutableMap(org.eclipse.collections.api.map.MutableMap) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) DeploymentMode(org.finos.legend.engine.shared.core.deployment.DeploymentMode) HelperGenerationSpecificationBuilder(org.finos.legend.engine.language.pure.dsl.generation.compiler.toPureGraph.HelperGenerationSpecificationBuilder) GenerationTreeNode(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationTreeNode) GenerationCompilerExtension(org.finos.legend.engine.language.pure.dsl.generation.compiler.toPureGraph.GenerationCompilerExtension) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Function3(org.eclipse.collections.api.block.function.Function3) Objects(java.util.Objects) GenerationTreeNode(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationTreeNode)

Example 2 with EngineException

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());
}
Also used : GenerationSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationSpecification) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 3 with EngineException

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);
}
Also used : Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) PureGrammarParser(org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Association(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Association) Enumeration(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Enumeration) IOException(java.io.IOException) Reader(java.io.Reader) Iterate(org.eclipse.collections.impl.utility.Iterate) EntityTextSerializer(org.finos.legend.sdlc.serialization.EntityTextSerializer) Profile(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Profile) List(java.util.List) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Map(java.util.Map) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Writer(java.io.Writer) PureProtocolObjectMapperFactory(org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory) SectionIndex(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) SectionIndex(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Map(java.util.Map) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)

Example 4 with EngineException

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");
        }
    }
}
Also used : Field(java.lang.reflect.Field) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Method(java.lang.reflect.Method) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with EngineException

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;
}
Also used : ConfigurationProperty(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.fileGeneration.ConfigurationProperty) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)

Aggregations

EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)104 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)27 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)22 ListIterate (org.eclipse.collections.impl.utility.ListIterate)19 List (java.util.List)16 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)14 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)13 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)12 RichIterable (org.eclipse.collections.api.RichIterable)10 ArrayList (java.util.ArrayList)9 Objects (java.util.Objects)9 Lists (org.eclipse.collections.impl.factory.Lists)9 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)8 Root_meta_pure_metamodel_type_generics_GenericType_Impl (org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl)8 VariableExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression)8 Collections (java.util.Collections)7 FastList (org.eclipse.collections.impl.list.mutable.FastList)7 Root_meta_external_shared_format_binding_Binding (org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding)7 ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)6 CString (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.CString)6