have a --no-notices option

This commit is contained in:
Jochen Stärk
2020-07-26 16:26:36 +02:00
parent 2778af34fd
commit d1b8d482ad
4 changed files with 69 additions and 60 deletions

View File

@@ -29,6 +29,7 @@ done
- remove migration - remove migration
- be able to recursively validate directories - be able to recursively validate directories
- be able to ignore input pdf errors with -i - be able to ignore input pdf errors with -i
- be able to recursively scan directories using validateExpectValid/validateExpectInvalid
- upgraded to verapdf 1.16.1 - upgraded to verapdf 1.16.1
- added Ghostscript signature - added Ghostscript signature
- removal of izugferddate/IZUGFeRDPaymentTerms,IZUGFeRDPaymentDiscountTerms - removal of izugferddate/IZUGFeRDPaymentTerms,IZUGFeRDPaymentDiscountTerms

View File

@@ -18,6 +18,15 @@
*********************************************************************** */ *********************************************************************** */
package org.mustangproject.commandline; package org.mustangproject.commandline;
import com.sanityinc.jargs.CmdLineParser;
import com.sanityinc.jargs.CmdLineParser.Option;
import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel;
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
import org.mustangproject.validator.Validator;
import org.mustangproject.validator.ZUGFeRDValidator;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -43,9 +52,11 @@ import org.mustangproject.validator.ZUGFeRDValidator;
import com.sanityinc.jargs.CmdLineParser; import com.sanityinc.jargs.CmdLineParser;
import com.sanityinc.jargs.CmdLineParser.Option; import com.sanityinc.jargs.CmdLineParser.Option;
import org.slf4j.LoggerFactory;
public class Main { public class Main {
// build with: /opt/local/bin/mvn clean compile assembly:single private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Validator.class.getCanonicalName()); // log output
private static void printUsage() { private static void printUsage() {
System.err.println(getUsage()); System.err.println(getUsage());
} }
@@ -74,45 +85,27 @@ public class Main {
+ " [--format <fx|zf>]: set ZUGFeRD or FacturX\n" + " [--format <fx|zf>]: set ZUGFeRD or FacturX\n"
+ " [--version <1|2>]: set ZUGFeRD version\n" + " [--version <1|2>]: set ZUGFeRD version\n"
+ " [--profile <...>]: set ZUGFeRD profile\n" + " [--profile <...>]: set ZUGFeRD profile\n"
+ " For ZUGFeRD v1: <B>ASIC, <C>OMFORT or <E>XTENDED\n" + " For ZUGFeRD v1: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, E<X>TENDED " + " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED "
+ " validate validate XML or PDF file \n" + " validate validate XML or PDF file \n"
+ " [--no-notices]: refrain from reporting notices\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: input PDF or XML file\n" + " [--source <filename>]: input PDF or XML file\n"
+ " validateExpectValid validate directory expecting positive results \n"
+ " [--no-notices]: refrain from reporting notices\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " -d, --directory to check recursively \n"
+ " validateExpectInvalid validate directory expecting negative results \n"
+ " [--no-notices]: refrain from reporting notices\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " -d, --directory to check recursively\n"
; ;
} }
private static void printHelp() { private static void printHelp() {
System.out.println("Mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + " \r\n" System.out.println("Mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + " \r\n"
+ "A Apache Public License library and command line tool for statistics on PDF invoices with\r\n" + "A Apache Public License tool for e-invoices with\r\n"
+ "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "\r\n" + "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "\r\n");
+ "* Count operations\r\n" + "\t-d, --directory\tcount ZUGFeRD files in directory to be scanned\r\n"
+ "\t\tIf it is a directory, it will recurse.\r\n"
+ "\t-l, --listfromstdin\tcount ZUGFeRD files from a list of linefeed separated files on runtime.\r\n"
+ "\t\tIt will start once a blank line has been entered.\r\n" + "\r\n"
+ "\tAdditional parameter for both count operations\r\n"
+ "\t[-i, --ignorefileextension]\tCheck for all files (*.*) instead of PDF files only (*.pdf)\r\n"
+ "\r\n" + "* Merge operations\r\n" + "\t-e, --extract\textract ZUGFeRD PDF to XML file\r\n"
+ "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
+ "\t\t[--source <filename>]: set input PDF file\r\n"
+ "\t\t[--out <filename>]: set output XML file\r\n"
+ "\t-u, --upgrade\tupgrade ZUGFeRD XML to ZUGFeRD 2 XML\r\n"
+ "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
+ "\t\t[--source <filename>]: set input XML ZUGFeRD 1 file\r\n"
+ "\t\t[--out <filename>]: set output XML ZUGFeRD 2 file\r\n"
+ "\t-a, --a3only\tupgrade from PDF/A1 to A3 only (no ZUGFeRD data attached) \r\n"
+ "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
+ "\t\t[--source <filename>]: set input PDF file\r\n"
+ "\t\t[--out <filename>]: set output PDF file\r\n"
+ "\t-c, --combine\tcombine XML and PDF file to ZUGFeRD PDF file\r\n"
+ "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
+ "\t\t[--source <filename>]: set input PDF file\r\n"
+ "\t\t[--source-xml <filename>]: set input XML file\r\n"
+ "\t\t[--out <filename>]: set output PDF file\r\n"
+ "\t\t[--format <fx|zf>]: enable factur-x or ZUGFeRD\r\n"
+ "\t\t[--version <1|2>]: set ZUGFeRD version\r\n" + "\t\t[--profile <...>]: set ZUGFeRD profile\r\n"
+ "\t\t\tFor ZUGFeRD v1: <B>ASIC, <C>OMFORT or <E>XTENDED\r\n"
+ "\t\t\tFor ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, EX<T>ENDED, <X>Rechnung\r\n");
} }
/** /**
@@ -148,7 +141,7 @@ public class Main {
try { try {
input = buffer.readLine(); input = buffer.readLine();
} catch (IOException e) { } catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
@@ -185,7 +178,7 @@ public class Main {
try { try {
selectedName = buffer.readLine(); selectedName = buffer.readLine();
} catch (IOException e) { } catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
@@ -217,7 +210,7 @@ public class Main {
try { try {
selectedAnswer = buffer.readLine(); selectedAnswer = buffer.readLine();
} catch (IOException e) { } catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
if (!selectedAnswer.equals("Y") && !selectedAnswer.equals("y")) { if (!selectedAnswer.equals("Y") && !selectedAnswer.equals("y")) {
System.err.println("Aborted by user"); System.err.println("Aborted by user");
@@ -259,6 +252,7 @@ public class Main {
Option<String> sourceOption = parser.addStringOption("source"); Option<String> sourceOption = parser.addStringOption("source");
// --out: output file // --out: output file
Option<String> outOption = parser.addStringOption("out"); Option<String> outOption = parser.addStringOption("out");
Option<Boolean> noNoticesOption = parser.addBooleanOption("no-notices");
// Command: Combining PDF and XML // Command: Combining PDF and XML
@@ -282,7 +276,6 @@ public class Main {
// Command: Show metrics from list from stdin // Command: Show metrics from list from stdin
// --listfromstdin // --listfromstdin
Option<Boolean> filesFromStdInOption = parser.addBooleanOption('l', "listfromstdin"); Option<Boolean> filesFromStdInOption = parser.addBooleanOption('l', "listfromstdin");
try { try {
parser.parse(args); parser.parse(args);
} catch (CmdLineParser.OptionException e) { } catch (CmdLineParser.OptionException e) {
@@ -301,6 +294,8 @@ public class Main {
String sourceXMLName = parser.getOptionValue(sourceXmlOption); String sourceXMLName = parser.getOptionValue(sourceXmlOption);
String outName = parser.getOptionValue(outOption); String outName = parser.getOptionValue(outOption);
String format = parser.getOptionValue(formatOption); String format = parser.getOptionValue(formatOption);
Boolean noNotices = parser.getOptionValue(noNoticesOption);
String zugferdVersion = parser.getOptionValue(zugferdVersionOption); String zugferdVersion = parser.getOptionValue(zugferdVersionOption);
String zugferdProfile = parser.getOptionValue(zugferdProfileOption); String zugferdProfile = parser.getOptionValue(zugferdProfileOption);
boolean optionsRecognized=false; boolean optionsRecognized=false;
@@ -320,37 +315,32 @@ public class Main {
performConvert(sourceName, outName); performConvert(sourceName, outName);
optionsRecognized=true; optionsRecognized=true;
} else if ((action!=null)&&(action.equals("validate"))) { } else if ((action!=null)&&(action.equals("validate"))) {
optionsRecognized=performValidate(sourceName, noNotices!=null&&noNotices);
optionsRecognized=performValidate(sourceName);
} else if ((action!=null)&&(action.equals("validateExpectValid"))) { } else if ((action!=null)&&(action.equals("validateExpectValid"))) {
optionsRecognized=performValidateExpect(true, directoryName); optionsRecognized=performValidateExpect(true, directoryName);
} else if ((action!=null)&&(action.equals("validateExpectInvalid"))) { } else if ((action!=null)&&(action.equals("validateExpectInvalid"))) {
optionsRecognized=performValidateExpect(false, directoryName); optionsRecognized=performValidateExpect(false, directoryName);
} else { } else {
// no argument or argument unknown // no argument or argument unknown
printUsage(); printUsage();
System.exit(2); System.exit(2);
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage(), e);
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
System.exit(-1); System.exit(-1);
} }
} }
private static boolean performValidate(String sourceName) { private static boolean performValidate(String sourceName, boolean noNotices) {
boolean optionsRecognized; boolean optionsRecognized;
if (sourceName == null) { if (sourceName == null) {
sourceName = getFilenameFromUser("Source PDF or XML", "invoice.pdf", "pdf|xml", true, false); sourceName = getFilenameFromUser("Source PDF or XML", "invoice.pdf", "pdf|xml", true, false);
} }
ZUGFeRDValidator zfv=new ZUGFeRDValidator(); ZUGFeRDValidator zfv=new ZUGFeRDValidator();
if (noNotices) {
zfv.disableNotices();
}
System.out.println(zfv.validate(sourceName)); System.out.println(zfv.validate(sourceName));
optionsRecognized = !zfv.hasOptionsError(); optionsRecognized = !zfv.hasOptionsError();
if (!zfv.wasCompletelyValid()) { if (!zfv.wasCompletelyValid()) {
@@ -470,7 +460,7 @@ public class Main {
try { try {
format = getStringFromUser("Format (fx=Factur-X, zf=ZUGFeRD)", "zf", "fx|zf"); format = getStringFromUser("Format (fx=Factur-X, zf=ZUGFeRD)", "zf", "fx|zf");
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
} else { } else {
System.out.println("Format set to " + format); System.out.println("Format set to " + format);
@@ -480,7 +470,7 @@ public class Main {
try { try {
zfVersion = getStringFromUser("Version (1 or 2)", Integer.toString(ZUGFeRDExporter.DefaultZUGFeRDVersion), "1|2"); zfVersion = getStringFromUser("Version (1 or 2)", Integer.toString(ZUGFeRDExporter.DefaultZUGFeRDVersion), "1|2");
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
} else { } else {
System.out.println("Version set to " + zfVersion); System.out.println("Version set to " + zfVersion);
@@ -497,8 +487,7 @@ public class Main {
"M|m|W|w|B|b|C|c|E|e|T|t|X|x|"); "M|m|W|w|B|b|C|c|E|e|T|t|X|x|");
} }
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
} else { } else {
System.out.println("Profile set to " + zfProfile); System.out.println("Profile set to " + zfProfile);
@@ -567,8 +556,7 @@ public class Main {
System.out.println("Written to " + outName); System.out.println("Written to " + outName);
} catch (IOException e) { } catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e); LOGGER.error(e.getMessage(), e);
} }
} }

View File

@@ -33,9 +33,6 @@ import com.helger.schematron.svrl.SVRLHelper;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
public class XMLValidator extends Validator { public class XMLValidator extends Validator {
public XMLValidator(ValidationContext ctx) {
super(ctx);
}
private static final Logger LOGGER = LoggerFactory.getLogger(XMLValidator.class.getCanonicalName()); // log output private static final Logger LOGGER = LoggerFactory.getLogger(XMLValidator.class.getCanonicalName()); // log output
// is // is
@@ -46,9 +43,15 @@ public class XMLValidator extends Validator {
protected String filename = ""; protected String filename = "";
int firedRules = 0; int firedRules = 0;
int failedRules = 0; int failedRules = 0;
boolean disableNotices=false;
ISchematronResource aResSCH = null; ISchematronResource aResSCH = null;
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
public XMLValidator(ValidationContext ctx) {
super(ctx);
}
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
filename = name; filename = name;
// file existence must have been checked before // file existence must have been checked before
@@ -74,6 +77,13 @@ public class XMLValidator extends Validator {
return (uri1.equals(uri2) || uri1.startsWith(uri2 + "#")); return (uri1.equals(uri2) || uri1.startsWith(uri2 + "#"));
} }
/***
* don't report notices in validation report
*/
public void disableNotices() {
disableNotices=true;
}
/*** /***
* *
* @param xmlString * @param xmlString
@@ -263,8 +273,9 @@ public class XMLValidator extends Validator {
&& (isEN16931 || isXRechnung)) { && (isEN16931 || isXRechnung)) {
//additionally validate against CEN //additionally validate against CEN
validateSchematron(zfXML, "/xslt/cii16931schematron/EN16931-CII-validation.xslt", 24, ESeverity.error); validateSchematron(zfXML, "/xslt/cii16931schematron/EN16931-CII-validation.xslt", 24, ESeverity.error);
if (!disableNotices||XrechnungSeverity!=ESeverity.notice) {
validateXR(zfXML, XrechnungSeverity); validateXR(zfXML, XrechnungSeverity);
}
} }

View File

@@ -39,6 +39,7 @@ public class ZUGFeRDValidator {
protected boolean displayXMLValidationOutput; protected boolean displayXMLValidationOutput;
protected long startTime; protected long startTime;
protected boolean optionsRecognized; protected boolean optionsRecognized;
protected boolean disableNotices = false;
protected String Signature; protected String Signature;
protected boolean wasCompletelyValid = false; protected boolean wasCompletelyValid = false;
protected String logAppend=null; protected String logAppend=null;
@@ -110,7 +111,9 @@ public class ZUGFeRDValidator {
} else { } else {
BigFileSearcher searcher = new BigFileSearcher(); BigFileSearcher searcher = new BigFileSearcher();
XMLValidator xv = new XMLValidator(context); XMLValidator xv = new XMLValidator(context);
if (disableNotices) {
xv.disableNotices();
}
byte[] pdfSignature = { '%', 'P', 'D', 'F' }; byte[] pdfSignature = { '%', 'P', 'D', 'F' };
boolean isPDF = searcher.indexOf(file, pdfSignature) == 0; boolean isPDF = searcher.indexOf(file, pdfSignature) == 0;
if (isPDF) { if (isPDF) {
@@ -250,6 +253,12 @@ public class ZUGFeRDValidator {
return sw.toString(); return sw.toString();
} }
/***
* don't report notices in validation report
*/
public void disableNotices() {
disableNotices=true;
}
/** /**
* Read the file and calculate the SHA-1 checksum * Read the file and calculate the SHA-1 checksum
* *