使用 Mustang 从 XML String 创建一个 facturX
Create a facturX with Mustang from XML String
我正在尝试在 API 中使用 Mustang 库构建一个 facturx。
我有一个(有效的)XML 字符串作为条目
@PostMapping
public FxResponse createFacturX(@RequestBody XmlRequest request) throws IOException {
if(request.getVersion() == null) {
request.setVersion(2);
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
log.debug("Converting to PDF/A-3u");
if ((request.getVersion() < 1) || (request.getVersion() > 2)) {
throw new IllegalArgumentException("invalid version");
}
PDFAConformanceLevel pdfaConformanceLevel;
switch (request.getConformanceLevel()) {
case "BASIC":
pdfaConformanceLevel = PDFAConformanceLevel.BASIC;
break;
case "ACCESSIBLE":
pdfaConformanceLevel = PDFAConformanceLevel.ACCESSIBLE;
break;
case "UNICODE":
pdfaConformanceLevel = PDFAConformanceLevel.UNICODE;
break;
default:
throw new IllegalArgumentException("invalid level");
}
System.out.println(Arrays.toString(request.getPdf().getBytes(StandardCharsets.UTF_8)));
byte[] xmlData = request.getXml().getBytes(StandardCharsets.UTF_8);
byte[] pdfData = Base64.getDecoder().decode(request.getPdf().getBytes(StandardCharsets.UTF_8));
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
.setProducer("Mustang API")
.setCreator("Creator ME")
.setZUGFeRDVersion(request.getVersion())
.setConformanceLevel(pdfaConformanceLevel)
.load(pdfData);
ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data");
ze.setXML(xmlData);
log.debug("Attaching ZUGFeRD-Data");
ze.disableAutoClose(true);
ze.export(output);
byte[] bytes = output.toByteArray();
InputStream inputStream = new ByteArrayInputStream(bytes);
byte[] pdfBytes = IOUtils.toByteArray(inputStream);
try {
Utils.facturxValidator(request.getXml());
} catch (Exception e) {
e.printStackTrace();
}
String encoded = Base64.getEncoder().encodeToString(pdfBytes);
return new FxResponse("OK", encoded);
}
我确实检索了 PDF 作为输出,但在验证 PDF 时出现错误。
另一方面,我的XML完全有效
我试图检查 pdf 是否兼容,我还尝试了 mustang cli 来检查输出。
我确实有以下失败:
<xml>
<info>
<version>2</version>
<profile>urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic</profile>
<validator version="2.4.0"/>
<rules>
<fired>466</fired>
<failed>3</failed>
</rules>
<duration unit="ms">5242</duration>
</info>
<messages>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ExchangedDocumentContext[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]" criterion="ram:GuidelineSpecifiedDocumentContextParameter/ram:ID = $XR-CIUS-ID">[BR-DE-21] Das Element "Specification identifier" (BT-24) soll syntaktisch der Kennung des Standards XRechnung entsprechen. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeAgreement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SellerTradeParty[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="ram:DefinedTradeContact">[BR-DE-2] Die Gruppe "SELLER CONTACT" (BG-6) muss übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementPaymentMeans[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="not(ram:ApplicableTradeSettlementFinancialCard) and not(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradePaymentTerms/ram:DirectDebitMandateID or /rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:CreditorReferenceID or ram:PayerPartyDebtorFinancialAccount/ram:IBANID)">[BR-DE-23-b] Wenn BT-81 "Payment means type code" einen Schlüssel für Überweisungen enthält (30, 58), dürfen BG-18 und BG-19 nicht übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
</messages>
<summary status="valid"/>
</xml>
我的问题如下:
- 我该如何解决这些失败
- 这些错误对我的 facturX 有影响吗?我确实在测试站点上验证了它们,它不在生产环境中
我注意到我忘记设置 facturx 配置文件,例如,EXTENDED:
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
.setProducer("Mustang API")
.setCreator("Creator ME")
.setProfile("EXTENDED");
.setZUGFeRDVersion(request.getVersion())
.setConformanceLevel(pdfaConformanceLevel)
.load(pdfData);
ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data");
ze.setXML(xmlData)
可用值如下:
{"MINIMUM", new Profile("MINIMUM", "urn:factur-x.eu:1p0:minimum")},
{"BASICWL", new Profile("BASICWL", "urn:factur-x.eu:1p0:basicwl")},
{"BASIC", new Profile("BASIC", "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic")},
{"EN16931", new Profile("EN16931", "urn:cen.eu:en16931:2017")},
{"EXTENDED", new Profile("EXTENDED", "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended")},
{"XRECHNUNG", new Profile("XRECHNUNG", "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.1")}
现在可以正常使用了!
我正在尝试在 API 中使用 Mustang 库构建一个 facturx。 我有一个(有效的)XML 字符串作为条目
@PostMapping
public FxResponse createFacturX(@RequestBody XmlRequest request) throws IOException {
if(request.getVersion() == null) {
request.setVersion(2);
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
log.debug("Converting to PDF/A-3u");
if ((request.getVersion() < 1) || (request.getVersion() > 2)) {
throw new IllegalArgumentException("invalid version");
}
PDFAConformanceLevel pdfaConformanceLevel;
switch (request.getConformanceLevel()) {
case "BASIC":
pdfaConformanceLevel = PDFAConformanceLevel.BASIC;
break;
case "ACCESSIBLE":
pdfaConformanceLevel = PDFAConformanceLevel.ACCESSIBLE;
break;
case "UNICODE":
pdfaConformanceLevel = PDFAConformanceLevel.UNICODE;
break;
default:
throw new IllegalArgumentException("invalid level");
}
System.out.println(Arrays.toString(request.getPdf().getBytes(StandardCharsets.UTF_8)));
byte[] xmlData = request.getXml().getBytes(StandardCharsets.UTF_8);
byte[] pdfData = Base64.getDecoder().decode(request.getPdf().getBytes(StandardCharsets.UTF_8));
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
.setProducer("Mustang API")
.setCreator("Creator ME")
.setZUGFeRDVersion(request.getVersion())
.setConformanceLevel(pdfaConformanceLevel)
.load(pdfData);
ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data");
ze.setXML(xmlData);
log.debug("Attaching ZUGFeRD-Data");
ze.disableAutoClose(true);
ze.export(output);
byte[] bytes = output.toByteArray();
InputStream inputStream = new ByteArrayInputStream(bytes);
byte[] pdfBytes = IOUtils.toByteArray(inputStream);
try {
Utils.facturxValidator(request.getXml());
} catch (Exception e) {
e.printStackTrace();
}
String encoded = Base64.getEncoder().encodeToString(pdfBytes);
return new FxResponse("OK", encoded);
}
我确实检索了 PDF 作为输出,但在验证 PDF 时出现错误。
另一方面,我的XML完全有效
我试图检查 pdf 是否兼容,我还尝试了 mustang cli 来检查输出。 我确实有以下失败:
<xml>
<info>
<version>2</version>
<profile>urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic</profile>
<validator version="2.4.0"/>
<rules>
<fired>466</fired>
<failed>3</failed>
</rules>
<duration unit="ms">5242</duration>
</info>
<messages>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ExchangedDocumentContext[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]" criterion="ram:GuidelineSpecifiedDocumentContextParameter/ram:ID = $XR-CIUS-ID">[BR-DE-21] Das Element "Specification identifier" (BT-24) soll syntaktisch der Kennung des Standards XRechnung entsprechen. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeAgreement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SellerTradeParty[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="ram:DefinedTradeContact">[BR-DE-2] Die Gruppe "SELLER CONTACT" (BG-6) muss übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
<notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementPaymentMeans[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="not(ram:ApplicableTradeSettlementFinancialCard) and not(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradePaymentTerms/ram:DirectDebitMandateID or /rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:CreditorReferenceID or ram:PayerPartyDebtorFinancialAccount/ram:IBANID)">[BR-DE-23-b] Wenn BT-81 "Payment means type code" einen Schlüssel für Überweisungen enthält (30, 58), dürfen BG-18 und BG-19 nicht übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice>
</messages>
<summary status="valid"/>
</xml>
我的问题如下:
- 我该如何解决这些失败
- 这些错误对我的 facturX 有影响吗?我确实在测试站点上验证了它们,它不在生产环境中
我注意到我忘记设置 facturx 配置文件,例如,EXTENDED:
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
.setProducer("Mustang API")
.setCreator("Creator ME")
.setProfile("EXTENDED");
.setZUGFeRDVersion(request.getVersion())
.setConformanceLevel(pdfaConformanceLevel)
.load(pdfData);
ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data");
ze.setXML(xmlData)
可用值如下:
{"MINIMUM", new Profile("MINIMUM", "urn:factur-x.eu:1p0:minimum")},
{"BASICWL", new Profile("BASICWL", "urn:factur-x.eu:1p0:basicwl")},
{"BASIC", new Profile("BASIC", "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic")},
{"EN16931", new Profile("EN16931", "urn:cen.eu:en16931:2017")},
{"EXTENDED", new Profile("EXTENDED", "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended")},
{"XRECHNUNG", new Profile("XRECHNUNG", "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.1")}
现在可以正常使用了!