Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix complex if constructs #677

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 102 additions & 91 deletions Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,63 +44,63 @@ private static void printUsage() {

private static String getUsage() {
return "Usage: --action metrics|combine|extract|a3only|ubl|validate|validateExpectInvalid|validateExpectValid|visualize [-d,--directory] [-l,--listfromstdin] [-i,--ignore fileextension, PDF/A errors] [--disable-file-logging] | [-h,--help] \r\n"
+ " --action license display open source license and notice\n"
+ " --action metrics\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) in metrics, ignore PDF/A input file errors in combine\n"
+ " [--disable-file-logging] disable logging to file.\n"
+ " --action extract extract Factur-X PDF to XML file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output XML file\n"
+ " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " --action combine combine XML and PDF file to Factur-X PDF file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--source-xml <filename>]: set input XML file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " [--format <fx|zf|ox|da>]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n"
+ " [--version <1|2>]: set ZUGFeRD version\n"
+ " [--profile <...>]: set ZUGFeRD profile\n"
+ " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
+ " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n"
+ " [--no-additional-attachments]: prevent prompting for attachments\n"
+ " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output XML file\n"
+ " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input XML ZUGFeRD 1 file\n"
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
+ " --action validate validate XML or PDF file \n"
+ " [--no-notices]: refrain from reporting notices\n"
+ " [--logAppend <text>]: text to be added to log line\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: input PDF or XML file\n"
+ " [--log-as-pdf]: save log output as pdf\n"
+ " --action 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"
+ " --action 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"
+ " --action visualize convert XML to HTML \n"
+ " [--language <lang>]: set output lang (en, fr or de)\n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output HTML file\n"
+ " --action pdf convert XML to PDF \n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " --action license display open source license and notice\n"
+ " --action metrics\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) in metrics, ignore PDF/A input file errors in combine\n"
+ " [--disable-file-logging] disable logging to file.\n"
+ " --action extract extract Factur-X PDF to XML file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output XML file\n"
+ " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " --action combine combine XML and PDF file to Factur-X PDF file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input PDF file\n"
+ " [--source-xml <filename>]: set input XML file\n"
+ " [--out <filename>]: set output PDF file\n"
+ " [--format <fx|zf|ox|da>]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n"
+ " [--version <1|2>]: set ZUGFeRD version\n"
+ " [--profile <...>]: set ZUGFeRD profile\n"
+ " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
+ " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n"
+ " [--no-additional-attachments]: prevent prompting for attachments\n"
+ " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output XML file\n"
+ " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: set input XML ZUGFeRD 1 file\n"
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
+ " --action validate validate XML or PDF file \n"
+ " [--no-notices]: refrain from reporting notices\n"
+ " [--logAppend <text>]: text to be added to log line\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source <filename>]: input PDF or XML file\n"
+ " [--log-as-pdf]: save log output as pdf\n"
+ " --action 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"
+ " --action 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"
+ " --action visualize convert XML to HTML \n"
+ " [--language <lang>]: set output lang (en, fr or de)\n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output HTML file\n"
+ " --action pdf convert XML to PDF \n"
+ " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output PDF file\n"
;
}

