Merge branch 'master' of github.com:ZUGFeRD/mustangproject
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
*********************************************************************** */
|
*********************************************************************** */
|
||||||
package org.mustangproject.ZUGFeRD;
|
package org.mustangproject.ZUGFeRD;
|
||||||
|
|
||||||
public class CustomXMLProvider implements IXMLProvider {
|
public class CustomXMLProvider implements IXMLProvider, IProfileProvider {
|
||||||
|
|
||||||
protected byte[] zugferdData;
|
protected byte[] zugferdData;
|
||||||
|
|
||||||
@@ -48,4 +48,14 @@ public class CustomXMLProvider implements IXMLProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProfile() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ package org.mustangproject.ZUGFeRD;
|
|||||||
public interface IProfileProvider {
|
public interface IProfileProvider {
|
||||||
|
|
||||||
public String getProfile();
|
public String getProfile();
|
||||||
|
|
||||||
|
public void setProfile(ZUGFeRDConformanceLevel level);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,4 +246,15 @@ public interface IZUGFeRDExportableTransaction {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the ID of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement
|
||||||
|
* @return the ID of the document
|
||||||
|
*/
|
||||||
|
default String getBuyerOrderReferencedDocumentID() { return null; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the issue timestamp of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement
|
||||||
|
* @return the IssueDateTime in format CCYY-MM-DDTHH:MM:SS
|
||||||
|
*/
|
||||||
|
default String getBuyerOrderReferencedDocumentIssueDateTime() { return null; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.mustangproject.ZUGFeRD;
|
package org.mustangproject.ZUGFeRD;
|
||||||
|
|
||||||
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
|
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
|
||||||
|
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
|
||||||
import org.mustangproject.ZUGFeRD.model.ZFNamespacePrefixMapper;
|
import org.mustangproject.ZUGFeRD.model.ZFNamespacePrefixMapper;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
@@ -27,13 +28,27 @@ import javax.xml.bind.JAXBException;
|
|||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
public class ZUGFeRD1PullProvider implements IXMLProvider {
|
public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
|
||||||
|
|
||||||
|
|
||||||
protected byte[] zugferdData;
|
protected byte[] zugferdData;
|
||||||
private Marshaller marshaller;
|
private Marshaller marshaller;
|
||||||
|
|
||||||
private boolean isTest;
|
private boolean isTest;
|
||||||
|
private ZUGFeRDConformanceLevel level;
|
||||||
|
|
||||||
|
|
||||||
|
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProfile() {
|
||||||
|
switch (level) {
|
||||||
|
case BASIC: return DocumentContextParameterTypeConstants.BASIC;
|
||||||
|
case COMFORT: return DocumentContextParameterTypeConstants.COMFORT;
|
||||||
|
default: return DocumentContextParameterTypeConstants.EXTENDED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,7 +74,7 @@ public class ZUGFeRD1PullProvider implements IXMLProvider {
|
|||||||
private String createZugferdXMLForTransaction(IZUGFeRDExportableTransaction trans) {
|
private String createZugferdXMLForTransaction(IZUGFeRDExportableTransaction trans) {
|
||||||
|
|
||||||
JAXBElement<CrossIndustryDocumentType> jaxElement =
|
JAXBElement<CrossIndustryDocumentType> jaxElement =
|
||||||
new ZUGFeRDTransactionModelConverter(trans).withTest(isTest).convertToModel();
|
new ZUGFeRDTransactionModelConverter(trans).withTest(isTest).withProfile(getProfile()).convertToModel();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return marshalJaxToXMLString(jaxElement);
|
return marshalJaxToXMLString(jaxElement);
|
||||||
|
|||||||
@@ -71,6 +71,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
|||||||
|
|
||||||
protected byte[] zugferdData;
|
protected byte[] zugferdData;
|
||||||
private IZUGFeRDExportableTransaction trans;
|
private IZUGFeRDExportableTransaction trans;
|
||||||
|
private ZUGFeRDConformanceLevel level;
|
||||||
|
|
||||||
|
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enables the flag to indicate a test invoice in the XML structure
|
* enables the flag to indicate a test invoice in the XML structure
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class ZUGFeRDExporter implements Closeable {
|
|||||||
*/
|
*/
|
||||||
public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
|
public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
|
||||||
prepareDocument();
|
prepareDocument();
|
||||||
|
((IProfileProvider) xmlProvider).setProfile(profile);
|
||||||
xmlProvider.generateXML(trans);
|
xmlProvider.generateXML(trans);
|
||||||
String filename = getFilenameForVersion(ZFVersion);
|
String filename = getFilenameForVersion(ZFVersion);
|
||||||
PDFAttachGenericFile(doc, filename, "Alternative",
|
PDFAttachGenericFile(doc, filename, "Alternative",
|
||||||
|
|||||||
@@ -31,51 +31,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.xml.bind.JAXBElement;
|
import javax.xml.bind.JAXBElement;
|
||||||
|
|
||||||
import org.mustangproject.ZUGFeRD.model.AmountType;
|
import org.mustangproject.ZUGFeRD.model.*;
|
||||||
import org.mustangproject.ZUGFeRD.model.CodeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.CountryIDType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.CreditorFinancialAccountType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.CreditorFinancialInstitutionType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DateTimeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DateTimeTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DocumentCodeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.DocumentLineDocumentType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.ExchangedDocumentContextType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.ExchangedDocumentType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.IDType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.IndicatorType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.LogisticsServiceChargeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.NoteType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.NoteTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.ObjectFactory;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.PercentType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.QuantityType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainEventType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainTradeAgreementType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainTradeDeliveryType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainTradeLineItemType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainTradeSettlementType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.SupplyChainTradeTransactionType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TaxRegistrationType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TaxRegistrationTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TaxTypeCodeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TaxTypeCodeTypeConstants;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TextType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeAddressType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeAllowanceChargeType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradePartyType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradePaymentTermsType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradePriceType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeProductType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeSettlementMonetarySummationType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeSettlementPaymentMeansType;
|
|
||||||
import org.mustangproject.ZUGFeRD.model.TradeTaxType;
|
|
||||||
|
|
||||||
class ZUGFeRDTransactionModelConverter {
|
class ZUGFeRDTransactionModelConverter {
|
||||||
private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
|
private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||||
@@ -85,6 +41,7 @@ class ZUGFeRDTransactionModelConverter {
|
|||||||
private final Totals totals;
|
private final Totals totals;
|
||||||
private boolean isTest;
|
private boolean isTest;
|
||||||
private String currency = "EUR";
|
private String currency = "EUR";
|
||||||
|
private String profile;
|
||||||
|
|
||||||
|
|
||||||
ZUGFeRDTransactionModelConverter(IZUGFeRDExportableTransaction trans) {
|
ZUGFeRDTransactionModelConverter(IZUGFeRDExportableTransaction trans) {
|
||||||
@@ -114,7 +71,7 @@ class ZUGFeRDTransactionModelConverter {
|
|||||||
DocumentContextParameterType contextParameter = xmlFactory
|
DocumentContextParameterType contextParameter = xmlFactory
|
||||||
.createDocumentContextParameterType();
|
.createDocumentContextParameterType();
|
||||||
IDType idType = xmlFactory.createIDType();
|
IDType idType = xmlFactory.createIDType();
|
||||||
idType.setValue(DocumentContextParameterTypeConstants.EXTENDED);
|
idType.setValue(profile);
|
||||||
contextParameter.setID(idType);
|
contextParameter.setID(idType);
|
||||||
context.getGuidelineSpecifiedDocumentContextParameter().add(
|
context.getGuidelineSpecifiedDocumentContextParameter().add(
|
||||||
contextParameter);
|
contextParameter);
|
||||||
@@ -200,6 +157,15 @@ class ZUGFeRDTransactionModelConverter {
|
|||||||
tradeAgreement.setBuyerTradeParty(getBuyer());
|
tradeAgreement.setBuyerTradeParty(getBuyer());
|
||||||
tradeAgreement.setSellerTradeParty(getSeller());
|
tradeAgreement.setSellerTradeParty(getSeller());
|
||||||
|
|
||||||
|
if (trans.getBuyerOrderReferencedDocumentID() != null) {
|
||||||
|
ReferencedDocumentType refdoc = xmlFactory.createReferencedDocumentType();
|
||||||
|
IDType id = xmlFactory.createIDType();
|
||||||
|
id.setValue(trans.getBuyerOrderReferencedDocumentID());
|
||||||
|
refdoc.getID().add(id);
|
||||||
|
refdoc.setIssueDateTime(trans.getBuyerOrderReferencedDocumentIssueDateTime());
|
||||||
|
tradeAgreement.getBuyerOrderReferencedDocument().add(refdoc);
|
||||||
|
}
|
||||||
|
|
||||||
return tradeAgreement;
|
return tradeAgreement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,6 +921,11 @@ class ZUGFeRDTransactionModelConverter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZUGFeRDTransactionModelConverter withProfile(String profile) {
|
||||||
|
this.profile = profile;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private class LineCalc {
|
private class LineCalc {
|
||||||
|
|
||||||
private BigDecimal totalGross;
|
private BigDecimal totalGross;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
package org.mustangproject.ZUGFeRD.model;
|
package org.mustangproject.ZUGFeRD.model;
|
||||||
|
|
||||||
public class DocumentContextParameterTypeConstants {
|
public class DocumentContextParameterTypeConstants {
|
||||||
|
public static final String BASIC = "urn:ferd:CrossIndustryDocument:invoice:1p0:basic";
|
||||||
public static final String COMFORT = "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort";
|
public static final String COMFORT = "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort";
|
||||||
public static final String EXTENDED = "urn:ferd:CrossIndustryDocument:invoice:1p0:extended";
|
public static final String EXTENDED = "urn:ferd:CrossIndustryDocument:invoice:1p0:extended";
|
||||||
// this does not look complete :-/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.apache.xmpbox.xml.DomXmpParser;
|
|||||||
import org.apache.xmpbox.xml.XmpParsingException;
|
import org.apache.xmpbox.xml.XmpParsingException;
|
||||||
import org.junit.FixMethodOrder;
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -349,7 +350,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
|||||||
|
|
||||||
// the writing part
|
// the writing part
|
||||||
try (InputStream SOURCE_PDF = this.getClass()
|
try (InputStream SOURCE_PDF = this.getClass()
|
||||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
||||||
|
|
||||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) {
|
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) {
|
||||||
|
|
||||||
@@ -366,7 +367,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
|||||||
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
|
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
|
||||||
// assertFalse(pdfContent.indexOf("<pdfaSchema:prefix>zf</pdfaSchema:prefix>") == -1);
|
// assertFalse(pdfContent.indexOf("<pdfaSchema:prefix>zf</pdfaSchema:prefix>") == -1);
|
||||||
// assertFalse(pdfContent.indexOf("urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#") == -1);
|
// assertFalse(pdfContent.indexOf("urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#") == -1);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail("IOException should not happen in testZExport");
|
fail("IOException should not happen in testZExport");
|
||||||
}
|
}
|
||||||
@@ -384,6 +385,37 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
|||||||
assertEquals(zi.getForeignReference(), getNumber());
|
assertEquals(zi.getForeignReference(), getNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick and dirty copy of testZExport to check if v1 files contain
|
||||||
|
* the correct profile string when the comfort profile is selected.
|
||||||
|
*/
|
||||||
|
public void testZExportv1Profile() {
|
||||||
|
|
||||||
|
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506new.pdf";
|
||||||
|
|
||||||
|
// the writing part
|
||||||
|
try (InputStream SOURCE_PDF = this.getClass()
|
||||||
|
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
||||||
|
|
||||||
|
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(1).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.COMFORT).load(SOURCE_PDF)) {
|
||||||
|
|
||||||
|
ze.PDFattachZugferdFile(this);
|
||||||
|
ze.disableAutoClose(true);
|
||||||
|
ze.export(TARGET_PDF);
|
||||||
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ze.export(baos);
|
||||||
|
ze.close();
|
||||||
|
String pdfContent = baos.toString("UTF-8");
|
||||||
|
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.BASIC) >= 0);
|
||||||
|
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.EXTENDED) >= 0);
|
||||||
|
assertTrue(pdfContent.indexOf(DocumentContextParameterTypeConstants.COMFORT) >= 0);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail("IOException should not happen in testZExport");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFXExport() throws Exception {
|
public void testFXExport() throws Exception {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user