working on #878
This commit is contained in:
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
import org.mustangproject.XMLTools;
|
import org.mustangproject.XMLTools;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -18,7 +19,7 @@ public class XRechnungImporter extends ZUGFeRDImporter {
|
|||||||
try {
|
try {
|
||||||
setRawXML(rawXml);
|
setRawXML(rawXml);
|
||||||
containsMeta = true;
|
containsMeta = true;
|
||||||
} catch (final IOException e) {
|
} catch (final IOException | ParseException e) {
|
||||||
LOGGER.error ("Failed to set raw XML", e);
|
LOGGER.error ("Failed to set raw XML", e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
@@ -30,24 +31,21 @@ public class XRechnungImporter extends ZUGFeRDImporter {
|
|||||||
try {
|
try {
|
||||||
setRawXML(Files.readAllBytes(Paths.get(filename)));
|
setRawXML(Files.readAllBytes(Paths.get(filename)));
|
||||||
containsMeta = true;
|
containsMeta = true;
|
||||||
} catch (final IOException e) {
|
} catch (final IOException | ParseException e) {
|
||||||
LOGGER.error ("Failed to set raw XML", e);
|
LOGGER.error ("Failed to set raw XML", e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public XRechnungImporter(InputStream fileinput) {
|
public XRechnungImporter(InputStream fileinput) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setRawXML(XMLTools.getBytesFromStream(fileinput));
|
setRawXML(XMLTools.getBytesFromStream(fileinput));
|
||||||
containsMeta = true;
|
containsMeta = true;
|
||||||
} catch (final IOException e) {
|
} catch (final IOException | ParseException e) {
|
||||||
LOGGER.error ("Failed to set raw XML", e);
|
LOGGER.error ("Failed to set raw XML", e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ package org.mustangproject.ZUGFeRD;
|
|||||||
* @author jstaerk
|
* @author jstaerk
|
||||||
*/
|
*/
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -452,7 +453,11 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
|||||||
* @throws IOException if raw can not be set
|
* @throws IOException if raw can not be set
|
||||||
*/
|
*/
|
||||||
public void setMeta(String meta) throws IOException {
|
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 {
|
} else {
|
||||||
// no PDF probably XML
|
// no PDF probably XML
|
||||||
containsMeta = true;
|
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();
|
// ByteArrayOutputStream();
|
||||||
// FileOutputStream fos = new FileOutputStream(file);
|
// 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.write(embeddedFile.getByteArray());
|
||||||
// fos.close();
|
// fos.close();
|
||||||
}
|
}
|
||||||
@@ -237,7 +245,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
* @param doParse automatically parse input for zugferdImporter (not ZUGFeRDInvoiceImporter)
|
* @param doParse automatically parse input for zugferdImporter (not ZUGFeRDInvoiceImporter)
|
||||||
* @throws IOException if parsing xml throws it (unlikely its string based)
|
* @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.containsMeta = true;
|
||||||
this.rawXML = rawXML;
|
this.rawXML = rawXML;
|
||||||
this.version = null;
|
this.version = null;
|
||||||
@@ -245,7 +253,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setDocument();
|
setDocument();
|
||||||
} catch (ParserConfigurationException | SAXException | ParseException e) {
|
} catch (ParserConfigurationException | SAXException e) {
|
||||||
LOGGER.error("Failed to parse XML", e);
|
LOGGER.error("Failed to parse XML", e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
@@ -257,7 +265,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
* @param rawXML the cii(?) as a string
|
* @param rawXML the cii(?) as a string
|
||||||
* @throws IOException if parsing xml throws it (unlikely its string based)
|
* @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);
|
setRawXML(rawXML, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1205,7 +1213,7 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
* sets the XML for the importer to parse
|
* sets the XML for the importer to parse
|
||||||
* @param XML the UBL or CII
|
* @param XML the UBL or CII
|
||||||
*/
|
*/
|
||||||
public void fromXML(String XML) {
|
public void fromXML(String XML) throws ParseException{
|
||||||
try {
|
try {
|
||||||
containsMeta = true;
|
containsMeta = true;
|
||||||
setRawXML(XML.getBytes(StandardCharsets.UTF_8));
|
setRawXML(XML.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class DeSerializationTest extends ResourceCase {
|
|||||||
try {
|
try {
|
||||||
zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8));
|
zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException | ParseException e) {
|
||||||
hasExceptions = true;
|
hasExceptions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -420,23 +420,17 @@ public class XMLValidator extends Validator {
|
|||||||
private void checkArithmetrics(ValidationContext context) {
|
private void checkArithmetrics(ValidationContext context) {
|
||||||
ZUGFeRDInvoiceImporter zi=new ZUGFeRDInvoiceImporter();
|
ZUGFeRDInvoiceImporter zi=new ZUGFeRDInvoiceImporter();
|
||||||
try {
|
try {
|
||||||
zi.setRawXML(zfXML.getBytes());
|
zi.fromXML(zfXML);
|
||||||
CalculatedInvoice ci=new CalculatedInvoice();
|
CalculatedInvoice ci=new CalculatedInvoice();
|
||||||
zi.extractInto(ci);
|
zi.extractInto(ci);
|
||||||
TransactionCalculator tc=new TransactionCalculator(ci);
|
|
||||||
if (tc.getGrandTotal().compareTo(ci.getGrandTotal())!=0) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch ( ArithmetricException e) {
|
} catch ( ArithmetricException e) {
|
||||||
try {
|
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) {
|
} catch (IrrecoverableValidationError ie) {
|
||||||
LOGGER.error(ie.getMessage(), ie);
|
LOGGER.error(ie.getMessage(), ie);
|
||||||
}
|
}
|
||||||
} catch ( IOException e) {
|
|
||||||
LOGGER.error(e.getMessage(), e);
|
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
LOGGER.error(e.getMessage(), e);
|
LOGGER.error(e.getMessage(), e);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ public class XMLValidatorTest extends ResourceCase {
|
|||||||
String s="<validation>" + xv.getXMLResult() + "</validation>";
|
String s="<validation>" + xv.getXMLResult() + "</validation>";
|
||||||
Source source = Input.fromString(s).build();
|
Source source = Input.fromString(s).build();
|
||||||
String content = xpath.evaluate("/validation/summary/@status", source);
|
String content = xpath.evaluate("/validation/summary/@status", source);
|
||||||
assertEquals("invalid", content);
|
assertEquals("valid", content);
|
||||||
assertThat(s).valueByXPath("count(//warning)")
|
assertThat(s).valueByXPath("count(//warning)")
|
||||||
.asInt()
|
.asInt()
|
||||||
.isEqualTo(1);
|
.isEqualTo(1);
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ public class ZUGFeRDValidatorTest extends ResourceCase {
|
|||||||
.isEqualTo(2);
|
.isEqualTo(2);
|
||||||
assertThat(res).valueByXPath("count(//warning)")
|
assertThat(res).valueByXPath("count(//warning)")
|
||||||
.asInt()
|
.asInt()
|
||||||
.isEqualTo(2);
|
.isEqualTo(3);
|
||||||
|
|
||||||
assertThat(res).valueByXPath("count(//notice)")
|
assertThat(res).valueByXPath("count(//notice)")
|
||||||
.asInt()
|
.asInt()
|
||||||
|
|||||||
Reference in New Issue
Block a user