From 87495133d364008f9c5449dba6289901dd8447be Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Fri, 19 Jul 2019 19:44:09 +0200 Subject: [PATCH] Extended export format to contain document types; #41 --- README.md | 1 + phoss-directory-publisher/pom.xml | 25 +++++ .../publisher/exportall/ExportAllManager.java | 33 ++++--- .../viewpages/en/docs_export_all.xml | 6 +- .../main/webapp/files/directory-export-v2.xsd | 95 +++++++++++++++++++ .../PublicSearchXServletHandlerTest.java | 13 ++- 6 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 phoss-directory-publisher/src/main/webapp/files/directory-export-v2.xsd diff --git a/README.md b/README.md index 5d90770d..6e2ab490 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The official PEPPOL Directory (PD; former PEPPOL Yellow Pages - PYP; www.peppol. * Updated to Jersey 2.29 * `PDClientConfiguration` can now be re-initialized during runtime * Known document type identifiers and process identifiers can now be used (see [issue #13](https://github.com/phax/phoss-directory/issues/13)) + * Extended XML export to include the new document types (see [issue #41](https://github.com/phax/phoss-directory/issues/41)) * v0.8.0 - 2019-06-27 * Renamed project `peppol-directory` to `phoss-directory` * **Maven artifact IDs changed** from `peppol-directory*` to `phoss-directory*` diff --git a/phoss-directory-publisher/pom.xml b/phoss-directory-publisher/pom.xml index 319451fd..2e9f2a25 100644 --- a/phoss-directory-publisher/pom.xml +++ b/phoss-directory-publisher/pom.xml @@ -149,6 +149,31 @@ ${basedir}/src/main/webapp + diff --git a/phoss-directory-publisher/src/main/java/com/helger/pd/publisher/exportall/ExportAllManager.java b/phoss-directory-publisher/src/main/java/com/helger/pd/publisher/exportall/ExportAllManager.java index 9dae3ef9..c348889c 100644 --- a/phoss-directory-publisher/src/main/java/com/helger/pd/publisher/exportall/ExportAllManager.java +++ b/phoss-directory-publisher/src/main/java/com/helger/pd/publisher/exportall/ExportAllManager.java @@ -39,7 +39,6 @@ import com.helger.commons.state.ESuccess; import com.helger.commons.string.StringHelper; import com.helger.pd.businesscard.generic.PDBusinessCard; -import com.helger.pd.businesscard.generic.PDBusinessEntity; import com.helger.pd.businesscard.generic.PDIdentifier; import com.helger.pd.indexer.mgr.PDMetaManager; import com.helger.pd.indexer.storage.EQueryMode; @@ -77,27 +76,37 @@ public static IMicroDocument queryAllContainedBusinessCardsAsXML (@Nonnull final final Query aQuery = eQueryMode.getEffectiveQuery (new MatchAllDocsQuery ()); // Query all and group by participant ID - final MultiLinkedHashMapArrayListBased aMap = new MultiLinkedHashMapArrayListBased <> (); - PDMetaManager.getStorageMgr () - .searchAllDocuments (aQuery, - -1, - x -> aMap.putSingle (x.getParticipantID (), x.getAsBusinessEntity ())); + final MultiLinkedHashMapArrayListBased aMap = new MultiLinkedHashMapArrayListBased <> (); + PDMetaManager.getStorageMgr ().searchAllDocuments (aQuery, -1, x -> aMap.putSingle (x.getParticipantID (), x)); // XML root final IMicroDocument aDoc = new MicroDocument (); - final String sNamespaceURI = "http://www.peppol.eu/schema/pd/businesscard-generic/201806/"; + final String sNamespaceURI = "http://www.peppol.eu/schema/pd/businesscard-generic/201907/"; final IMicroElement aRoot = aDoc.appendElement (sNamespaceURI, "root"); - aRoot.setAttribute ("version", "1"); + aRoot.setAttribute ("version", "2"); aRoot.setAttribute ("creationdt", PDTWebDateHelper.getAsStringXSD (PDTFactory.getCurrentZonedDateTimeUTC ())); // For all BCs - for (final Map.Entry > aEntry : aMap.entrySet ()) + for (final Map.Entry > aEntry : aMap.entrySet ()) { final IParticipantIdentifier aParticipantID = aEntry.getKey (); + final PDBusinessCard aBC = new PDBusinessCard (); aBC.setParticipantIdentifier (new PDIdentifier (aParticipantID.getScheme (), aParticipantID.getValue ())); - aBC.businessEntities ().addAll (aEntry.getValue ()); - aRoot.appendChild (aBC.getAsMicroXML (sNamespaceURI, "businesscard")); + for (final PDStoredBusinessEntity aSBE : aEntry.getValue ()) + aBC.businessEntities ().add (aSBE.getAsBusinessEntity ()); + final IMicroElement eBC = aBC.getAsMicroXML (sNamespaceURI, "businesscard"); + + // New in v2 - add all Document types + if (aEntry.getValue ().isNotEmpty ()) + for (final IDocumentTypeIdentifier aDocTypeID : aEntry.getValue ().getFirst ().documentTypeIDs ()) + { + eBC.appendElement (sNamespaceURI, "doctypeid") + .setAttribute ("scheme", aDocTypeID.getScheme ()) + .setAttribute ("value", aDocTypeID.getValue ()); + } + + aRoot.appendChild (eBC); } return aDoc; @@ -124,6 +133,7 @@ static ESuccess writeFileXML (@Nonnull final IMicroDocument aDoc) LOGGER.error ("Failed to export all BCs as XML to " + f.getAbsolutePath ()); return ESuccess.FAILURE; } + LOGGER.info ("Successfully wrote all BCs as XML to " + f.getAbsolutePath ()); } finally { @@ -240,6 +250,7 @@ static ESuccess writeFileExcel (@Nonnull final Function aFileWr LOGGER.error ("Failed to export all BCs as XLSX to " + f.getAbsolutePath ()); return ESuccess.FAILURE; } + LOGGER.info ("Successfully exported all BCs as XLSX to " + f.getAbsolutePath ()); } finally { diff --git a/phoss-directory-publisher/src/main/resources/viewpages/en/docs_export_all.xml b/phoss-directory-publisher/src/main/resources/viewpages/en/docs_export_all.xml index 6a0abbf1..7416e511 100644 --- a/phoss-directory-publisher/src/main/resources/viewpages/en/docs_export_all.xml +++ b/phoss-directory-publisher/src/main/resources/viewpages/en/docs_export_all.xml @@ -29,7 +29,11 @@
  • The data is updated once a day.
  • The XML Schema for the XML responses can be downloaded from - /files/directory-export-v1.xsd. + /files/directory-export-v2.xsd +
  • +
  • + XML schema old versions: + /files/directory-export-v1.xsd
  • diff --git a/phoss-directory-publisher/src/main/webapp/files/directory-export-v2.xsd b/phoss-directory-publisher/src/main/webapp/files/directory-export-v2.xsd new file mode 100644 index 00000000..b8aac4f0 --- /dev/null +++ b/phoss-directory-publisher/src/main/webapp/files/directory-export-v2.xsd @@ -0,0 +1,95 @@ + + + + + + XML Schema for the Directory export data. + Version 2 + Last update: 2019-07-19 + Author: Philip Helger + + This XSD is only needed in the Directory export. + Additional XSDs are available for the business cards (BCs) as well as for the search results. + + History: + * v2 - 2019-07-19 + * Added document type IDs + * v1 - 2018-10-29 + * Initial release + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The root element of the exported data. + + + + diff --git a/phoss-directory-publisher/src/test/java/com/helger/pd/publisher/servlet/PublicSearchXServletHandlerTest.java b/phoss-directory-publisher/src/test/java/com/helger/pd/publisher/servlet/PublicSearchXServletHandlerTest.java index df7fcd76..37293401 100644 --- a/phoss-directory-publisher/src/test/java/com/helger/pd/publisher/servlet/PublicSearchXServletHandlerTest.java +++ b/phoss-directory-publisher/src/test/java/com/helger/pd/publisher/servlet/PublicSearchXServletHandlerTest.java @@ -34,9 +34,8 @@ */ public final class PublicSearchXServletHandlerTest { - @Test - public void testParseXSDExport () + public void testParseXSDExportV1 () { // Demo validation final CollectingSAXErrorHandler aErrHdl = new CollectingSAXErrorHandler (); @@ -45,6 +44,16 @@ public void testParseXSDExport () assertTrue (aErrHdl.getErrorList ().toString (), aErrHdl.getErrorList ().isEmpty ()); } + @Test + public void testParseXSDExportV2 () + { + // Demo validation + final CollectingSAXErrorHandler aErrHdl = new CollectingSAXErrorHandler (); + final Validator v = new XMLSchemaCache (aErrHdl).getValidator (new FileSystemResource ("src/main/webapp/files/directory-export-v2.xsd")); + assertNotNull (v); + assertTrue (aErrHdl.getErrorList ().toString (), aErrHdl.getErrorList ().isEmpty ()); + } + @Test public void testParseXSDSearch () {