From 5395880429c7aeb73e18bb1beff261056d5d4c49 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 21 Nov 2024 01:24:51 +0100 Subject: [PATCH] Implemented validating eInvoices via API --- .../kotlin/net/codinux/invoicing/api/InvoicingResource.kt | 8 ++++++++ .../net/codinux/invoicing/service/InvoicingService.kt | 7 +++++++ e-invoice-api/src/main/resources/application.properties | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt index 929eabc..abf2fdd 100644 --- a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt +++ b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/api/InvoicingResource.kt @@ -49,4 +49,12 @@ class InvoicingResource( fun extractInvoiceData(invoice: java.nio.file.Path) = service.extractInvoiceData(invoice) + @Path("validate") + @POST + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + @Produces(MediaType.APPLICATION_XML) + @Operation(summary = "Validate a Factur-x / ZUGFeRD or XRechnung file") + fun validateInvoiceXml(invoice: java.nio.file.Path) = + service.validateInvoice(invoice).reportAsXml + } \ No newline at end of file diff --git a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt index c5e709c..31805b9 100644 --- a/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt +++ b/e-invoice-api/src/main/kotlin/net/codinux/invoicing/service/InvoicingService.kt @@ -4,6 +4,7 @@ import jakarta.inject.Singleton import net.codinux.invoicing.creation.EInvoiceCreator import net.codinux.invoicing.model.Invoice import net.codinux.invoicing.reader.EInvoiceReader +import net.codinux.invoicing.validation.EInvoiceValidator import java.io.File import java.nio.file.Path import kotlin.io.path.extension @@ -15,6 +16,8 @@ class InvoicingService { private val reader = EInvoiceReader() + private val validator = EInvoiceValidator() + fun createXRechnung(invoice: Invoice): String = creator.createXRechnungXml(invoice) @@ -39,4 +42,8 @@ class InvoicingService { else -> throw IllegalArgumentException("We can only extract eInvoice data from .xml and .pdf files") } + + fun validateInvoice(invoice: Path) = + validator.validate(invoice.toFile()) + } \ No newline at end of file diff --git a/e-invoice-api/src/main/resources/application.properties b/e-invoice-api/src/main/resources/application.properties index 9c59bb2..0c8cd7d 100644 --- a/e-invoice-api/src/main/resources/application.properties +++ b/e-invoice-api/src/main/resources/application.properties @@ -44,6 +44,12 @@ quarkus.log.loki.field.kubernetes.field.containername.include=false # to turn off verbose FOP messages quarkus.log.category."org.apache.fop.apps".level=ERROR +# to turn off verbose invoice validation logging +quarkus.log.category."org.mustangproject.validator".level=ERROR + + +# to fix that javax.xml.namespace.QName gets loaded with Quarkus' class loader instead of default class loader which causes an error +quarkus.class-loading.parent-first-artifacts=xpp3:xpp3 # Live reload