Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZUGFeRD/mustangproject
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Jul 11, 2024
2 parents 5d5b316 + 4d53235 commit affc468
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.dom4j.Document;
import org.dom4j.DocumentException;
Expand All @@ -34,8 +32,11 @@
import org.dom4j.io.XMLWriter;
import org.mustangproject.EStandard;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UBLDAPullProvider implements IXMLProvider {
private static final Logger LOGGER = LoggerFactory.getLogger (UBLDAPullProvider.class);

protected IExportableTransaction trans;
protected TransactionCalculator calc;
Expand Down Expand Up @@ -118,7 +119,7 @@ public byte[] getXML() {
try {
document = DocumentHelper.parseText(new String(ublData));
} catch (final DocumentException e1) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e1);
LOGGER.error ("Failed to parse UBL", e1);
}
try {
final OutputFormat format = OutputFormat.createPrettyPrint();
Expand All @@ -128,7 +129,7 @@ public byte[] getXML() {
res = sw.toString().getBytes(StandardCharsets.UTF_8);

} catch (final IOException e) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to write XML", e);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class XRechnungImporter extends ZUGFeRDImporter {
private static final Logger LOGGER = LoggerFactory.getLogger (XRechnungImporter.class);

public XRechnungImporter(byte[] rawXml) {
super();
Expand All @@ -18,7 +19,7 @@ public XRechnungImporter(byte[] rawXml) {
setRawXML(rawXml);
containsMeta = true;
} catch (final IOException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}
}
Expand All @@ -30,7 +31,7 @@ public XRechnungImporter(String filename) {
setRawXML(Files.readAllBytes(Paths.get(filename)));
containsMeta = true;
} catch (final IOException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}

Expand All @@ -42,7 +43,7 @@ public XRechnungImporter(InputStream fileinput) {
setRawXML(XMLTools.getBytesFromStream(fileinput));
containsMeta = true;
} catch (final IOException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to set raw XML", e);
throw new ZUGFeRDExportException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZUGFeRD1PullProvider extends ZUGFeRD2PullProvider {

private static final Logger LOGGER = LoggerFactory.getLogger (ZUGFeRD1PullProvider.class);

//// MAIN CLASS

Expand Down Expand Up @@ -93,7 +93,7 @@ public byte[] getXML() {
try {
document = DocumentHelper.parseText(new String(zugferdData));
} catch (final DocumentException e1) {
Logger.getLogger(ZUGFeRD1PullProvider.class.getName()).log(Level.SEVERE, null, e1);
LOGGER.error ("Failed to parse ZUGFeRD data", e1);
}
try {
final OutputFormat format = OutputFormat.createPrettyPrint();
Expand All @@ -103,7 +103,7 @@ public byte[] getXML() {
res = sw.toString().getBytes(StandardCharsets.UTF_8);

} catch (final IOException e) {
Logger.getLogger(ZUGFeRD1PullProvider.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to write ZUGFeRD data", e);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.dom4j.Document;
Expand All @@ -48,8 +46,11 @@
import org.mustangproject.IncludedNote;
import org.mustangproject.XMLTools;
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZUGFeRD2PullProvider implements IXMLProvider {
private static final Logger LOGGER = LoggerFactory.getLogger (ZUGFeRD2PullProvider.class);

protected byte[] zugferdData;
protected IExportableTransaction trans;
Expand Down Expand Up @@ -91,7 +92,7 @@ public byte[] getXML() {
try {
document = DocumentHelper.parseText(new String(zugferdData));
} catch (final DocumentException e1) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e1);
LOGGER.error ("Failed to parse ZUGFeRD data", e1);
}
try {
final OutputFormat format = OutputFormat.createPrettyPrint();
Expand All @@ -101,7 +102,7 @@ public byte[] getXML() {
res = sw.toString().getBytes(StandardCharsets.UTF_8);

} catch (final IOException e) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to write ZUGFeRD data", e);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -52,12 +49,15 @@
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ZUGFeRDImporter {
private static final Logger LOGGER = LoggerFactory.getLogger (ZUGFeRDImporter.class);

/**
* if metadata has been found
Expand Down Expand Up @@ -90,7 +90,7 @@ public ZUGFeRDImporter(String pdfFilename) {
try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) {
extractLowLevel(bis);
} catch (final IOException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to extract ZUGFeRD data", e);
throw new ZUGFeRDExportException(e);
}
}
Expand All @@ -100,7 +100,7 @@ public ZUGFeRDImporter(InputStream pdfStream) {
try {
extractLowLevel(pdfStream);
} catch (final IOException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to extract ZUGFeRD data", e);
throw new ZUGFeRDExportException(e);
}
}
Expand All @@ -127,7 +127,7 @@ private void extractLowLevel(InputStream inStream) throws IOException {
//start

if (doc.getDocumentCatalog() == null || doc.getDocumentCatalog().getMetadata() == null) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.INFO, "no-xmlpart");
LOGGER.info("no-xmlpart");
return;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public void setRawXML(byte[] rawXML) throws IOException {
try {
setDocument();
} catch (ParserConfigurationException | SAXException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to parse XML", e);
throw new ZUGFeRDExportException(e);
}
}
Expand All @@ -236,7 +236,7 @@ protected String extractString(String xpathStr) {
final XPath xpath = xpathFact.newXPath();
result = xpath.evaluate(xpathStr, document);
} catch (final XPathExpressionException e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error ("Failed to evaluate XPath", e);
throw new ZUGFeRDExportException(e);
}
return result;
Expand Down Expand Up @@ -301,8 +301,7 @@ public String getInvoiceCurrencyCode() {
return extractString("//*[local-name() = 'ApplicableHeaderTradeSettlement']//*[local-name() = 'InvoiceCurrencyCode']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);

// Exception was already logged
return "";
}
}
Expand Down Expand Up @@ -336,7 +335,7 @@ private String extractIssuerAssignedID(String propertyName) {
return extractString("//*[local-name() = '" + propertyName + "']//*[local-name() = 'IssuerAssignedID']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -359,7 +358,7 @@ public String getIssueDate() {
return extractString("//*[local-name() = 'ExchangedDocument']//*[local-name() = 'IssueDateTime']//*[local-name() = 'DateTimeString']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand Down Expand Up @@ -391,7 +390,7 @@ public String getTaxBasisTotalAmount() {
return extractString("//*[local-name() = 'SpecifiedTradeSettlementHeaderMonetarySummation']//*[local-name() = 'TaxBasisTotalAmount']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -407,7 +406,7 @@ public String getTaxTotalAmount() {
return extractString("//*[local-name() = 'SpecifiedTradeSettlementHeaderMonetarySummation']//*[local-name() = 'TaxTotalAmount']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -423,7 +422,7 @@ public String getRoundingAmount() {
return extractString("//*[local-name() = 'SpecifiedTradeSettlementHeaderMonetarySummation']//*[local-name() = 'RoundingAmount']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -439,7 +438,7 @@ public String getPaidAmount() {
return extractString("//*[local-name() = 'SpecifiedTradeSettlementHeaderMonetarySummation']//*[local-name() = 'TotalPrepaidAmount']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand Down Expand Up @@ -477,7 +476,7 @@ public String getIncludedNote() {
return extractString("//*[local-name() = 'ExchangedDocument']//*[local-name() = 'IncludedNote']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand Down Expand Up @@ -508,7 +507,7 @@ public String getLineTotalAmount() {
return extractString("//*[local-name() = 'SpecifiedTradeSettlementHeaderMonetarySummation']//*[local-name() = 'LineTotalAmount']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -531,7 +530,7 @@ public String getTaxPointDate() {
return extractString("//*[local-name() = 'ActualDeliverySupplyChainEvent']//*[local-name() = 'OccurrenceDateTime']//*[local-name() = 'DateTimeString']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -547,7 +546,7 @@ public String getInvoiceID() {
return extractString("//*[local-name() = 'ExchangedDocument']//*[local-name() = 'ID']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -564,7 +563,7 @@ public String getDocumentCode() {
return extractString("//*[local-name() = 'ExchangedDocument']/*[local-name() = 'TypeCode']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand All @@ -581,7 +580,7 @@ public String getReference() {
return extractString("//*[local-name() = 'ApplicableHeaderTradeAgreement']/*[local-name() = 'BuyerReference']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return "";
}
}
Expand Down Expand Up @@ -806,7 +805,7 @@ public PostalTradeAddress getBuyerTradePartyAddress() {
nl = getNodeListByPath("//*[local-name() = 'CrossIndustryInvoice']//*[local-name() = 'SupplyChainTradeTransaction']//*[local-name() = 'ApplicableHeaderTradeAgreement']//*[local-name() = 'BuyerTradeParty']//*[local-name() = 'PostalTradeAddress']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return null;
}

Expand All @@ -828,7 +827,7 @@ public PostalTradeAddress getSellerTradePartyAddress() {
nl = getNodeListByPath("//*[local-name() = 'CrossIndustryInvoice']//*[local-name() = 'SupplyChainTradeTransaction']//*[local-name() = 'ApplicableHeaderTradeAgreement']//*[local-name() = 'SellerTradeParty']//*[local-name() = 'PostalTradeAddress']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return null;
}

Expand All @@ -850,7 +849,7 @@ public PostalTradeAddress getDeliveryTradePartyAddress() {
nl = getNodeListByPath("//*[local-name() = 'CrossIndustryInvoice']//*[local-name() = 'SupplyChainTradeTransaction']//*[local-name() = 'ApplicableHeaderTradeDelivery']//*[local-name() = 'ShipToTradeParty']//*[local-name() = 'PostalTradeAddress']");
}
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
return null;
}

Expand Down Expand Up @@ -1063,7 +1062,7 @@ public List<Node> getLineItemNodes() {
nl = getNodeListByPath("//*[local-name() = 'IncludedSupplyChainTradeLineItem']");

} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
// Exception was already logged
}

for (int i = 0; i < nl.getLength(); i++) {
Expand Down Expand Up @@ -1110,7 +1109,7 @@ public NodeList getNodeListByPath(String path) {
final XPathExpression xpr = xPath.compile(s);
return (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
} catch (final Exception e) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
LOGGER.error("Failed to evaluate XPath", e);
return null;
}
}
Expand Down
Loading

0 comments on commit affc468

Please sign in to comment.