From 5dcaf11aa73f05bfd25ee93fe6c6a521b213198a Mon Sep 17 00:00:00 2001 From: Herman Wika Horn Date: Mon, 8 Jan 2024 13:30:21 +0100 Subject: [PATCH 1/2] Methods for PeppolBillingApi to find country identifier of supplier and customer party These values can be useful for mandatory header property COUNTRY_C1 and corresponding PEPPOL End User and Transmission report --- .../bis/invoice3/api/PeppolBillingApi.java | 14 +++++++ .../invoice3/api/PeppolBillingApiTest.java | 41 +++++++++++++++++++ ...le.xml => generated_norwegian-example.xml} | 0 3 files changed, 55 insertions(+) create mode 100644 api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java rename api/src/test/resources/{generated_norwegian-exmple.xml => generated_norwegian-example.xml} (100%) diff --git a/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java b/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java index e702bd7..de8a27f 100644 --- a/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java +++ b/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java @@ -71,6 +71,20 @@ public boolean isInvoice() { return false; } + public String getSupplierCountryIdentifier() { + if (this.object instanceof Document) { + return ((Document) this.object).find("AccountingSupplierParty", "Party", "PostalAddress", "Country", "IdentificationCode").single().text().trim(); + } + throw new RuntimeException("Mandatory property missing in document: AccountingSupplierParty -> Party -> PostalAddress -> Country -> IdentificationCode"); + } + + public String getCustomerCountryIdentifier() { + if (this.object instanceof Document) { + return ((Document) this.object).find("AccountingCustomerParty", "Party", "PostalAddress", "Country", "IdentificationCode").single().text().trim(); + } + throw new RuntimeException("Mandatory property missing in document: AccountingCustomerParty -> Party -> PostalAddress -> Country -> IdentificationCode"); + } + public String prettyPrint() { return XML_FIRST_LINE + (this.object instanceof BillingCommon ? ((BillingCommon) this.object).xmlRoot() : ((Document) this.object).getRootElement()).toIndentedXML(); } diff --git a/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java b/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java new file mode 100644 index 0000000..1a095ef --- /dev/null +++ b/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java @@ -0,0 +1,41 @@ +/** + * Copyright (C) Posten Norge AS + * + * 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 peppol.bis.invoice3.api; + +import org.eaxy.Document; +import org.eaxy.Xml; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class PeppolBillingApiTest { + + @Test + public void test() throws IOException { + try (InputStream inputStream = PeppolBillingApiTest.class.getResourceAsStream("/norwegian-example.xml")) { + assertNotNull(inputStream); + Document document = Xml.xml(new String(inputStream.readAllBytes())); + PeppolBillingApi peppolBillingApi = new PeppolBillingApi<>(document); + assertEquals("NO", peppolBillingApi.getCustomerCountryIdentifier()); + assertEquals("NO", peppolBillingApi.getSupplierCountryIdentifier()); + } + } + +} diff --git a/api/src/test/resources/generated_norwegian-exmple.xml b/api/src/test/resources/generated_norwegian-example.xml similarity index 100% rename from api/src/test/resources/generated_norwegian-exmple.xml rename to api/src/test/resources/generated_norwegian-example.xml From 0d03b2249e51705e5492fd6e4c2b4cd3e1aefcc9 Mon Sep 17 00:00:00 2001 From: Herman Wika Horn Date: Tue, 16 Jan 2024 17:00:38 +0100 Subject: [PATCH 2/2] Method to get EndpointID for supplier This can be used as an unique identifier for each supplier, e.g. as EndUserID when reporting end user statistics to OpenPEPPOL --- .../java/peppol/bis/invoice3/api/PeppolBillingApi.java | 9 +++++++++ .../peppol/bis/invoice3/api/PeppolBillingApiTest.java | 1 + 2 files changed, 10 insertions(+) diff --git a/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java b/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java index de8a27f..6bf57e3 100644 --- a/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java +++ b/api/src/main/java/peppol/bis/invoice3/api/PeppolBillingApi.java @@ -16,6 +16,7 @@ package peppol.bis.invoice3.api; import org.eaxy.Document; +import org.eaxy.Element; import peppol.bis.invoice3.domain.BillingCommon; import peppol.bis.invoice3.domain.CreditNote; import peppol.bis.invoice3.domain.Invoice; @@ -85,6 +86,14 @@ public String getCustomerCountryIdentifier() { throw new RuntimeException("Mandatory property missing in document: AccountingCustomerParty -> Party -> PostalAddress -> Country -> IdentificationCode"); } + public String getSupplierEndpointID() { + if (this.object instanceof Document) { + Element element = ((Document) this.object).find("AccountingSupplierParty", "Party", "EndpointID").single(); + return element.attr("schemeID").trim() + ":" + element.text().trim(); + } + throw new RuntimeException("Mandatory property missing in document: AccountingSupplierParty -> Party -> EndpointID"); + } + public String prettyPrint() { return XML_FIRST_LINE + (this.object instanceof BillingCommon ? ((BillingCommon) this.object).xmlRoot() : ((Document) this.object).getRootElement()).toIndentedXML(); } diff --git a/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java b/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java index 1a095ef..9470ceb 100644 --- a/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java +++ b/api/src/test/java/peppol/bis/invoice3/api/PeppolBillingApiTest.java @@ -35,6 +35,7 @@ public void test() throws IOException { PeppolBillingApi peppolBillingApi = new PeppolBillingApi<>(document); assertEquals("NO", peppolBillingApi.getCustomerCountryIdentifier()); assertEquals("NO", peppolBillingApi.getSupplierCountryIdentifier()); + assertEquals("0192:123456785", peppolBillingApi.getSupplierEndpointID()); } }