Merge pull request #931 from langfr/FileAttachmentDescription

Enable setting and reading Additional Document Description.
This commit is contained in:
Jochen Staerk
2025-09-23 10:20:00 +02:00
committed by GitHub
3 changed files with 18 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ public class FileAttachment {
protected String filename; protected String filename;
protected String mimetype; protected String mimetype;
protected String relation = "Unspecified"; protected String relation = "Unspecified";
protected String description; protected String description = "Additional file attachment";
protected byte[] data; protected byte[] data;
@@ -21,19 +21,25 @@ public class FileAttachment {
} }
public FileAttachment(String filename, String mimetype, String relation, byte[] data, String description) {
this.filename = filename;
this.mimetype = mimetype;
this.relation = relation;
this.data = data;
this.description = description;
}
public FileAttachment(String filename, String mimetype, String relation, byte[] data) { public FileAttachment(String filename, String mimetype, String relation, byte[] data) {
this.filename = filename; this.filename = filename;
this.mimetype = mimetype; this.mimetype = mimetype;
this.relation = relation; this.relation = relation;
this.data = data; this.data = data;
this.description = "Additional file attachment";
} }
public FileAttachment(String filename, String mimetype, byte[] data) { public FileAttachment(String filename, String mimetype, byte[] data) {
this.filename = filename; this.filename = filename;
this.mimetype = mimetype; this.mimetype = mimetype;
this.data = data; this.data = data;
this.description = "Additional file attachment";
} }
public String getDescription() { public String getDescription() {

View File

@@ -994,6 +994,12 @@ public class ZUGFeRDInvoiceImporter {
NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
for (int i = 0; i < attachmentNodes.getLength(); i++) { for (int i = 0; i < attachmentNodes.getLength(); i++) {
FileAttachment fa = new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(), attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(), "Data", Base64.getMimeDecoder().decode(XMLTools.trimOrNull(attachmentNodes.item(i)))); FileAttachment fa = new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(), attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(), "Data", Base64.getMimeDecoder().decode(XMLTools.trimOrNull(attachmentNodes.item(i))));
NodeList nl = attachmentNodes.item(i).getParentNode().getChildNodes();
for (int j = 0; j < nl.getLength(); j++) {
if (nl.item(j).getLocalName() != null && nl.item(j).getLocalName().equals("Name")) {
fa.setDescription(nl.item(j).getTextContent());
}
}
zpp.embedFileInXML(fa); zpp.embedFileInXML(fa);
// filename = "Aufmass.png" mimeCode = "image/png" // filename = "Aufmass.png" mimeCode = "image/png"
//EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png" //EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png"

View File

@@ -102,7 +102,7 @@ public class XRTest extends TestCase {
BigDecimal amount = new BigDecimal(amountStr); BigDecimal amount = new BigDecimal(amountStr);
byte[] b = {12, 13}; byte[] b = {12, 13};
FileAttachment fe1 = new FileAttachment("one.pdf", "application/pdf", "Alternative", b); FileAttachment fe1 = new FileAttachment("one.pdf", "application/pdf", "Alternative", b,"Beschreibung");
Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").setEmail("sender@example.com").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test", "+49123456789", "test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890", "COBADEFXXX").setAccountName("kontoInhaber"))) .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").setEmail("sender@example.com").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test", "+49123456789", "test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890", "COBADEFXXX").setAccountName("kontoInhaber")))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setEmail("recipient@sample.org")) .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setEmail("recipient@sample.org"))
@@ -121,6 +121,7 @@ public class XRTest extends TestCase {
zf2p.setProfile(Profiles.getByName("XRechnung")); zf2p.setProfile(Profiles.getByName("XRechnung"));
zf2p.generateXML(i); zf2p.generateXML(i);
String theXML = new String(zf2p.getXML(), StandardCharsets.UTF_8); String theXML = new String(zf2p.getXML(), StandardCharsets.UTF_8);
System.out.println(theXML);
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice")); assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
assertTrue(theXML.contains("#SKONTO#")); assertTrue(theXML.contains("#SKONTO#"));
assertThat(theXML).valueByXPath("count(//*[local-name()='IncludedSupplyChainTradeLineItem'])") assertThat(theXML).valueByXPath("count(//*[local-name()='IncludedSupplyChainTradeLineItem'])")
@@ -158,7 +159,7 @@ public class XRTest extends TestCase {
assertEquals(attachedFiles.length, 1); assertEquals(attachedFiles.length, 1);
assertTrue(Arrays.equals(attachedFiles[0].getData(), b)); assertTrue(Arrays.equals(attachedFiles[0].getData(), b));
assertEquals("Beschreibung",attachedFiles[0].getDescription());
} }