diff --git a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java index 3dd8c651..4af952b4 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -52,13 +52,13 @@ public class Main { } private static String getUsage() { - return "Usage: --action metrics|combine|extract|a3only|upgrade|validate [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n" + return "Usage: --action metrics|combine|extract|a3only|upgrade|validate [-d,--directory] [-l,--listfromstdin] [-i,--ignore fileextension, PDF/A errors] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n" + "* merics\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n" + " If it is a directory, it will recurse.\n" + " -l, --listfromstdin count ZUGFeRD files from a list of linefeed separated files on runtime.\n" + " It will start once a blank line has been entered.\n" + "\n" + " Additional parameter for both count operations\n" - + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf)\n" + + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf) in metrics, ignore PDF/A input file errors in combine\n" + "\n" + "* Merge actions\n" + " extract extract ZUGFeRD PDF to XML file\n" + " Additional parameters (optional - user will be prompted if not defined)\n" + " [--source ]: set input PDF file\n" @@ -309,7 +309,7 @@ public class Main { performMetrics(directoryName, filesFromStdIn, ignoreFileExt); optionsRecognized=true; } else if ((action!=null)&&(action.equals("combine"))) { - performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile); + performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, ignoreFileExt); optionsRecognized=true; } else if ((action!=null)&&(action.equals("extract"))) { performExtract(sourceName, outName); @@ -364,7 +364,7 @@ public class Main { } private static boolean performValidateExpect(boolean valid, String dirName) { - ValidatorFileWalker zfWalk = new ValidatorFileWalker(); + ValidatorFileWalker zfWalk = new ValidatorFileWalker(valid); Path startingDir = Paths.get(dirName); try { Files.walkFileTree(startingDir, zfWalk); @@ -373,7 +373,12 @@ public class Main { // TODO Auto-generated catch block e1.printStackTrace(); } + String totalResult="valid"; + if (!zfWalk.getResult()) { + totalResult="invalid"; + } + System.out.println("Overall test result: "+totalResult); return true; } @@ -466,7 +471,7 @@ public class Main { } private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion, - String zfProfile) throws Exception { + String zfProfile, Boolean ignoreInputErrors) throws Exception { /* * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory() * .setProducer("toecount") .setCreator(System.getProperty("user.name")) @@ -577,6 +582,10 @@ public class Main { .setZUGFeRDVersion(zfIntVersion) .setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile) .load(pdfName); + if (ignoreInputErrors) { + ze.ignoreA1Errors(); + + } if (format.equals("fx")) { ze.setFacturX(); diff --git a/Mustang-CLI/src/main/java/org/mustangproject/commandline/ValidatorFileWalker.java b/Mustang-CLI/src/main/java/org/mustangproject/commandline/ValidatorFileWalker.java index 5edae80b..ec241aa7 100644 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/ValidatorFileWalker.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/ValidatorFileWalker.java @@ -27,13 +27,19 @@ public class ValidatorFileWalker protected PathMatcher matcher; protected ZUGFeRDValidator zul; protected int fileCount=1; + protected boolean expectValid=true; + protected boolean allValid=true; - public ValidatorFileWalker() { + public ValidatorFileWalker(boolean expectValid) { this.zul = new ZUGFeRDValidator(); - ; + this.expectValid=expectValid; matcher = FileSystems.getDefault().getPathMatcher("glob:*.{pdf,xml}"); } + + public boolean getResult() { + return allValid; + } // Print information about // each type of file. @Override @@ -42,16 +48,26 @@ public class ValidatorFileWalker DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //get current date time with Date() Date date = new Date(); + String expectedString="valid"; + if (!expectValid) { + expectedString="invalid"; + } if ((attr!=null)&&(attr.isRegularFile())) { if (matcher.matches(file.getFileName())) { - - LOGGER.info(String.format("\n@%s Testing file %d: %s ", dateFormat.format(date), fileCount++, file)); - assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status") - .asString() - .isEqualTo( - "valid"); + boolean thisResultValid=true; + String thisResultString=" valid"; + try { + assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status") + .asString() + .isEqualTo(expectedString); - } + } catch (AssertionError ae) { + thisResultValid=false; + thisResultString="invalid"; + } + LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file)); + + } } return FileVisitResult.CONTINUE; } diff --git a/Mustang-CLI/src/main/resources/logback.xml b/Mustang-CLI/src/main/resources/logback.xml index 5c52d73c..5bfbb0db 100644 --- a/Mustang-CLI/src/main/resources/logback.xml +++ b/Mustang-CLI/src/main/resources/logback.xml @@ -24,6 +24,6 @@ - + - \ No newline at end of file +