Skip to content

Commit

Permalink
Extended export format to contain document types; #41
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jul 19, 2019
1 parent eeb85ab commit 8749513
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*`
Expand Down
25 changes: 25 additions & 0 deletions phoss-directory-publisher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@
<sourceDirectory>${basedir}/src/main/webapp</sourceDirectory>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<bindingDirectory>${basedir}/src/main/jaxb</bindingDirectory>
<schemaDirectory>${basedir}/src/main/webapp/files</schemaDirectory>
<schemaIncludes>
<schemaInclude>directory-export-v1.xsd</schemaInclude>
<schemaInclude>directory-export-v2.xsd</schemaInclude>
<schemaInclude>directory-search-result-list-v1.xsd</schemaInclude>
</schemaIncludes>
<extension>true</extension>
<strict>false</strict>
</configuration>
</plugin>
-->
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <IParticipantIdentifier, PDBusinessEntity> aMap = new MultiLinkedHashMapArrayListBased <> ();
PDMetaManager.getStorageMgr ()
.searchAllDocuments (aQuery,
-1,
x -> aMap.putSingle (x.getParticipantID (), x.getAsBusinessEntity ()));
final MultiLinkedHashMapArrayListBased <IParticipantIdentifier, PDStoredBusinessEntity> 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 <IParticipantIdentifier, ICommonsList <PDBusinessEntity>> aEntry : aMap.entrySet ())
for (final Map.Entry <IParticipantIdentifier, ICommonsList <PDStoredBusinessEntity>> 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;
Expand All @@ -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
{
Expand Down Expand Up @@ -240,6 +250,7 @@ static ESuccess writeFileExcel (@Nonnull final Function <File, ESuccess> 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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
<li>The data is updated once a day.</li>
<li>
The XML Schema for the XML responses can be downloaded from
<a href="../../files/directory-export-v1.xsd">/files/directory-export-v1.xsd</a>.
<a href="../../files/directory-export-v2.xsd">/files/directory-export-v2.xsd</a>
</li>
<li>
XML schema old versions:
<a href="../../files/directory-export-v1.xsd">/files/directory-export-v1.xsd</a>
</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015-2019 Philip Helger (www.helger.com)
philip[at]helger[dot]com
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.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.peppol.eu/schema/pd/businesscard-generic/201907/"
xmlns="http://www.peppol.eu/schema/pd/businesscard-generic/201907/"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:annotation>
<xs:documentation>
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
</xs:documentation>
</xs:annotation>

<xs:complexType name="IDType">
<xs:attribute name="scheme" type="xs:string" use="optional" />
<xs:attribute name="value" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="NameType">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="language" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="ContactType">
<xs:attribute name="email" type="xs:string" use="optional" />
<xs:attribute name="name" type="xs:string" use="optional" />
<xs:attribute name="phonenumber" type="xs:string" use="optional" />
<xs:attribute name="type" type="xs:string" use="optional" />
</xs:complexType>

<xs:complexType name="EntityType">
<xs:sequence>
<xs:element name="name" type="NameType" maxOccurs="unbounded" />
<xs:element name="geoinfo" type="xs:string" minOccurs="0" />
<xs:element name="id" type="IDType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="website" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="contact" type="ContactType" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="additionalinfo" type="xs:string" minOccurs="0" />
</xs:sequence>
<xs:attribute name="countrycode" type="xs:string" use="required" />
</xs:complexType>

<xs:complexType name="BusinessCardType">
<xs:sequence>
<xs:element name="participant" type="IDType" />
<xs:element name="entity" type="EntityType" maxOccurs="unbounded" />
<xs:element name="doctypeid" type="IDType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="businesscard" type="BusinessCardType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required" />
<xs:attribute name="creationdt" type="xs:dateTime" use="required" />
</xs:complexType>

<xs:element name="root" type="RootType">
<xs:annotation>
<xs:documentation>
The root element of the exported data.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
*/
public final class PublicSearchXServletHandlerTest
{

@Test
public void testParseXSDExport ()
public void testParseXSDExportV1 ()
{
// Demo validation
final CollectingSAXErrorHandler aErrHdl = new CollectingSAXErrorHandler ();
Expand All @@ -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 ()
{
Expand Down

0 comments on commit 8749513

Please # to comment.