working on #878
This commit is contained in:
@@ -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,24 +31,21 @@ public class XRechnungImporter extends ZUGFeRDImporter {
|
||||
try {
|
||||
setRawXML(Files.readAllBytes(Paths.get(filename)));
|
||||
containsMeta = true;
|
||||
} catch (final IOException e) {
|
||||
LOGGER.error ("Failed to set raw XML", e);
|
||||
} catch (final IOException | ParseException e) {
|
||||
LOGGER.error ("Failed to set raw XML", e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
}
|
||||
|
||||
}
|
||||
public XRechnungImporter(InputStream fileinput) {
|
||||
super();
|
||||
|
||||
try {
|
||||
setRawXML(XMLTools.getBytesFromStream(fileinput));
|
||||
containsMeta = true;
|
||||
} catch (final IOException e) {
|
||||
LOGGER.error ("Failed to set raw XML", e);
|
||||
} catch (final IOException | ParseException e) {
|
||||
LOGGER.error ("Failed to set raw XML", e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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 {
|
||||
setRawXML(meta.getBytes());
|
||||
try {
|
||||
setRawXML(meta.getBytes());
|
||||
} catch (ParseException e) {
|
||||
LOGGER.error("Failed to parse", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -174,7 +174,12 @@ public class ZUGFeRDInvoiceImporter {
|
||||
} else {
|
||||
// no PDF probably XML
|
||||
containsMeta = true;
|
||||
setRawXML(XMLTools.getBytesFromStream(pdfStream));
|
||||
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);
|
||||
|
||||
setRawXML(embeddedFile.toByteArray());
|
||||
|
||||
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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user