extend IProfileProvider to allow modification of profile

This commit is contained in:
Stefan Schmiedl
2019-07-25 18:33:14 +02:00
parent b701bf25c8
commit 9681b4fa6d
6 changed files with 43 additions and 5 deletions

View File

@@ -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
}
} }

View File

@@ -22,4 +22,6 @@ public interface IProfileProvider {
public String getProfile(); public String getProfile();
public void setProfile(ZUGFeRDConformanceLevel level);
} }

View File

@@ -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);

View File

@@ -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

View File

@@ -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",

View File

@@ -85,6 +85,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 +115,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);
@@ -955,6 +956,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;