Search in sources :

Example 1 with ExternalFormatSchemaException

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

the class FlatDataSchemaCompiler method compile.

public Root_meta_external_format_flatdata_metamodel_FlatData compile() {
    try {
        FlatData flatData = new FlatDataSchemaParser(context.getContent()).parse();
        FlatDataValidationResult validationResult = FlatDataValidation.validate(flatData);
        if (!validationResult.isValid()) {
            String message = validationResult.getDefects().stream().map(Object::toString).collect(Collectors.joining(", "));
            throw new ExternalFormatSchemaException(message);
        }
        return convert(flatData);
    } catch (FlatDataSchemaParseException e) {
        throw new ExternalFormatSchemaException(e.getMessage(), e.getStartLine(), e.getStartColumn(), e.getEndLine(), e.getEndColumn());
    }
}
Also used : FlatDataSchemaParseException(org.finos.legend.engine.external.format.flatdata.shared.grammar.FlatDataSchemaParseException) FlatDataSchemaParser(org.finos.legend.engine.external.format.flatdata.shared.grammar.FlatDataSchemaParser) FlatDataValidationResult(org.finos.legend.engine.external.format.flatdata.shared.validation.FlatDataValidationResult) FlatDataString(org.finos.legend.engine.external.format.flatdata.shared.model.FlatDataString) ExternalFormatSchemaException(org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException) FlatData(org.finos.legend.engine.external.format.flatdata.shared.model.FlatData) Root_meta_external_format_flatdata_metamodel_FlatData(org.finos.legend.pure.generated.Root_meta_external_format_flatdata_metamodel_FlatData)

Example 2 with ExternalFormatSchemaException

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

the class XsdParser method handleXmlStreamException.

private ExternalFormatSchemaException handleXmlStreamException(XMLStreamException e) {
    Matcher matcher = Pattern.compile("ParseError at .*\nMessage: (.*)").matcher(e.getMessage());
    String message;
    if (matcher.matches()) {
        message = matcher.group(1);
    } else {
        Matcher matcher2 = Pattern.compile("(.*)\\s*at\\s*\\[.*]").matcher(e.getMessage());
        message = matcher2.matches() ? matcher2.group(1) : e.getMessage();
    }
    return new ExternalFormatSchemaException(message, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
}
Also used : Matcher(java.util.regex.Matcher) ExternalFormatSchemaException(org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException)

Example 3 with ExternalFormatSchemaException

use of org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException 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)

Aggregations

ExternalFormatSchemaException (org.finos.legend.engine.external.shared.format.model.compile.ExternalFormatSchemaException)3 Matcher (java.util.regex.Matcher)1 FlatDataSchemaParseException (org.finos.legend.engine.external.format.flatdata.shared.grammar.FlatDataSchemaParseException)1 FlatDataSchemaParser (org.finos.legend.engine.external.format.flatdata.shared.grammar.FlatDataSchemaParser)1 FlatData (org.finos.legend.engine.external.format.flatdata.shared.model.FlatData)1 FlatDataString (org.finos.legend.engine.external.format.flatdata.shared.model.FlatDataString)1 FlatDataValidationResult (org.finos.legend.engine.external.format.flatdata.shared.validation.FlatDataValidationResult)1 ExternalFormatExtension (org.finos.legend.engine.external.shared.format.model.ExternalFormatExtension)1 ExternalSchemaCompileContext (org.finos.legend.engine.external.shared.format.model.ExternalSchemaCompileContext)1 ExternalFormatSchema (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchema)1 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 Root_meta_external_format_flatdata_metamodel_FlatData (org.finos.legend.pure.generated.Root_meta_external_format_flatdata_metamodel_FlatData)1 Root_meta_external_shared_format_metamodel_Schema (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema)1 Root_meta_external_shared_format_metamodel_SchemaDetail (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaDetail)1 Root_meta_external_shared_format_metamodel_SchemaSet (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_SchemaSet)1 Root_meta_external_shared_format_metamodel_Schema_Impl (org.finos.legend.pure.generated.Root_meta_external_shared_format_metamodel_Schema_Impl)1