This commit is contained in:
jstaerk
2025-06-30 10:53:52 +02:00
parent 1b174e243f
commit 8ce3d21eae
7 changed files with 32 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
@@ -18,7 +19,7 @@ public class XRechnungImporter extends ZUGFeRDImporter {
try {
setRawXML(rawXml);
containsMeta = true;
} catch (final IOException e) {
} catch (final IOException | ParseException e) {
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}
@@ -30,7 +31,7 @@ public class XRechnungImporter extends ZUGFeRDImporter {
try {
setRawXML(Files.readAllBytes(Paths.get(filename)));
containsMeta = true;
} catch (final IOException e) {
} catch (final IOException | ParseException e) {
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}
@@ -38,16 +39,13 @@ public class XRechnungImporter extends ZUGFeRDImporter {
}
public XRechnungImporter(InputStream fileinput) {
super();
try {
setRawXML(XMLTools.getBytesFromStream(fileinput));
containsMeta = true;
} catch (final IOException e) {
} catch (final IOException | ParseException e) {
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}
}

View File

@@ -14,6 +14,7 @@ package org.mustangproject.ZUGFeRD;
* @author jstaerk
*/
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -452,7 +453,11 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
* @throws IOException if raw can not be set
*/
public void setMeta(String meta) throws IOException {
try {
setRawXML(meta.getBytes());
} catch (ParseException e) {
LOGGER.error("Failed to parse", e);
}
}

View File

@@ -174,7 +174,12 @@ public class ZUGFeRDInvoiceImporter {
} else {
// no PDF probably XML
containsMeta = true;
try {
setRawXML(XMLTools.getBytesFromStream(pdfStream));
} catch(ParseException e) {
LOGGER.error("Failed to parse PDF", e);
}
}
}
@@ -219,8 +224,11 @@ public class ZUGFeRDInvoiceImporter {
// ByteArrayOutputStream();
// FileOutputStream fos = new FileOutputStream(file);
try {
setRawXML(embeddedFile.toByteArray());
} catch (ParseException e) {
LOGGER.error("Failed to parse XML", e);
}
// fos.write(embeddedFile.getByteArray());
// fos.close();
}
@@ -237,7 +245,7 @@ public class ZUGFeRDInvoiceImporter {
* @param doParse automatically parse input for zugferdImporter (not ZUGFeRDInvoiceImporter)
* @throws IOException if parsing xml throws it (unlikely its string based)
*/
public void setRawXML(byte[] rawXML, boolean doParse) throws IOException {
public void setRawXML(byte[] rawXML, boolean doParse) throws IOException, ParseException {
this.containsMeta = true;
this.rawXML = rawXML;
this.version = null;
@@ -245,7 +253,7 @@ public class ZUGFeRDInvoiceImporter {
try {
setDocument();
} catch (ParserConfigurationException | SAXException | ParseException e) {
} catch (ParserConfigurationException | SAXException e) {
LOGGER.error("Failed to parse XML", e);
throw new ZUGFeRDExportException(e);
}
@@ -257,7 +265,7 @@ public class ZUGFeRDInvoiceImporter {
* @param rawXML the cii(?) as a string
* @throws IOException if parsing xml throws it (unlikely its string based)
*/
public void setRawXML(byte[] rawXML) throws IOException {
public void setRawXML(byte[] rawXML) throws IOException, ParseException {
setRawXML(rawXML, true);
}
@@ -1205,7 +1213,7 @@ public class ZUGFeRDInvoiceImporter {
* sets the XML for the importer to parse
* @param XML the UBL or CII
*/
public void fromXML(String XML) {
public void fromXML(String XML) throws ParseException{
try {
containsMeta = true;
setRawXML(XML.getBytes(StandardCharsets.UTF_8));

View File

@@ -79,7 +79,7 @@ public class DeSerializationTest extends ResourceCase {
try {
zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8));
} catch (IOException e) {
} catch (IOException | ParseException e) {
hasExceptions = true;
}

View File

@@ -420,23 +420,17 @@ public class XMLValidator extends Validator {
private void checkArithmetrics(ValidationContext context) {
ZUGFeRDInvoiceImporter zi=new ZUGFeRDInvoiceImporter();
try {
zi.setRawXML(zfXML.getBytes());
zi.fromXML(zfXML);
CalculatedInvoice ci=new CalculatedInvoice();
zi.extractInto(ci);
TransactionCalculator tc=new TransactionCalculator(ci);
if (tc.getGrandTotal().compareTo(ci.getGrandTotal())!=0) {
}
} catch ( ArithmetricException e) {
try {
context.addResultItem(new ValidationResultItem(ESeverity.warning, "Can not arithmetrically reproduce the invoice.").setSection(10));
context.addResultItem(new ValidationResultItem(ESeverity.warning, "Arithmetical issue:"+e.getMessage()).setSection(10));
} catch (IrrecoverableValidationError ie) {
LOGGER.error(ie.getMessage(), ie);
}
} catch ( IOException e) {
LOGGER.error(e.getMessage(), e);
} catch (XPathExpressionException e) {
LOGGER.error(e.getMessage(), e);
} catch (ParseException e) {

View File

@@ -297,7 +297,7 @@ public class XMLValidatorTest extends ResourceCase {
String s="<validation>" + xv.getXMLResult() + "</validation>";
Source source = Input.fromString(s).build();
String content = xpath.evaluate("/validation/summary/@status", source);
assertEquals("invalid", content);
assertEquals("valid", content);
assertThat(s).valueByXPath("count(//warning)")
.asInt()
.isEqualTo(1);

View File

@@ -219,7 +219,7 @@ public class ZUGFeRDValidatorTest extends ResourceCase {
.isEqualTo(2);
assertThat(res).valueByXPath("count(//warning)")
.asInt()
.isEqualTo(2);
.isEqualTo(3);
assertThat(res).valueByXPath("count(//notice)")
.asInt()