Skip to content

Commit

Permalink
Added additional SMPClientReadOnly.getWildcardServiceMetadataOrNull
Browse files Browse the repository at this point in the history
overload
  • Loading branch information
phax committed Aug 7, 2024
1 parent 45eb691 commit b6892dd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <IDocumentTypeIdentifier> aSupportedDocTypes = SMPClientReadOnly.getAllDocumentTypes (aServiceGroup);

LOGGER.info ("Found " +
aSupportedDocTypes.size () +
" supported document types for '" +
aReceiverID.getURIEncoded () +
"'");

// Main matching
final Wrapper <IDocumentTypeIdentifier> 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 '" +
Expand All @@ -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 <IDocumentTypeIdentifier> aSupportedDocTypes = SMPClientReadOnly.getAllDocumentTypes (aSG);

LOGGER.info ("Found " +
aSupportedDocTypes.size () +
" supported document types for '" +
aReceiverID.getURIEncoded () +
"'");

// Main matching
final Wrapper <IDocumentTypeIdentifier> 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);
}

/**
Expand Down

0 comments on commit b6892dd

Please sign in to comment.