From c92b9dd0b2420b9e83b7353347a721483ab42a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Sta=CC=88rk?= Date: Sun, 7 Jun 2020 10:36:02 +0200 Subject: [PATCH] dropped orphaned migration feature --- History.md | 3 +- .../org/mustangproject/commandline/Main.java | 39 +-- .../ZUGFeRD/ZUGFeRDMigrator.java | 101 ------- .../src/main/resources/COMFORTtoEN16931.xsl | 277 ------------------ .../ZUGFeRD/VersionMigrationTest.java | 116 -------- 5 files changed, 3 insertions(+), 533 deletions(-) delete mode 100644 library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java delete mode 100644 library/src/main/resources/COMFORTtoEN16931.xsl delete mode 100644 library/src/test/java/org/mustangproject/ZUGFeRD/VersionMigrationTest.java diff --git a/History.md b/History.md index 695e64cb..686242c8 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,6 @@ 2.0 todo - verapdf as prevalidation - remove jaxb -- remove migration - visualization? - factory for xrechnung - new sample innvoice @@ -22,6 +21,8 @@ done - getSellerTradePartyAddress (PR #157 ) thanks to aberndt-hub - switched from eclipse to IntelliJ - added ph-schematron-maven-plugin so that xrechnung xslt can be generated +- remove migration +- be able to recursively validate directories 1.7.7 ===== 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 4af952b4..e2b24022 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -34,7 +34,6 @@ import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel; import org.mustangproject.ZUGFeRD.ZUGFeRDExporter; import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory; import org.mustangproject.ZUGFeRD.ZUGFeRDImporter; -import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator; import org.mustangproject.validator.ZUGFeRDValidator; /*** @@ -52,7 +51,7 @@ public class Main { } private static String getUsage() { - 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" + return "Usage: --action metrics|combine|extract|a3only|validate [-d,--directory] [-l,--listfromstdin] [-i,--ignore fileextension, PDF/A errors] | [-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" @@ -63,10 +62,6 @@ public class Main { + " Additional parameters (optional - user will be prompted if not defined)\n" + " [--source ]: set input PDF file\n" + " [--out ]: set output XML file\n" - + " upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: set input XML ZUGFeRD 1 file\n" - + " [--out ]: set output XML ZUGFeRD 2 file\n" + " 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 ]: set input PDF file\n" @@ -317,9 +312,6 @@ public class Main { } else if ((action!=null)&&(action.equals("a3only"))) { performConvert(sourceName, outName); optionsRecognized=true; - } else if ((action!=null)&&(action.equals("upgrade"))) { - performUpgrade(sourceName, outName); - optionsRecognized=true; } else if ((action!=null)&&(action.equals("validate"))) { optionsRecognized=performValidate(sourceName); @@ -382,35 +374,6 @@ public class Main { return true; } - private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException { - - // Get params from user if not already defined - if (xmlName == null) { - xmlName = getFilenameFromUser("ZUGFeRD 1.0 XML source", "ZUGFeRD-invoice.xml", "xml", true, false); - } else { - System.out.println("ZUGFeRD 1.0 XML source set to " + xmlName); - } - if (outName == null) { - outName = getFilenameFromUser("ZUGFeRD 2.0 XML target", "zugferd-invoice.xml", "xml", false, true); - } else { - System.out.println("ZUGFeRD 1.0 XML source set to " + outName); - } - - // Verify params - ensureFileExists(xmlName); - ensureFileNotExists(outName); - - // All params are good! continue... - ZUGFeRDMigrator zmi = new ZUGFeRDMigrator(); - String xml = null; - xml = zmi.migrateFromV1ToV2(xmlName); - Files.write(Paths.get(outName), xml.getBytes()); - System.out.println("Written to " + outName); - /* - * } catch (FileNotFoundException ex) { - * Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex); - */ - } private static void performConvert(String pdfName, String outName) throws IOException { /* diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java deleted file mode 100644 index 83d67468..00000000 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java +++ /dev/null @@ -1,101 +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; - -import javax.xml.transform.*; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; -import java.io.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class ZUGFeRDMigrator { - - static final ClassLoader CLASS_LOADER = ZUGFeRDMigrator.class.getClassLoader(); - private static final String RESOURCE_PATH = ""; //$NON-NLS-1$ - private static final Logger LOG = Logger.getLogger(ZUGFeRDMigrator.class.getName()); - // private static File createTempFileResult(final Transformer transformer, final StreamSource toTransform, -// final String suffix) throws TransformerException, IOException { -// File result = File.createTempFile("ZUV_", suffix); //$NON-NLS-1$ -// result.deleteOnExit(); -// -// try (FileOutputStream fos = new FileOutputStream(result)) { -// transformer.transform(toTransform, new StreamResult(fos)); -// } -// return result; -// } - private TransformerFactory mFactory = null; - private Templates mXsltTemplate = null; - - public ZUGFeRDMigrator() { - mFactory = new net.sf.saxon.TransformerFactoryImpl(); - //fact = TransformerFactory.newInstance(); - mFactory.setURIResolver(new ClasspathResourceURIResolver()); - try { - mXsltTemplate = mFactory.newTemplates(new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "COMFORTtoEN16931.xsl"))); - } catch (TransformerConfigurationException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - - public String migrateFromV1ToV2(String xmlFilename) throws FileNotFoundException, TransformerException, UnsupportedEncodingException { - /** - * * - * http://www.unece.org/fileadmin/DAM/cefact/xml/XML-Naming-And-Design-Rules-V2_1.pdf - * http://www.ferd-net.de/upload/Dokumente/FACTUR-X_ZUGFeRD_2p0_Teil1_Profil_EN16931_1p03.pdf - * http://countwordsfree.com/xmlviewer - */ - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - applySchematronXsl(new FileInputStream(xmlFilename), baos); - - String res = null; - res = baos.toString("UTF-8"); - - //migrate the profiles - - res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:basic", "urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p0:basic"); - res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:comfort", "urn:cen.eu:en16931:2017"); - res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:extended", "urn:cen.eu:en16931:2017#conformant#urn:zugferd.de:2p0:extended"); - - //somehow the XML parser seems to insert erreneous XML namespaces, depending on which one it is, saxon seems to be cleaner. - //nevertheless, remove them manually - res=res.replace("", ""); - res=res.replace("", ""); - - - return res; - } - - public void applySchematronXsl(final InputStream xmlFile, - final OutputStream EN16931Outstream) throws TransformerException { - Transformer transformer = mXsltTemplate.newTransformer(); - transformer.transform(new StreamSource(xmlFile), new StreamResult(EN16931Outstream)); - } - - private static class ClasspathResourceURIResolver implements URIResolver { - ClasspathResourceURIResolver() { - // Do nothing, just prevents synthetic access warning. - } - - @Override - public Source resolve(String href, String base) throws TransformerException { - return new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + href)); - } - } -} diff --git a/library/src/main/resources/COMFORTtoEN16931.xsl b/library/src/main/resources/COMFORTtoEN16931.xsl deleted file mode 100644 index c4f974a9..00000000 --- a/library/src/main/resources/COMFORTtoEN16931.xsl +++ /dev/null @@ -1,277 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - <!-- -Migrated by Mustangproject XSLT ---> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/VersionMigrationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/VersionMigrationTest.java deleted file mode 100644 index 62e83b67..00000000 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/VersionMigrationTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** ********************************************************************** - * - * 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; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.xmlunit.builder.DiffBuilder; -import org.xmlunit.diff.Diff; - -import javax.xml.transform.TransformerException; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.junit.Assert.assertFalse; - - -/** - * Every ZUGFeRD 1.0 XML file from src/test/resources/migration/input - * will be migrated to src/test/resources/migration/output. - * If there is a similar named file as test reference src/test/resources/migration/reference a test - * will be triggered for every single file. - * - * Note: Any 'ZUGFeRD1' will be exchanged to 'ZUGFeRD2' during migration and adequate reference will be searched for. - */ -@RunWith(Parameterized.class) -public class VersionMigrationTest { - - private static final Logger LOG = Logger.getLogger(VersionMigrationTest.class.getName()); - - private static final String INPUT_DIR = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "migration" + File.separator + "input" + File.separator; - private static final String REFERENCE_DIR = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "migration" + File.separator + "reference" + File.separator; - private static final String OUTPUT_DIR = "target" + File.separator + "test-classes" + File.separator + "migration" + File.separator + "output" + File.separator; - private File mTestFile = null; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - // Creating the output directory for the tests - new File(OUTPUT_DIR).mkdirs(); - } - - public VersionMigrationTest(File testFile) { - mTestFile = testFile; - } - - @Parameterized.Parameters(name = "Test# {index}: {0}") - public static Collection data() { - Collection testSuiteData = new ArrayList(); - addFilesFromFolder(new File(INPUT_DIR), testSuiteData); - return testSuiteData; - } - - private static void addFilesFromFolder(final File folder, Collection testSuiteData) { - for (final File fileEntry : folder.listFiles()) { - String filePath = fileEntry.getAbsolutePath(); - if (fileEntry.isDirectory()) { - LOG.log(Level.INFO, "*** testDirectory:{0}", filePath); - addFilesFromFolder(fileEntry, testSuiteData); - } else { - LOG.log(Level.INFO, "*** testFile: {0}", filePath); - Object[] testData = new Object[]{fileEntry}; - testSuiteData.add(testData); - } - } - } - - @Test - /** - * ZUGFeRD 1.0 to 2.0 migration test. - * For more information see class description. */ - public void testFile() { - testMigration(mTestFile.getName()); - } - - private void testMigration(String fileName) { - try { - String tmp = new ZUGFeRDMigrator().migrateFromV1ToV2(INPUT_DIR + fileName); - String newName = fileName.replace("ZUGFeRD1", "ZUGFeRD2"); - ResourceUtilities.saveFile(StandardCharsets.UTF_8, OUTPUT_DIR + newName, tmp); - if (new File(REFERENCE_DIR + newName).exists()) { - // we need to save the string and reload it otherwise two bytes are missing (likely EOF related) - String outXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, OUTPUT_DIR + newName); - String refXML = ResourceUtilities.readFile(StandardCharsets.UTF_8, REFERENCE_DIR + newName); - Diff myDiff = DiffBuilder.compare(refXML).withTest(outXML).checkForSimilar().ignoreComments().ignoreWhitespace().build(); - assertFalse(myDiff.toString(), myDiff.hasDifferences()); - } else { - LOG.log(Level.INFO, "\n*** Migrated from ZUGFeRD 1.0 to 2.0 invoice: '" + newName + "'' ***\n", OUTPUT_DIR); - } - } catch (IOException | TransformerException t) { - LOG.log(Level.SEVERE, t.getMessage(), t); - Assert.fail("Failed with " + t.getClass().getName() + ": '" + t.getMessage() + "'"); - } - } - -}