improvements on directory validation
This commit is contained in:
@@ -52,13 +52,13 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getUsage() {
|
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"
|
+ "* merics\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n"
|
||||||
+ " If it is a directory, it will recurse.\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"
|
+ " -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"
|
+ " It will start once a blank line has been entered.\n" + "\n"
|
||||||
+ " Additional parameter for both count operations\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"
|
+ "\n" + "* Merge actions\n" + " extract extract ZUGFeRD PDF to XML file\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>]: set input PDF file\n"
|
+ " [--source <filename>]: set input PDF file\n"
|
||||||
@@ -309,7 +309,7 @@ public class Main {
|
|||||||
performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
|
performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
|
||||||
optionsRecognized=true;
|
optionsRecognized=true;
|
||||||
} else if ((action!=null)&&(action.equals("combine"))) {
|
} else if ((action!=null)&&(action.equals("combine"))) {
|
||||||
performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile);
|
performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, ignoreFileExt);
|
||||||
optionsRecognized=true;
|
optionsRecognized=true;
|
||||||
} else if ((action!=null)&&(action.equals("extract"))) {
|
} else if ((action!=null)&&(action.equals("extract"))) {
|
||||||
performExtract(sourceName, outName);
|
performExtract(sourceName, outName);
|
||||||
@@ -364,7 +364,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean performValidateExpect(boolean valid, String dirName) {
|
private static boolean performValidateExpect(boolean valid, String dirName) {
|
||||||
ValidatorFileWalker zfWalk = new ValidatorFileWalker();
|
ValidatorFileWalker zfWalk = new ValidatorFileWalker(valid);
|
||||||
Path startingDir = Paths.get(dirName);
|
Path startingDir = Paths.get(dirName);
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(startingDir, zfWalk);
|
Files.walkFileTree(startingDir, zfWalk);
|
||||||
@@ -373,7 +373,12 @@ public class Main {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
String totalResult="valid";
|
||||||
|
if (!zfWalk.getResult()) {
|
||||||
|
totalResult="invalid";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Overall test result: "+totalResult);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +471,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion,
|
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()
|
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
||||||
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
||||||
@@ -577,6 +582,10 @@ public class Main {
|
|||||||
.setZUGFeRDVersion(zfIntVersion)
|
.setZUGFeRDVersion(zfIntVersion)
|
||||||
.setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile)
|
.setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile)
|
||||||
.load(pdfName);
|
.load(pdfName);
|
||||||
|
if (ignoreInputErrors) {
|
||||||
|
ze.ignoreA1Errors();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (format.equals("fx")) {
|
if (format.equals("fx")) {
|
||||||
ze.setFacturX();
|
ze.setFacturX();
|
||||||
|
|||||||
@@ -27,13 +27,19 @@ public class ValidatorFileWalker
|
|||||||
protected PathMatcher matcher;
|
protected PathMatcher matcher;
|
||||||
protected ZUGFeRDValidator zul;
|
protected ZUGFeRDValidator zul;
|
||||||
protected int fileCount=1;
|
protected int fileCount=1;
|
||||||
|
protected boolean expectValid=true;
|
||||||
|
protected boolean allValid=true;
|
||||||
|
|
||||||
public ValidatorFileWalker() {
|
public ValidatorFileWalker(boolean expectValid) {
|
||||||
this.zul = new ZUGFeRDValidator();
|
this.zul = new ZUGFeRDValidator();
|
||||||
;
|
this.expectValid=expectValid;
|
||||||
matcher = FileSystems.getDefault().getPathMatcher("glob:*.{pdf,xml}");
|
matcher = FileSystems.getDefault().getPathMatcher("glob:*.{pdf,xml}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getResult() {
|
||||||
|
return allValid;
|
||||||
|
}
|
||||||
// Print information about
|
// Print information about
|
||||||
// each type of file.
|
// each type of file.
|
||||||
@Override
|
@Override
|
||||||
@@ -42,14 +48,24 @@ public class ValidatorFileWalker
|
|||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
//get current date time with Date()
|
//get current date time with Date()
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
|
String expectedString="valid";
|
||||||
|
if (!expectValid) {
|
||||||
|
expectedString="invalid";
|
||||||
|
}
|
||||||
if ((attr!=null)&&(attr.isRegularFile())) {
|
if ((attr!=null)&&(attr.isRegularFile())) {
|
||||||
if (matcher.matches(file.getFileName())) {
|
if (matcher.matches(file.getFileName())) {
|
||||||
|
boolean thisResultValid=true;
|
||||||
LOGGER.info(String.format("\n@%s Testing file %d: %s ", dateFormat.format(date), fileCount++, file));
|
String thisResultString=" valid";
|
||||||
|
try {
|
||||||
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
|
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
|
||||||
.asString()
|
.asString()
|
||||||
.isEqualTo(
|
.isEqualTo(expectedString);
|
||||||
"valid");
|
|
||||||
|
} catch (AssertionError ae) {
|
||||||
|
thisResultValid=false;
|
||||||
|
thisResultString="invalid";
|
||||||
|
}
|
||||||
|
LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
<!-- Configure so that it outputs to both console and log file -->
|
<!-- Configure so that it outputs to both console and log file -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
<!-- appender-ref ref="STDOUT" /-->
|
<appender-ref ref="STDOUT" />
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
Reference in New Issue
Block a user