diff --git a/README.md b/README.md index 5142cc12..e012d48d 100644 --- a/README.md +++ b/README.md @@ -302,6 +302,7 @@ They depend on several other libraries so I suggest you are going for the Maven * v9.5.1 - work in progress * Make sure that wildcard lookups including a "*" in the Customization ID will always fail + * Added additional `SMPClientReadOnly.getWildcardServiceMetadataOrNull` overload * v9.5.0 - 2024-07-29 * Updated to dnsjava 3.6 fixing CVE-2024-25638 * Added new submodule `dbnalliance-xhe`. See [#53](https://github.com/phax/peppol-commons/pull/53) - thx @robinsongarciax diff --git a/peppol-smp-client/src/main/java/com/helger/smpclient/peppol/SMPClientReadOnly.java b/peppol-smp-client/src/main/java/com/helger/smpclient/peppol/SMPClientReadOnly.java index a81e2177..9d2a9e9b 100644 --- a/peppol-smp-client/src/main/java/com/helger/smpclient/peppol/SMPClientReadOnly.java +++ b/peppol-smp-client/src/main/java/com/helger/smpclient/peppol/SMPClientReadOnly.java @@ -997,17 +997,56 @@ public SignedServiceMetadataType getWildcardServiceMetadataOrNull (@Nonnull fina } @Nullable - public SignedServiceMetadataType getWildcardServiceMetadataOrNull (@Nonnull final IParticipantIdentifier aReceiverID, + public SignedServiceMetadataType getWildcardServiceMetadataOrNull (@Nonnull final ServiceGroupType aServiceGroup, + @Nonnull final IParticipantIdentifier aReceiverID, @Nonnull final IDocumentTypeIdentifier aDocTypeID, @Nonnull final PeppolWildcardSelector.EMode eSelectionMode) throws SMPClientException { + ValueEnforcer.notNull (aServiceGroup, "ServiceGroup"); ValueEnforcer.notNull (aReceiverID, "ReceiverID"); ValueEnforcer.notNull (aDocTypeID, "DocTypeID"); ValueEnforcer.notNull (eSelectionMode, "SelectionMode"); - final SignedServiceMetadataType aSSM; + // Extract all document types from SMP result + final ICommonsList aSupportedDocTypes = SMPClientReadOnly.getAllDocumentTypes (aServiceGroup); + + LOGGER.info ("Found " + + aSupportedDocTypes.size () + + " supported document types for '" + + aReceiverID.getURIEncoded () + + "'"); + + // Main matching + final Wrapper aMatchingDocType = new Wrapper <> (); + new PeppolWildcardSelector (eSelectionMode).forEachMatchingDocumentType (aSupportedDocTypes, + aDocTypeID.getValue (), + dt -> { + aMatchingDocType.set (dt); + return EContinue.BREAK; + }); + + final IDocumentTypeIdentifier aSelectedDocTypeID = aMatchingDocType.get (); + if (aSelectedDocTypeID == null) + { + LOGGER.info ("Found no matching document type ID to be queried via Wildcard"); + return null; + } + + LOGGER.info ("Using '" + aSelectedDocTypeID.getURIEncoded () + "' for defacto querying the SMP"); + // Do the main SMP lookup on the metadata + return getServiceMetadataOrNull (aReceiverID, aSelectedDocTypeID); + } + + @Nullable + public SignedServiceMetadataType getWildcardServiceMetadataOrNull (@Nonnull final IParticipantIdentifier aReceiverID, + @Nonnull final IDocumentTypeIdentifier aDocTypeID, + @Nonnull final PeppolWildcardSelector.EMode eSelectionMode) throws SMPClientException + { + ValueEnforcer.notNull (aReceiverID, "ReceiverID"); + ValueEnforcer.notNull (aDocTypeID, "DocTypeID"); + ValueEnforcer.notNull (eSelectionMode, "SelectionMode"); - // PINT/DDTS specific lookup + // Wildcard specific lookup LOGGER.info ("Using SMP wildcard lookup for '" + aReceiverID.getURIEncoded () + "' on '" + @@ -1018,44 +1057,10 @@ public SignedServiceMetadataType getWildcardServiceMetadataOrNull (@Nonnull fina // 1. query all document types from SMP final ServiceGroupType aSG = getServiceGroupOrNull (aReceiverID); if (aSG == null) - { - // Invalid participant ID - aSSM = null; - } - else - { - // Extract all document types from SMP result - final ICommonsList aSupportedDocTypes = SMPClientReadOnly.getAllDocumentTypes (aSG); - - LOGGER.info ("Found " + - aSupportedDocTypes.size () + - " supported document types for '" + - aReceiverID.getURIEncoded () + - "'"); - - // Main matching - final Wrapper aMatchingDocType = new Wrapper <> (); - new PeppolWildcardSelector (eSelectionMode).forEachMatchingDocumentType (aSupportedDocTypes, - aDocTypeID.getValue (), - dt -> { - aMatchingDocType.set (dt); - return EContinue.BREAK; - }); - - final IDocumentTypeIdentifier aSelectedDocTypeID = aMatchingDocType.get (); - if (aSelectedDocTypeID != null) - { - LOGGER.info ("Using '" + aSelectedDocTypeID.getURIEncoded () + "' for defacto querying the SMP"); - // Do the main SMP lookup on the metadata - aSSM = getServiceMetadataOrNull (aReceiverID, aSelectedDocTypeID); - } - else - { - LOGGER.info ("Found no matching document type ID to be queried via Wildcard"); - aSSM = null; - } - } - return aSSM; + return null; + + // Select and query service metadata + return getWildcardServiceMetadataOrNull (aSG, aReceiverID, aDocTypeID, eSelectionMode); } /**