Expand Down Expand Up @@ -474,7 +474,7 @@ private static boolean performValidate(String sourceName, boolean noNotices, Str
String validationResultXML = zfv.validate(sourceName);
System.out.println(validationResultXML);

if( createLogAsPDF) {
if (createLogAsPDF) {
ValidationLogVisualizer vlvi = new ValidationLogVisualizer();
String fileBasename = FilenameUtils.getBaseName(sourceName);

Expand Down Expand Up @@ -533,9 +533,9 @@ private static void performConvert(String pdfName, String outName) throws IOExce

// All params are good! continue...
try (ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()) {
ze.convertOnly().load(pdfName);
ze.export(outName);
System.out.println("Written to " + outName);
ze.convertOnly().load(pdfName);
ze.export(outName);
System.out.println("Written to " + outName);
}
}

Expand Down Expand Up @@ -609,8 +609,7 @@ private static void performCombine(String pdfName, String xmlName, String outNam
}
}
} else {
for (int i = 0; i < attachmentFilenames.length; i++) {
String attachmentFilename = attachmentFilenames[i];
for (String attachmentFilename : attachmentFilenames) {
if (!attachmentFilename.isEmpty()) {
byte[] attachmentContents = Files.readAllBytes(Paths.get(attachmentFilename));
String attachmentMime = Files.probeContentType(Paths.get(attachmentFilename));
Expand Down Expand Up @@ -639,7 +638,7 @@ private static void performCombine(String pdfName, String xmlName, String outNam
} else {
System.out.println("Version set to " + zfVersion);
}
zfIntVersion = Integer.valueOf(zfVersion);
zfIntVersion = Integer.parseInt(zfVersion);

if (zfProfile == null) {
try {
Expand Down Expand Up @@ -682,32 +681,44 @@ private static void performCombine(String pdfName, String xmlName, String outNam
if (format.equals("ox")) {
standard = EStandard.orderx;
}
if (zfProfile.equals("b")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion);
} else if (zfProfile.equals("c")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "COMFORT", zfIntVersion);
} else if (zfProfile.equals("t")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "EXTENDED", zfIntVersion);
} else {
throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
switch (zfProfile) {
case "b":
zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion);
break;
case "c":
zfConformanceLevelProfile = Profiles.getByName(standard, "COMFORT", zfIntVersion);
break;
case "t":
zfConformanceLevelProfile = Profiles.getByName(standard, "EXTENDED", zfIntVersion);
break;
default:
throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
}
} else if (((format.equals("zf")) && (zfIntVersion == 2)) || (format.equals("fx"))) {
if (zfProfile.equals("m")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "MINIMUM", zfIntVersion);
} else if (zfProfile.equals("w")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "BASICWL", zfIntVersion);
} else if (zfProfile.equals("b")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion);
} else if (zfProfile.equals("c")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "CIUS", zfIntVersion);
} else if (zfProfile.equals("e")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "EN16931", zfIntVersion);
} else if (zfProfile.equals("t")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "EXTENDED", zfIntVersion);
} else if (zfProfile.equals("x")) {
zfConformanceLevelProfile = Profiles.getByName(standard, "XRECHNUNG", zfIntVersion);
} else {
throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
switch (zfProfile) {
case "m":
zfConformanceLevelProfile = Profiles.getByName(standard, "MINIMUM", zfIntVersion);
break;
case "w":
zfConformanceLevelProfile = Profiles.getByName(standard, "BASICWL", zfIntVersion);
break;
case "b":
zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion);
break;
case "c":
zfConformanceLevelProfile = Profiles.getByName(standard, "CIUS", zfIntVersion);
break;
case "e":
zfConformanceLevelProfile = Profiles.getByName(standard, "EN16931", zfIntVersion);
break;
case "t":
zfConformanceLevelProfile = Profiles.getByName(standard, "EXTENDED", zfIntVersion);
break;
case "x":
zfConformanceLevelProfile = Profiles.getByName(standard, "XRECHNUNG", zfIntVersion);
break;
default:
throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
}
} else {
throw new Exception(String.format("Unknown version '%i'", zfIntVersion));
Expand Down Expand Up @@ -897,9 +908,9 @@ static public String ExportResource(String resourceName) throws Exception {
byte[] buffer = new byte[4096];
jarFolder = System.getProperty("user.dir");
try (FileOutputStream resStreamOut = new FileOutputStream(jarFolder + resourceName)) {
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
}
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public FileVisitResult visitFile(Path file,
thisResultString="invalid";
allValid=false;
}
LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));
LOGGER.info(String.format("%n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));

}
}
Expand All @@ -72,7 +72,7 @@ public FileVisitResult visitFile(Path file,
@Override
public FileVisitResult postVisitDirectory(Path dir,
IOException exc) {
LOGGER.info("\nDirectory: %s%n", dir);
LOGGER.info("%nDirectory: {}%n", dir);
return FileVisitResult.CONTINUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testCii2Ubl() throws Exception {
if (!result.isEmpty()) {
System.out.println(result);
}
assertTrue(new String(Files.readAllBytes(output), StandardCharsets.UTF_8).contains("Invoice"));
assertTrue(Files.readString(output).contains("Invoice"));
}

private String getOutput(Process process) throws IOException {
Expand All @@ -61,7 +61,7 @@ private String getOutput(Process process) throws IOException {
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
builder.append(System.lineSeparator());
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* will be thrown if a invoice cant be read
*/
public class StructureException extends ParseException {
public StructureException(String message, int line) {
super(message, line);
}
public StructureException(String message, int line) {
super(message, line);
}
}
59 changes: 25 additions & 34 deletions library/src/main/java/org/mustangproject/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ public Item(NodeList itemChilds, boolean recalcPrice) {
icnm.getAsString("Name").ifPresent(product::setName);
icnm.getAsString("Description").ifPresent(product::setDescription);

icnm.getAsNodeMap("SellersItemIdentification").ifPresent(SellersItemIdentification -> {
SellersItemIdentification.getAsString("ID").ifPresent(product::setSellerAssignedID);
});
icnm.getAsNodeMap("SellersItemIdentification").ifPresent(SellersItemIdentification -> SellersItemIdentification.getAsString("ID").ifPresent(product::setSellerAssignedID));

icnm.getAsNodeMap("BuyersItemIdentification").ifPresent(BuyersItemIdentification -> {
BuyersItemIdentification.getAsString("ID").ifPresent(product::setBuyerAssignedID);
});
icnm.getAsNodeMap("BuyersItemIdentification").ifPresent(BuyersItemIdentification -> BuyersItemIdentification.getAsString("ID").ifPresent(product::setBuyerAssignedID));

// String name = icnm.getAsStringOrNull("Name");
// String val = icnm.getAsStringOrNull("Value");
Expand All @@ -100,9 +96,7 @@ public Item(NodeList itemChilds, boolean recalcPrice) {
icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsBigDecimal("Percent"))
.ifPresent(product::setVATPercent);
});
itemMap.getAsNodeMap("AssociatedDocumentLineDocument").ifPresent(icnm -> {
icnm.getAsString("LineID").ifPresent(this::setId);
});
itemMap.getAsNodeMap("AssociatedDocumentLineDocument").ifPresent(icnm -> icnm.getAsString("LineID").ifPresent(this::setId));

itemMap.getAsNodeMap("Price").ifPresent(icnm -> {
// ubl
Expand Down Expand Up @@ -172,32 +166,29 @@ public Item(NodeList itemChilds, boolean recalcPrice) {
icnm.getAsNodeMap("ApplicableTradeTax")
.flatMap(cnm -> cnm.getAsBigDecimal("RateApplicablePercent", "ApplicablePercent"))
.ifPresent(product::setVATPercent);
icnm.getAsNodeMap("SpecifiedTradeAllowanceCharge").ifPresent(stac -> {
stac.getAsNodeMap("ChargeIndicator").ifPresent(ci -> {
String isChargeString=ci.getAsString("Indicator").get();
String percentString=stac.getAsStringOrNull("CalculationPercent");
String amountString=stac.getAsStringOrNull("ActualAmount");
String reason=stac.getAsStringOrNull("Reason");
Charge izac= new Charge();
if (isChargeString.equalsIgnoreCase("false")) {
izac = new Allowance();
} else {
izac = new Charge();
}
if (amountString!=null) {
izac.setTotalAmount(new BigDecimal(amountString));
}
izac.setPercent(new BigDecimal(percentString));
izac.setReason(reason);

if (isChargeString.equalsIgnoreCase("false")) {
addAllowance(izac);
} else {
addCharge(izac);
}
});
icnm.getAsNodeMap("SpecifiedTradeAllowanceCharge").ifPresent(stac -> stac.getAsNodeMap("ChargeIndicator").ifPresent(ci -> {
String isChargeString=ci.getAsString("Indicator").get();
String percentString=stac.getAsStringOrNull("CalculationPercent");
String amountString=stac.getAsStringOrNull("ActualAmount");
String reason=stac.getAsStringOrNull("Reason");
Charge izac= new Charge();
if (isChargeString.equalsIgnoreCase("false")) {
izac = new Allowance();
} else {
izac = new Charge();
}
if (amountString!=null) {
izac.setTotalAmount(new BigDecimal(amountString));
}
izac.setPercent(new BigDecimal(percentString));
izac.setReason(reason);

});
if (isChargeString.equalsIgnoreCase("false")) {
addAllowance(izac);
} else {
addCharge(izac);
}
}));

if (recalcPrice && !BigDecimal.ZERO.equals(quantity)) {
icnm.getAsNodeMap("SpecifiedTradeSettlementLineMonetarySummation")
Expand Down
Loading
Loading