add zugferdimporter.getversion, add total amount in metrics
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -68,12 +68,12 @@
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.2.11</version>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
private PDDocument doc;
|
||||
int ZFVersion;
|
||||
|
||||
private HashMap<String, byte[]> additionalXMLs = new HashMap<String, byte[]>();
|
||||
private HashMap<String, byte[]> additionalFiles = new HashMap<String, byte[]>();
|
||||
|
||||
|
||||
private boolean disableAutoClose;
|
||||
@@ -130,10 +130,21 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
init();
|
||||
}
|
||||
|
||||
public void addAdditonalXML(String filename, byte[] xml) {
|
||||
additionalXMLs.put(filename, xml);
|
||||
/**
|
||||
* Adds additional file attachments into the ZF
|
||||
* @param filename
|
||||
* @param filecontent
|
||||
*/
|
||||
public void addAdditionalFile(String filename, byte[] xml) {
|
||||
additionalFiles.put(filename, xml);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper function: get namespace for given zugferd or factur-x version
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getNamespaceForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
|
||||
@@ -147,6 +158,11 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper: returns the namespace prefix for the given zf/fx version number
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getPrefixForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "fx";
|
||||
@@ -155,6 +171,11 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper: return the name of the file attachment for the given zf/fx version
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getFilenameForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "factur-x.xml";
|
||||
@@ -374,8 +395,8 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
PDFAttachGenericFile(doc, filename, "Alternative",
|
||||
"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
|
||||
"text/xml", xmlProvider.getXML());
|
||||
for (String filenameAdditional : additionalXMLs.keySet()) {
|
||||
PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalXMLs.get(filenameAdditional));
|
||||
for (String filenameAdditional : additionalFiles.keySet()) {
|
||||
PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalFiles.get(filenameAdditional));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,7 +539,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ZUGFeRD conformance level (override).
|
||||
* Sets the ZUGFeRD profile.
|
||||
*
|
||||
* @param zUGFeRDConformanceLevel the new conformance level
|
||||
* @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
|
||||
@@ -532,7 +553,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ZUGFeRD conformance level (override).
|
||||
* Sets the ZUGFeRD profile.
|
||||
*
|
||||
* @param zUGFeRDConformanceLevel the new conformance level
|
||||
* @deprecated Use {@link #setConformanceLevel(PDFAConformanceLevel)} instead
|
||||
@@ -572,6 +593,10 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
XMPSchemaPDFAExtensions pdfaex = new XMPSchemaPDFAExtensions(this, metadata, ZFVersion, attachZUGFeRDHeaders);
|
||||
pdfaex.setZUGFeRDVersion(ZFVersion);
|
||||
metadata.addSchema(pdfaex);
|
||||
for (String filenameAdditional : additionalFiles.keySet()) {
|
||||
XMPSchemaPDFAExtensionsAdditionalData pdfaexadd = new XMPSchemaPDFAExtensionsAdditionalData(metadata);
|
||||
metadata.addSchema(pdfaexadd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
|
||||
import org.mustangproject.toecount.Toecount;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@@ -163,21 +162,6 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private void prettyPrint(Document document) throws TransformerException {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = null;
|
||||
try {
|
||||
transformer = tf.newTransformer();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(new DOMSource(document), new StreamResult(writer));
|
||||
String output = writer.getBuffer().toString();//.replaceAll("\n|\r", "");
|
||||
System.err.println(output);
|
||||
}
|
||||
|
||||
private Document getDocument() { return document; }
|
||||
|
||||
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
||||
@@ -368,6 +352,16 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
|
||||
public int getVersion() throws Exception {
|
||||
if (!containsMeta) throw new Exception("Not yet parsed");
|
||||
if (getUTF8().contains("<rsm:CrossIndustryDocument")) {
|
||||
return 1;
|
||||
} else if (getUTF8().contains("<rsm:CrossIndustryInvoice")) {
|
||||
return 2;
|
||||
}
|
||||
throw new Exception("ZUGFeRD version could not be determined");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return return UTF8 XML (without BOM) of the invoice
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||
|
||||
public class FileChecker {
|
||||
@@ -53,6 +55,7 @@ public class FileChecker {
|
||||
try {
|
||||
if (zi.canParse()) {
|
||||
thisRun.incZUGFeRDCount();
|
||||
thisRun.incTotal(new BigDecimal(zi.getAmount()));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class StatRun {
|
||||
private int pdfCount = 0;
|
||||
private int horseCount = 0;
|
||||
private int fileCount = 0;
|
||||
private int dirCount = 0;
|
||||
private BigDecimal total = BigDecimal.ZERO;
|
||||
private boolean checkFileExt = true;
|
||||
|
||||
public void ignoreFileExtension() {
|
||||
@@ -73,8 +76,8 @@ public class StatRun {
|
||||
public String getSummaryLine() {
|
||||
|
||||
return "\r\n===================================================================\r\n" + String.format(
|
||||
"Files:\t%d\tDirs:\t%d\tPDF:\t%d\tZUGFeRD:\t%d\r\n",
|
||||
getFileCount(), getDirCount(), getPDFCount(), getZUGFeRDCount());
|
||||
"Files:\t%d\tDirs:\t%d\tPDF:\t%d\tZUGFeRD:\t%d\tTotal:\t%s\r\n",
|
||||
getFileCount(), getDirCount(), getPDFCount(), getZUGFeRDCount(), total.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -87,5 +90,10 @@ public class StatRun {
|
||||
return ".";
|
||||
}
|
||||
|
||||
public void incTotal(BigDecimal delta) {
|
||||
total=total.add(delta);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,24 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator;
|
||||
|
||||
/***
|
||||
* This is the command line interface to mustangproject
|
||||
*
|
||||
@@ -25,24 +43,6 @@ package org.mustangproject.toecount;
|
||||
|
||||
import com.sanityinc.jargs.CmdLineParser;
|
||||
import com.sanityinc.jargs.CmdLineParser.Option;
|
||||
import org.mustangproject.ZUGFeRD.*;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Toecount {
|
||||
// build with: /opt/local/bin/mvn clean compile assembly:single
|
||||
@@ -454,7 +454,7 @@ public class Toecount {
|
||||
} else {
|
||||
System.out.println("ZUGFeRD XML set to " + xmlName);
|
||||
}
|
||||
|
||||
|
||||
if (outName == null) {
|
||||
outName = getFilenameFromUser("Ouput PDF", "invoice.ZUGFeRD.pdf", "pdf", false, true);
|
||||
} else {
|
||||
|
||||
@@ -230,6 +230,13 @@ public class MustangReaderWriterEdgeTest extends MustangReaderTestCase {
|
||||
assertEquals(zi.getKTO(), getTradeSettlementPayment()[0].getOwnKto());
|
||||
assertEquals(zi.getHolder(), getOwnOrganisationName());
|
||||
assertEquals(zi.getForeignReference(), getNumber());
|
||||
try {
|
||||
assertEquals(zi.getVersion(), 1);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -75,11 +76,10 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
return "Ecke 12";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IZUGFeRDExportableContact getOwnContact() {
|
||||
return new SenderContact();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,8 +115,10 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
@Override
|
||||
public IZUGFeRDExportableItem[] getZFItems() {
|
||||
Item[] allItems = new Item[3];
|
||||
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", new BigDecimal("7.000000"));
|
||||
Product balloonProduct = new Product("", "Bestellerweiterung für E&F Umbau", "C62", new BigDecimal("19.000000"));// test for issue 103
|
||||
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR",
|
||||
new BigDecimal("7.000000"));
|
||||
Product balloonProduct = new Product("", "Bestellerweiterung für E&F Umbau", "C62",
|
||||
new BigDecimal("19.000000"));// test for issue 103
|
||||
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
|
||||
|
||||
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
|
||||
@@ -167,26 +169,25 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
return new TestSuite(ZF2EdgeTest.class);
|
||||
}
|
||||
|
||||
|
||||
// //////// TESTS //////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //////// TESTS
|
||||
// //////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf}, adds metadata,
|
||||
* writes to @{code ./target/testout-*} and then imports to check the values.
|
||||
* The exporter test bases on @{code
|
||||
* ./src/test/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf}, adds
|
||||
* metadata, writes to @{code ./target/testout-*} and then imports to check the
|
||||
* values.
|
||||
*/
|
||||
public void testEdgeExport() {
|
||||
|
||||
// the writing part
|
||||
|
||||
try (InputStream SOURCE_PDF =
|
||||
this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf");
|
||||
try (InputStream SOURCE_PDF = this.getClass()
|
||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf");
|
||||
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory()
|
||||
.setProducer("My Application")
|
||||
.setCreator(System.getProperty("user.name"))
|
||||
.setZUGFeRDVersion(2)
|
||||
.ignorePDFAErrors()
|
||||
.load(SOURCE_PDF)) {
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory().setProducer("My Application")
|
||||
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
|
||||
.load(SOURCE_PDF)) {
|
||||
ze.PDFattachZugferdFile(this);
|
||||
String theXML = new String(ze.getProvider().getXML());
|
||||
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
|
||||
@@ -204,6 +205,40 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
|
||||
assertEquals(zi.getIBAN(), getTradeSettlementPayment()[0].getOwnIBAN());
|
||||
assertEquals(zi.getHolder(), getOwnOrganisationName());
|
||||
assertEquals(zi.getForeignReference(), getNumber());
|
||||
try {
|
||||
assertEquals(zi.getVersion(), 2);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The exporter test bases on @{code
|
||||
* ./src/test/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf}, adds
|
||||
* metadata, writes to @{code ./target/testout-*} and then imports to check the
|
||||
* values.
|
||||
*/
|
||||
public void testOutpuStreamExport() {
|
||||
|
||||
// the writing part
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
try (InputStream SOURCE_PDF = this.getClass()
|
||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf");
|
||||
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory().setProducer("My Application")
|
||||
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
|
||||
.load(SOURCE_PDF)) {
|
||||
ze.PDFattachZugferdFile(this);
|
||||
String theXML = new String(ze.getProvider().getXML());
|
||||
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
|
||||
ze.export(bos);
|
||||
} catch (IOException e) {
|
||||
fail("IOException should not be raised in testEdgeExport");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user