Search in sources :

Example 21 with ServiceMetadataType

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

the class BDXR2Client method saveServiceEndpoints.

/**
 * Saves a service information data object.
 *
 * @param aServiceGroupID
 *        The service group ID to use. May not be <code>null</code>.
 * @param aDocumentTypeID
 *        The document type ID to use. May not be <code>null</code>.
 * @param aEndpoints
 *        The endpoints to the created or updated. May not be
 *        <code>null</code>.
 * @param aCredentials
 *        The user name and password to use as credentials. May not be
 *        <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The user name or password was not correct.
 * @throws SMPClientNotFoundException
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #saveServiceRedirect(ParticipantIDType, IDType, RedirectType,
 *      BasicAuthClientCredentials)
 */
public void saveServiceEndpoints(@Nonnull final ParticipantIDType aServiceGroupID, @Nonnull final IDType aDocumentTypeID, @Nonnull final List<EndpointType> aEndpoints, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aEndpoints, "Endpoints");
    ValueEnforcer.notNull(aCredentials, "Credentials");
    final ServiceMetadataType aServiceMetadata = new ServiceMetadataType();
    aServiceMetadata.setSMPVersionID("2.0");
    aServiceMetadata.setID(aDocumentTypeID);
    aServiceMetadata.setParticipantID(aServiceGroupID);
    final ProcessMetadataType aPM = new ProcessMetadataType();
    aPM.getEndpoint().addAll(aEndpoints);
    aServiceMetadata.addProcessMetadata(aPM);
    _saveServiceInformation(aServiceMetadata, aCredentials);
}
Also used : ServiceMetadataType(com.helger.xsds.bdxr.smp2.ServiceMetadataType) ProcessMetadataType(com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType)

Example 22 with ServiceMetadataType

use of com.helger.xsds.bdxr.smp2.ServiceMetadataType 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

ServiceMetadataType (com.helger.xsds.peppol.smp1.ServiceMetadataType)11 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)8 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)7 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)6 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)5 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)5 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)5 ServiceMetadataType (com.helger.xsds.bdxr.smp1.ServiceMetadataType)5 Nonnull (javax.annotation.Nonnull)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)4 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)4 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)4 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)4 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)4 ProcessMetadataType (com.helger.xsds.bdxr.smp2.ac.ProcessMetadataType)4 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)3 PeppolProcessIdentifier (com.helger.peppolid.peppol.process.PeppolProcessIdentifier)3 ServiceMetadataType (com.helger.xsds.bdxr.smp2.ServiceMetadataType)3