switch to new profiles (the old ones did not work)

This commit is contained in:
Jochen Stärk
2020-09-24 21:59:03 +02:00
parent 5144758c2f
commit d1b16f6b4d
22 changed files with 192 additions and 122 deletions

View File

@@ -43,6 +43,7 @@ public class Invoice implements IExportableTransaction {
Charges = new ArrayList<IZUGFeRDAllowanceCharge>(), LogisticsServiceCharges = new ArrayList<IZUGFeRDAllowanceCharge>();
protected IZUGFeRDTradeSettlement[] getTradeSettlement = null;
protected IZUGFeRDPaymentTerms paymentTerms = null;
private Profile profile;
public Invoice() {
@@ -72,6 +73,7 @@ public class Invoice implements IExportableTransaction {
return this;
}
@Override
public String getNumber() {
return number;
@@ -482,4 +484,5 @@ public class Invoice implements IExportableTransaction {
return null;
}
}
}

View File

@@ -18,9 +18,10 @@
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
public class CustomXMLProvider implements IXMLProvider, IProfileProvider {
public class CustomXMLProvider implements IXMLProvider {
protected byte[] zugferdData;
protected Profile profile=Profiles.getByName("EN16931");
@Override
public byte[] getXML() {
@@ -49,13 +50,11 @@ public class CustomXMLProvider implements IXMLProvider, IProfileProvider {
}
@Override
public String getProfile() {
// TODO Auto-generated method stub
return null;
public Profile getProfile() {
return profile;
}
@Override
public void setProfile(Profiles level) {
// TODO Auto-generated method stub
public void setProfile(Profile level) {
profile=level;
}
}

View File

@@ -435,4 +435,6 @@ public interface IExportableTransaction {
default Date getOccurrencePeriodTo() {
return null;
}
}

View File

@@ -1,27 +0,0 @@
/** **********************************************************************
*
* Copyright 2018 Jochen Staerk
*
* Use is subject to license terms.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
public interface IProfileProvider {
public String getProfile();
public void setProfile(Profiles level);
}

View File

@@ -26,4 +26,9 @@ public interface IXMLProvider {
public void generateXML(IExportableTransaction trans);
public void setProfile(Profile p);
public Profile getProfile();
}

View File

@@ -59,7 +59,7 @@ public interface IZUGFeRDExporter extends Closeable, IExporter {
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException;
public IZUGFeRDExporter setXML(byte[] zugferdData) throws IOException;
public IZUGFeRDExporter disableFacturX();
public IZUGFeRDExporter setProfile(Profiles zugferdConformanceLevel);
// public IZUGFeRDExporter setProfile(Profile zugferdConformanceLevel);
public String getNamespaceForVersion(int ver);
public String getPrefixForVersion(int ver) ;
public IZUGFeRDExporter disableAutoClose(boolean disableAutoClose);

View File

@@ -0,0 +1,28 @@
package org.mustangproject.ZUGFeRD;
public class Profile {
protected String name, id;
public Profile(String name, String ID) {
this.name = name;
this.id = ID;
}
public String getName() {
return name;
}
public String getID() {
return id;
}
public String getXMPName() {
if (name.equals("BASICWL")) {
return "BASIC WL";
} else if (name.equals("EN16931")) {
return "EN 16931";
} else {
return name;
}
}
}

View File

@@ -1,23 +1,59 @@
/** **********************************************************************
*
/**
* *********************************************************************
* <p>
* Copyright 2018 Jochen Staerk
*
* <p>
* Use is subject to license terms.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* <p>
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
* <p>
* **********************************************************************
*/
package org.mustangproject.ZUGFeRD;
public enum Profiles {
BASIC, COMFORT, EXTENDED, EN16931/*=Comfort*/, MINIMUM, BASICWL /*basic without lines, less than basic*/, CIUS, XRECHNUNG
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Profiles {
static Map<String, Profile> zf2Map = Stream.of(new Object[][]{
{"MINIMUM", new Profile("MINIMUM", "urn:factur-x.eu:1p0:minimum")},
{"BASICWL", new Profile("BASICWL", "urn:factur-x.eu:1p0:basicwl")},
{"BASIC", new Profile("BASIC", "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic")},
{"EN16931", new Profile("EN16931", "urn:cen.eu:en16931:2017")},
{"EXTENDED", new Profile("EXTENDED", "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended")},
{"XRECHNUNG", new Profile("XRECHNUNG", "XRECHNUNG")}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Profile) data[1]));
static Map<String, Profile> zf1Map = Stream.of(new Object[][]{
{"BASIC", new Profile("BASIC", "urn:ferd:CrossIndustryDocument:invoice:1p0:basic")},
{"COMFORT", new Profile("COMFORT", "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort")},
{"EXTENDED", new Profile("EXTENDED", "urn:ferd:CrossIndustryDocument:invoice:1p0:extended")},
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Profile) data[1]));
public static Profile getByName(String name, int version) {
if (version==1) {
return zf1Map.get(name);
} else {
return zf2Map.get(name);
}
}
public static Profile getByName(String name) {
return getByName(name, ZUGFeRDExporterFromA3.DefaultZUGFeRDVersion);
}
}

View File

@@ -41,17 +41,12 @@ public class XMPSchemaZugferd extends XMPSchema {
* @param prefix the xml namespace prefix for the XMP, zf for ZUGFeRD, fx for Factur-X
* @param filename the filename of the invoice
*/
public XMPSchemaZugferd(XMPMetadata metadata, int zfVersion, boolean isFacturX, Profiles conformanceLevel, String URN, String prefix, String filename) {
public XMPSchemaZugferd(XMPMetadata metadata, int zfVersion, boolean isFacturX, Profile conformanceLevel, String URN, String prefix, String filename) {
super(metadata, URN, prefix, "ZUGFeRD Schema");
setAboutAsSimple("");
String conformanceLevelValue = conformanceLevel.name();
if (conformanceLevelValue.equals("BASICWL")) {
conformanceLevelValue = "BASIC WL";
} else if (conformanceLevelValue.equals("EN16931")) {
conformanceLevelValue = "EN 16931";
}
String conformanceLevelValue = conformanceLevel.getXMPName();
setTextPropertyValue("ConformanceLevel", conformanceLevelValue);
setTextPropertyValue("DocumentType", "INVOICE");
setTextPropertyValue("DocumentFileName", filename);

View File

@@ -35,21 +35,17 @@ import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
public class ZUGFeRD1PullProvider implements IXMLProvider {
//// MAIN CLASS
protected byte[] zugferdData;
private IExportableTransaction trans;
private Profiles level;
private String paymentTermsDescription;
SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
protected Profile profile=Profiles.getByName("COMFORT",1);
@Override
public void setProfile(Profiles level) {
this.level = level;
}
/**
* enables the flag to indicate a test invoice in the XML structure
@@ -73,6 +69,12 @@ public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
return XMLTools.nDigitFormat(value, 4);
}
@Override
public Profile getProfile() {
return profile;
}
@Override
public byte[] getXML() {
@@ -152,11 +154,6 @@ public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
return hm;
}
@Override
public String getProfile() {
return "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort";
}
protected String getTradePartyAsXML(IZUGFeRDExportableTradeParty contact) {
String xml = " <ram:Name>" + XMLTools.encodeXML(contact.getName()) + "</ram:Name>\n" //$NON-NLS-2$
// + " <DefinedTradeContact>\n"
@@ -242,7 +239,7 @@ public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
// <ram:TestIndicator><udt:Indicator>"+testBooleanStr+"</udt:Indicator></ram:TestIndicator>\n"
//
+ " <ram:GuidelineSpecifiedDocumentContextParameter>\n"
+ " <ram:ID>" + getProfile() + "</ram:ID>\n"
+ " <ram:ID>" + getProfile().getID() + "</ram:ID>\n"
+ " </ram:GuidelineSpecifiedDocumentContextParameter>\n"
+ " </rsm:SpecifiedExchangedDocumentContext>\n"
+ " <rsm:HeaderExchangedDocument>\n"
@@ -541,6 +538,11 @@ public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
} // $NON-NLS-1$
}
@Override
public void setProfile(Profile p) {
profile=p;
}
private String buildPaymentTermsXml() {
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";

View File

@@ -38,19 +38,15 @@ import org.dom4j.io.XMLWriter;
import org.mustangproject.Invoice;
import org.mustangproject.XMLTools;
public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
public class ZUGFeRD2PullProvider implements IXMLProvider {
//// MAIN CLASS
protected SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
protected byte[] zugferdData;
private IExportableTransaction trans;
private Profiles level;
private String paymentTermsDescription;
protected Profile profile=Profiles.getByName("EN16931");
@Override
public void setProfile(Profiles level) {
this.level = level;
}
/**
* enables the flag to indicate a test invoice in the XML structure
@@ -155,9 +151,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
}
@Override
public String getProfile() {
// return "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2";
return "urn:cen.eu:en16931:2017";
public Profile getProfile() {
return profile;
}
protected String getTradePartyAsXML(IZUGFeRDExportableTradeParty party) {
@@ -272,7 +267,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
// <ram:TestIndicator><udt:Indicator>"+testBooleanStr+"</udt:Indicator></ram:TestIndicator>\n"
//
+ " <ram:GuidelineSpecifiedDocumentContextParameter>\n"
+ " <ram:ID>" + getProfile() + "</ram:ID>\n"
+ " <ram:ID>" + getProfile().getID() + "</ram:ID>\n"
+ " </ram:GuidelineSpecifiedDocumentContextParameter>\n"
+ " </rsm:ExchangedDocumentContext>\n"
+ " <rsm:ExchangedDocument>\n"
@@ -539,6 +534,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
} // $NON-NLS-1$
}
@Override
public void setProfile(Profile p) {
profile=p;
}
private String buildPaymentTermsXml() {
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";

View File

@@ -68,6 +68,14 @@ public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUG
}
}
public ZUGFeRDExporterFromA1 setProfile(Profile p) {
return (ZUGFeRDExporterFromA1)super.setProfile(p);
}
public ZUGFeRDExporterFromA1 setProfile(String profileName) {
return (ZUGFeRDExporterFromA1)super.setProfile(profileName);
}
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
if (!ignorePDFAErrors && !isValidA1(dataSource)) {
throw new IOException("File is not a valid PDF/A input file");
@@ -106,9 +114,6 @@ public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUG
return (ZUGFeRDExporterFromA1) super.setXML(zugferdData);
}
public ZUGFeRDExporterFromA1 setProfile(Profiles zugferdConformanceLevel){
return (ZUGFeRDExporterFromA1) super.setProfile(zugferdConformanceLevel);
}
public ZUGFeRDExporterFromA1 disableAutoClose(boolean disableAutoClose){
return (ZUGFeRDExporterFromA1) super.disableAutoClose(disableAutoClose);
}

View File

@@ -53,7 +53,6 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
public static final int DefaultZUGFeRDVersion = 2;
protected Profiles profile = Profiles.EXTENDED;
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<FileAttachment>();
@@ -62,7 +61,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
private boolean disableAutoClose;
private boolean fileAttached = false;
private Profile profile = null;
private boolean documentPrepared = false;
/**
@@ -113,6 +112,23 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return xmlProvider;
}
public ZUGFeRDExporterFromA3 setProfile(Profile p) {
this.profile=p;
if (xmlProvider!=null) {
xmlProvider.setProfile(p);
}
return this;
}
public ZUGFeRDExporterFromA3 setProfile(String profilename) {
this.profile=Profiles.getByName(profilename);
if (xmlProvider!=null) {
xmlProvider.setProfile(this.profile);
}
return this;
}
public ZUGFeRDExporterFromA3 addAdditionalFile(String name, byte[] content) {
fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data"));
return this;
@@ -154,14 +170,14 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @param ver the zf/fx version
* @return the filename of the file to be embedded
*/
public String getFilenameForVersion(int ver, Profiles profile) {
public String getFilenameForVersion(int ver, Profile profile) {
if (isFacturX) {
return "factur-x.xml";
} else {
if (ver == 1) {
return "ZUGFeRD-invoice.xml";
} else {
if (profile == Profiles.XRECHNUNG) {
if (profile.getName().equals("XRECHNUNG")) {
return "xrechnung.xml";
} else {
return "zugferd-invoice.xml";
@@ -190,6 +206,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return this;
}
/**
* Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
* metadata level, this will not e.g. convert graphics to JPG-2000)
@@ -207,6 +224,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
ensurePDFisUpgraded = false;
}
public void attachFile(FileAttachment file) {
fileAttachments.add(file);
}
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
FileAttachment fa=new FileAttachment(filename, mimetype, relation, data);
fileAttachments.add(fa);
@@ -349,8 +369,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
public ZUGFeRDExporterFromA3 setXML(byte[] zugferdData) throws IOException {
CustomXMLProvider cus = new CustomXMLProvider();
cus.setXML(zugferdData);
this.xmlProvider = cus;
setTransaction(null);
this.setXMLProvider(cus);
prepare();
return this;
}
@@ -375,15 +395,6 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return buffer.toByteArray();
}
/**
* Sets the ZUGFeRD conformance level (override).
*
* @param zugferdConformanceLevel the new conformance level
*/
public ZUGFeRDExporterFromA3 setProfile(Profiles zugferdConformanceLevel) {
this.profile = zugferdConformanceLevel;
return this;
}
/**
* All files are PDF/A-3, setConformance refers to the level conformance.
@@ -434,9 +445,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
protected void addXMP(XMPMetadata metadata) {
if (attachZUGFeRDHeaders) {
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, profile,
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, xmlProvider.getProfile(),
getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion),
getFilenameForVersion(ZFVersion, profile));
getFilenameForVersion(ZFVersion, xmlProvider.getProfile()));
metadata.addSchema(zf);
}
@@ -513,10 +524,13 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
*/
public IExporter setTransaction(IExportableTransaction trans) throws IOException {
this.trans = trans;
return prepare();
}
public IExporter prepare() throws IOException{
prepareDocument();
((IProfileProvider) xmlProvider).setProfile(profile);
xmlProvider.generateXML(trans);
String filename = getFilenameForVersion(ZFVersion, profile);
String filename = getFilenameForVersion(ZFVersion, xmlProvider.getProfile());
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());
@@ -563,16 +577,22 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return this;
}
protected void setXMLProvider(IXMLProvider p) {
this.xmlProvider = p;
if (profile!=null) {
xmlProvider.setProfile(profile);
}
}
@Override
public ZUGFeRDExporterFromA3 setZUGFeRDVersion(int version) {
this.ZFVersion = version;
if (version == 1) {
ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider();
disableFacturX();
this.xmlProvider = z1p;
setXMLProvider(z1p);
} else if (version == 2) {
ZUGFeRD2PullProvider z2p = new ZUGFeRD2PullProvider();
this.xmlProvider = z2p;
setXMLProvider(z2p);
} else {
throw new IllegalArgumentException("Version not supported");
}