From ac05158050a9ab49ff522212bb942bfb97f00673 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Fri, 2 Aug 2024 10:40:09 +0200 Subject: [PATCH] Add GlobalID to product When reading the node list to get the line items then add also the GlobalID to the product --- .../ZUGFeRD/ZUGFeRDImporter.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 4016e2a1..57f9a2d7 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -14,26 +14,8 @@ package org.mustangproject.ZUGFeRD; * @author jstaerk */ -import java.io.*; -import java.math.BigDecimal; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.text.SimpleDateFormat; -import java.util.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.apache.commons.io.IOUtils; import org.apache.pdfbox.Loader; +import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; @@ -48,6 +30,19 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.*; +import java.io.*; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.text.SimpleDateFormat; +import java.util.*; + public class ZUGFeRDImporter { private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDImporter.class); @@ -112,7 +107,6 @@ public class ZUGFeRDImporter { } - /** * Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. Errors are reported via exception handling. * @@ -977,7 +971,14 @@ public class ZUGFeRDImporter { break; case "SpecifiedTradeProduct": - + node = getNodeByName(nn.getChildNodes(), "GlobalID"); + if (node != null) { + SchemedID globalId = new SchemedID() + .setScheme(node.getAttributes() + .getNamedItem("schemeID").getNodeValue()) + .setId(getNodeValue(node)); + lineItem.getProduct().addGlobalID(globalId); + } node = getNodeByName(nn.getChildNodes(), "SellerAssignedID"); lineItem.getProduct().setSellerAssignedID(getNodeValue(node));