From 487f85b8af87c4f3334e0a965779100692dc7e73 Mon Sep 17 00:00:00 2001 From: AaronArrick Date: Mon, 25 Nov 2019 10:18:08 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Gj=C3=B8r=20at=20vi=20lager=20en=20xml=20fi?= =?UTF-8?q?l=20med=20datatypes=20eksemplene,=20til=20=C3=A5=20bli=20brukt?= =?UTF-8?q?=20i=20klient=20bibliotek=20utvidelsene.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datatypes-examples.xml | 357 ++++++++++++++++++ pom.xml | 2 +- .../documentation/DocumentationGenerator.java | 20 +- .../documentation/MarkdownPrinter.java | 12 + 4 files changed, 387 insertions(+), 4 deletions(-) create mode 100644 datatypes-examples.xml diff --git a/datatypes-examples.xml b/datatypes-examples.xml new file mode 100644 index 00000000..3ecb6731 --- /dev/null +++ b/datatypes-examples.xml @@ -0,0 +1,357 @@ + + + + 2017-06-27T10:00:00+02:00 + 2017-06-27T11:00:00+02:00 + Oppmøte senest 15 minutter før timen + Oslo City Røntgen +
+ Storgata 23 + 0011 + Oslo + Norge +
+ Undersøke smerter i ryggen + + Informasjon om Oslo City Røntgen + Oslo City Røntgen er et spesialistsenter for avansert bildediagnostikk. + +
+ + + + +
+ 23 + Storgata + 0011 + Oslo +
+ + 0301 + 208 + 630 + 0 + 0 + + boligmappa + externalId +
+ + Gunnar Gunnersen + gunnargunnar@gunn.ar + + 59 + 3 + 4 + + 2017-07-27T10:00:00+02:00 + Privat salg av sekundærbolig + Bill Isalg + Cooper Coopersen + 12345678 + + 123456789 + H1337 + 42 + + TNT ASA + Pantedokument + 3000000000 + + + https://www.example.com + Gå til avsenders side for å gjøre en handling + Ta meg til handling! + +
+ + + + Kommunestyre- og fylkestingvalg + + 2019-05-23T10:00:00+02:00 + 2019-05-23T16:00:00+02:00 + + Opening hours + Velkommen til valg! Husk legitimasjon. + Sagene skole + Election venue +
+ Storgata 23 + 0011 + Oslo + Norge +
+ + Forhåndsstemming + Du kan forhåndsstemme fra 10. august + + Barcode for use on election day: + + 1234567890 + code-128 + Show barcode for faster identification + true + + + https://valg.no + Les mer om valget på valg.no + +
+ + + + https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/ + 2017-09-30T13:37:00+02:00 + Oslo Kommune ber deg akseptere eller avslå tilbudet om barnehageplass. + Svar på barnehageplass + + + + + + + + KB432788293NO + 70300492517312675 + + 1234567890 + CODE_128 + Show barcode for faster identification + true + + Klimanøytral Servicepakke + 2018-09-10T10:00:00+02:00 + 2018-09-24T10:00:00+02:00 + + Test Testesen + test.testesen#0000 +
+ Storgata 23 + 0011 + Oslo + Norge +
+
+ + Avsenderservice as + 13372500 +
+ Storgata 23 + 0011 + Oslo + Norge +
+
+ + Coop Mega + RC89 + Må hentes innen 010180 + H32 +
+ Storgata 23 + 0011 + Oslo + Norge +
+
+ + 120 + 60 + 60 + 35000 + + + 128.00 + 1277.00 + 162.00 + FORENKLET TOLLBEHANDLING + 0 + 0 + 0 + 0 + + READY_FOR_PICKUP + POSTEN +
+ + + + READY_FOR_PICKUP + 2019-01-10T10:10:00+01:00 + + + + + Bekkestua Bibliotek + #e1e1e1 + 2019-05-23T10:00:00+02:00 + + + 2020 + 2022 + + 1 + 1 + + + 12 + 31 + 0 + 0 + +01:00 + + + + + Ola + Nordmann +
+ Storgata 23 + 0011 + Oslo + Norge +
+
+ Lånekort + Lånekortnummer + a-132415124-xyzzy-21341 + + Kaffeklubb + Premium deluxe medlem + + + Regler + Det er ikke lov å rive ut sider i bøkene, eller søle med ketchup. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquet urna condimentum, pulvinar neque ac, tempor tellus. Vestibulum ante ipsum primis in faucibus orci luctus et + +
+ + + + F96B6805-2453-478A-B58B-CCDFA07E21ED + 364567 + 2018-05-27T10:00:00+02:00 + 59.80 + 11.96 + NOK + Benny + 15 + 7F5A1EFF-ECAE-48A7-A07F-38D87576F815 + Grünerløkka Hip Coffee + 12345678 + + Storgata 23 + 0011 + Oslo + Norge + + 123456789 + + 1234567890 + code-128 + Show barcode for faster identification + true + + + Bank Axept + ************1234 + Visa + 100.00 + NOK + + USD + 15 + 7.534567 + + + + Tall Cafe latte + Tall vanilla latte with extra sugar + 0000012 + cup + 2.0 + 29.90 + 5.98 + 59.80 + 11.96 + 5.50 + XY12345325GF + 1345678 + + + EK99999 + 12341ASDF + 123456789 + 2018-06-05T10:00:00+02:00 + 2018-06-05T10:30:00+02:00 + 8.00 + 438.50 + 2000 + 8500 + 6500 + 320 + 1220 + 900 + + + 400.00 + 320.00 + 80.00 + 25.00 + + 64.90 + + + + Ola Nordmann +
+ Storgata 23 + 0011 + Oslo + Norge +
+ Delivered to the doorstep +
+ + Ola Nordmann +
+ Storgata 23 + 0011 + Oslo + Norge +
+ Delivered to the doorstep +
+ 123456 + HG1234HH8778 + Hip Coffee to the good citizens of Løkka +
+ + + +
+ 23 + Storgata + 0011 + Oslo +
+ + 0301 + 208 + 630 + 0 + 0 + + boligmappa + externalId +
+ + + + Bedrift AS + Ansettelseskontrakt + 2018-07-11T10:00:00+02:00 + + +
diff --git a/pom.xml b/pom.xml index 7d98616a..b309fd50 100644 --- a/pom.xml +++ b/pom.xml @@ -298,7 +298,7 @@ package no.digipost.api.datatypes.documentation.DocumentationGenerator - ${basedir}/readme.md + ${basedir}/readme.md ${basedir}/datatypes-examples.xml java diff --git a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java index 2b56753e..16f41e29 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java @@ -7,9 +7,7 @@ import javax.xml.bind.JAXBException; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.Set; import java.util.function.Function; import java.util.stream.Stream; @@ -20,7 +18,9 @@ public class DocumentationGenerator { public static void main(String[] args) throws IOException, JAXBException { final Path outputPath = Paths.get(args[0]); + final Path examplesOutputPath = Paths.get(args[1]); DocumentationGenerator.generate(outputPath, DataTypeIdentifier.getAllClasses(), DocumentationGenerator::getDataTypeExample); + DocumentationGenerator.generateExamples(examplesOutputPath, DataTypeIdentifier.getAllClasses(), DocumentationGenerator::getDataTypeExample); } public static DataType getDataTypeExample(Class dataType) { @@ -32,4 +32,18 @@ private static void generate(Path outputPath, Set> typesT final String markdown = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).print(types.collect(toList())); Files.write(outputPath, markdown.getBytes(StandardCharsets.UTF_8)); } + + private static void generateExamples(Path outputPath, Set> typesToDocument, Function, T> getExample) throws IOException, JAXBException { + final Stream types = DocumentationStructureBuilder.buildTypeStructure(typesToDocument, getExample); + + Files.write(outputPath, "".getBytes()); + Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); + + for (ComplexType complexType : types.collect(toList())) { + final String markdown = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).getXmlExample(complexType.getExample()); + Files.write(outputPath, markdown.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); + } + + Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); + } } diff --git a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java index 6ba0fb1a..09825cbc 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java @@ -81,6 +81,18 @@ private String printXmlExample(Object example) { } } + public String getXmlExample(Object example) { + try { + final StringWriter writer = new StringWriter(); + final Marshaller marshaller = jaxb.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.marshal(example, writer); + return writer.toString() + LF; + } catch (JAXBException e) { + throw new RuntimeException(e); + } + } + private String code(String type, String s) { return "```" + type + LF + s + LF + "```"; } From b7b7ebb9097764e8da1938cf0a562f1592ed876b Mon Sep 17 00:00:00 2001 From: AaronArrick Date: Mon, 25 Nov 2019 10:55:43 +0100 Subject: [PATCH 2/4] Kombiner metoder og endre variabel navn etter PR feedback --- .../documentation/DocumentationGenerator.java | 4 ++-- .../documentation/MarkdownPrinter.java | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java index 16f41e29..99822cf5 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java @@ -40,8 +40,8 @@ private static void generateExamples(Path outputPath, Set Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); for (ComplexType complexType : types.collect(toList())) { - final String markdown = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).getXmlExample(complexType.getExample()); - Files.write(outputPath, markdown.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); + final String xml = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).getXmlExample(complexType.getExample()); + Files.write(outputPath, xml.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); } Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); diff --git a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java index 09825cbc..590e47cb 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java @@ -69,25 +69,20 @@ private String printComplementedByInformation(ComplexType type) { } private String printXmlExample(Object example) { - try { - final StringWriter writer = new StringWriter(); - final Marshaller marshaller = jaxb.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(example, writer); - return heading(3, "XML") + LLF + - code("xml", writer.toString().trim()); - } catch (JAXBException e) { - throw new RuntimeException(e); - } + return heading(3, "XML") + LLF + code("xml", createXmlExample(example).trim()); } public String getXmlExample(Object example) { + return createXmlExample(example) + LF; + } + + private String createXmlExample(Object example) { try { final StringWriter writer = new StringWriter(); final Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(example, writer); - return writer.toString() + LF; + return writer.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } From 2c8dad6e08a9e42850c81f68993229564fe0ab8b Mon Sep 17 00:00:00 2001 From: AaronArrick Date: Mon, 25 Nov 2019 11:52:57 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Fjern=20un=C3=B8dvendig=20notasjonselemente?= =?UTF-8?q?r=20fra=20eksempel=20output.=20Litt=20mer=20tweaking=20av=20met?= =?UTF-8?q?oder=20for=20=C3=A5=20sl=C3=A5=20dem=20sammen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datatypes-examples.xml | 14 ++------------ readme.md | 11 ----------- .../documentation/DocumentationGenerator.java | 4 ++-- .../datatypes/documentation/MarkdownPrinter.java | 9 +++------ 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/datatypes-examples.xml b/datatypes-examples.xml index 3ecb6731..a54cee39 100644 --- a/datatypes-examples.xml +++ b/datatypes-examples.xml @@ -1,5 +1,5 @@ - + 2017-06-27T10:00:00+02:00 2017-06-27T11:00:00+02:00 @@ -18,7 +18,6 @@ -
@@ -66,7 +65,6 @@ - Kommunestyre- og fylkestingvalg @@ -100,7 +98,6 @@ - https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/ 2017-09-30T13:37:00+02:00 @@ -108,10 +105,8 @@ Svar på barnehageplass - - KB432788293NO 70300492517312675 @@ -176,13 +171,11 @@ POSTEN - READY_FOR_PICKUP 2019-01-10T10:10:00+01:00 - Bekkestua Bibliotek #e1e1e1 @@ -227,7 +220,6 @@ - F96B6805-2453-478A-B58B-CCDFA07E21ED 364567 @@ -328,7 +320,6 @@ Hip Coffee to the good citizens of Løkka -
23 @@ -347,11 +338,10 @@ externalId - Bedrift AS Ansettelseskontrakt 2018-07-11T10:00:00+02:00 - + \ No newline at end of file diff --git a/readme.md b/readme.md index f5cf0b97..2b1cf7c8 100644 --- a/readme.md +++ b/readme.md @@ -43,7 +43,6 @@ Appointment represents a meeting set for a specific place and time ### XML ```xml - 2017-06-27T10:00:00+02:00 2017-06-27T11:00:00+02:00 @@ -127,7 +126,6 @@ Details about a Residence, and may be joined with Residence to retrieve the core ### XML ```xml -
@@ -218,7 +216,6 @@ Event represents an event that occurs over a time period or several days. Eg. a ### XML ```xml - Kommunestyre- og fylkestingvalg @@ -269,7 +266,6 @@ An external URL, along with an optional description and deadline for resources s ### XML ```xml - https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/ 2017-09-30T13:37:00+02:00 @@ -291,7 +287,6 @@ For treating documents as Payslips. ### XML ```xml - ``` @@ -400,7 +395,6 @@ Valid values: ### XML ```xml - KB432788293NO 70300492517312675 @@ -490,7 +484,6 @@ Valid values: ### XML ```xml - READY_FOR_PICKUP 2019-01-10T10:10:00+01:00 @@ -571,7 +564,6 @@ Represents a legal document (Certificate, Licence, Permit, etc.) issued to a sin ### XML ```xml - Bekkestua Bibliotek #e1e1e1 @@ -712,7 +704,6 @@ Receipt represents a document containing details about a purchase ### XML ```xml - F96B6805-2453-478A-B58B-CCDFA07E21ED 364567 @@ -850,7 +841,6 @@ Residence is a way of linking separate data for the same residence ### XML ```xml -
23 @@ -885,7 +875,6 @@ Details about a signed document ### XML ```xml - Bedrift AS Ansettelseskontrakt diff --git a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java index 99822cf5..ef30a107 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java @@ -37,13 +37,13 @@ private static void generateExamples(Path outputPath, Set final Stream types = DocumentationStructureBuilder.buildTypeStructure(typesToDocument, getExample); Files.write(outputPath, "".getBytes()); - Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); + Files.write(outputPath, ("" + System.lineSeparator() + "" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); for (ComplexType complexType : types.collect(toList())) { final String xml = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).getXmlExample(complexType.getExample()); Files.write(outputPath, xml.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND); } - Files.write(outputPath, ("" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND); + Files.write(outputPath, "".getBytes(), StandardOpenOption.APPEND); } } diff --git a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java index 590e47cb..dc93173d 100644 --- a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java +++ b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java @@ -69,20 +69,17 @@ private String printComplementedByInformation(ComplexType type) { } private String printXmlExample(Object example) { - return heading(3, "XML") + LLF + code("xml", createXmlExample(example).trim()); + return heading(3, "XML") + LLF + code("xml", getXmlExample(example).trim()); } public String getXmlExample(Object example) { - return createXmlExample(example) + LF; - } - - private String createXmlExample(Object example) { try { final StringWriter writer = new StringWriter(); final Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.marshal(example, writer); - return writer.toString(); + return writer.toString() + LLF; } catch (JAXBException e) { throw new RuntimeException(e); } From a5462041ea8f5065dc2aad8212c2d7c2acbff5b0 Mon Sep 17 00:00:00 2001 From: AaronArrick Date: Mon, 25 Nov 2019 12:00:42 +0100 Subject: [PATCH 4/4] Fiks hardcoded xml tekst i test --- .../resources/no/digipost/api/datatypes/documentation/testdoc.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md b/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md index 269fe1e2..9d09fc49 100644 --- a/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md +++ b/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md @@ -39,7 +39,6 @@ ### XML ```xml - Dette er en kort melding til deg