Search in sources :

Example 1 with ProcessType

use of com.helger.xsds.bdxr.smp2.ac.ProcessType in project peppol-commons by phax.

the class BDXR2ClientReadOnly method getEndpoint.

/**
 * Extract the Endpoint from the ServiceMetadata that matches the passed
 * process ID and the optional required transport profile.
 *
 * @param aServiceMetadata
 *        The service meta data object (e.g. from a call to
 *        {@link #getServiceMetadataOrNull(IParticipantIdentifier, IDocumentTypeIdentifier)}
 *        . May not be <code>null</code>.
 * @param aProcessID
 *        The process identifier to be looked up. May not be <code>null</code>
 *        .
 * @param aTransportProfile
 *        The required transport profile to be used. May not be
 *        <code>null</code>.
 * @return <code>null</code> if no matching endpoint was found
 */
@Nullable
public static EndpointType getEndpoint(@Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final IProcessIdentifier aProcessID, @Nonnull final ISMPTransportProfile aTransportProfile) {
    ValueEnforcer.notNull(aServiceMetadata, "SignedServiceMetadata");
    ValueEnforcer.notNull(aProcessID, "ProcessID");
    ValueEnforcer.notNull(aTransportProfile, "TransportProfile");
    // Iterate all processes
    for (final ProcessMetadataType aPM : aServiceMetadata.getProcessMetadata()) {
        boolean bMatchesProcess = false;
        for (final ProcessType aP : aPM.getProcess()) if (SimpleProcessIdentifier.wrap(aP.getID()).hasSameContent(aProcessID)) {
            bMatchesProcess = true;
            break;
        }
        if (bMatchesProcess) {
            final ICommonsList<EndpointType> aRelevantEndpoints = new CommonsArrayList<>();
            for (final EndpointType aEndpoint : aPM.getEndpoint()) if (aTransportProfile.getID().equals(aEndpoint.getTransportProfileIDValue()))
                aRelevantEndpoints.add(aEndpoint);
            if (aRelevantEndpoints.size() != 1) {
                if (LOGGER.isWarnEnabled())
                    LOGGER.warn("Found " + aRelevantEndpoints.size() + " endpoints for process '" + aProcessID.getURIEncoded() + "' and transport profile '" + aTransportProfile.getID() + "'" + (aRelevantEndpoints.isEmpty() ? "" : ": " + aRelevantEndpoints.toString() + " - using the first one"));
            }
            // Use the first endpoint or null
            final EndpointType ret = aRelevantEndpoints.getFirst();
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Found matching endpoint: " + ret);
            return ret;
        }
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Found no matching SMP endpoint");
    return null;
}
Also used : ProcessType(com.helger.xsds.bdxr.smp2.ac.ProcessType) EndpointType(com.helger.xsds.bdxr.smp2.ac.EndpointType) ProcessMetadataType(com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nullable(javax.annotation.Nullable)

Aggregations

CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 EndpointType (com.helger.xsds.bdxr.smp2.ac.EndpointType)1 ProcessMetadataType (com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType)1 ProcessType (com.helger.xsds.bdxr.smp2.ac.ProcessType)1 Nullable (javax.annotation.Nullable)1