Search in sources :

Example 26 with ServiceGroupType

use of com.helger.xsds.peppol.smp1.ServiceGroupType in project peppol-commons by phax.

the class SMPClientReadOnly method getAllDocumentTypes.

/**
 * Extract all parsable document types from the passed Service group. This
 * method always uses {@link PeppolIdentifierFactory} to parse the document
 * type identifiers.
 *
 * @param aSG
 *        The service group to parse. May be <code>null</code>.
 * @param aIdentifierFactory
 *        The identifier factory to be used. May not be <code>null</code>.
 * @param aUnhandledHrefHandler
 *        An optional consumer for Hrefs that could not be parsed into a
 *        document type identifier. May be <code>null</code>.
 * @return Never <code>null</code> but a maybe empty list.
 * @since 8.0.4
 */
@Nonnull
public static ICommonsList<IDocumentTypeIdentifier> getAllDocumentTypes(@Nullable final ServiceGroupType aSG, @Nonnull final IIdentifierFactory aIdentifierFactory, @Nullable final Consumer<String> aUnhandledHrefHandler) {
    ValueEnforcer.notNull(aIdentifierFactory, "IdentifierFactory");
    final ICommonsList<IDocumentTypeIdentifier> ret = new CommonsArrayList<>();
    if (aSG != null && aSG.getParticipantIdentifier() != null && aSG.getServiceMetadataReferenceCollection() != null) {
        final String sPathStart = "/" + CIdentifier.getURIEncoded(aSG.getParticipantIdentifier()) + "/" + URL_PART_SERVICES + "/";
        for (final ServiceMetadataReferenceType aSMR : aSG.getServiceMetadataReferenceCollection().getServiceMetadataReference()) {
            final String sOriginalHref = aSMR.getHref();
            // Decoded href is important for unification
            final String sHref = CIdentifier.createPercentDecoded(sOriginalHref);
            boolean bSuccess = false;
            // Case insensitive "indexOf" here
            final int nPathStart = StringHelper.getIndexOfIgnoreCase(sHref, sPathStart, Locale.US);
            if (nPathStart >= 0) {
                final String sDocType = sHref.substring(nPathStart + sPathStart.length());
                final IDocumentTypeIdentifier aDocType = aIdentifierFactory.parseDocumentTypeIdentifier(sDocType);
                if (aDocType != null) {
                    // Found a document type
                    ret.add(aDocType);
                    bSuccess = true;
                }
            }
            if (!bSuccess) {
                // Failed to parse as doc type
                if (aUnhandledHrefHandler != null)
                    aUnhandledHrefHandler.accept(sOriginalHref);
            }
        }
    }
    return ret;
}
Also used : ServiceMetadataReferenceType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceType) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nonnull(javax.annotation.Nonnull)

Example 27 with ServiceGroupType

use of com.helger.xsds.peppol.smp1.ServiceGroupType in project peppol-commons by phax.

the class SMPDebugHelper method getAsString.

@Nonnull
public static String getAsString(@Nonnull final ServiceGroupType aServiceGroup) {
    final StringBuilder aSB = new StringBuilder();
    aSB.append("ServiceGroup information:\n");
    aSB.append("ParticipantIdentifier: ").append(CIdentifier.getURIEncoded(aServiceGroup.getParticipantIdentifier())).append('\n');
    // References
    final ServiceMetadataReferenceCollectionType aSMRC = aServiceGroup.getServiceMetadataReferenceCollection();
    if (aSMRC != null && !aSMRC.getServiceMetadataReference().isEmpty()) {
        aSB.append("ServiceMetadataReferenceCollection:\n");
        for (final ServiceMetadataReferenceType aSMR : aSMRC.getServiceMetadataReference()) aSB.append("  ").append(aSMR.getHref()).append('\n');
    }
    // Extension
    final ExtensionType aExt = aServiceGroup.getExtension();
    if (aExt != null && aExt.getAny() != null) {
        aSB.append("Extension:\n");
        aSB.append("  Class = ").append(aExt.getAny().getClass().getName()).append('\n');
        aSB.append("  Value = ").append(aExt.getAny()).append('\n');
    }
    return aSB.toString();
}
Also used : ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) ServiceMetadataReferenceType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceType) ExtensionType(com.helger.xsds.peppol.smp1.ExtensionType) Nonnull(javax.annotation.Nonnull)

Example 28 with ServiceGroupType

use of com.helger.xsds.peppol.smp1.ServiceGroupType in project peppol-commons by phax.

the class MainSMPServiceGroupList method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Get the service group information
    final ServiceGroupType aServiceGroup = aClient.getServiceGroupOrNull(PARTICIPANT_ID);
    if (aServiceGroup == null)
        LOGGER.error("Failed to get service group infos for " + PARTICIPANT_ID);
    else
        LOGGER.info(SMPDebugHelper.getAsString(aServiceGroup));
    LOGGER.info("Done");
}
Also used : SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 29 with ServiceGroupType

use of com.helger.xsds.peppol.smp1.ServiceGroupType in project peppol-commons by phax.

the class BDXR2ClientReadOnly method getServiceGroup.

/**
 * Returns a service group. A service group references to the service
 * metadata. This is a specification compliant method.
 *
 * @param aServiceGroupID
 *        The service group id corresponding to the service group which one
 *        wants to get.
 * @return The service group. Never <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientNotFoundException
 *         The service group id did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceGroupOrNull(IParticipantIdentifier)
 */
@Nonnull
public ServiceGroupType getServiceGroup(@Nonnull final IParticipantIdentifier aServiceGroupID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    final String sURI = getSMPHostURI() + PATH_OASIS_BDXR_SMP_2 + aServiceGroupID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("BDXR2Client getServiceGroup@" + sURI);
    final HttpGet aRequest = new HttpGet(sURI);
    final BDXR2ServiceGroupMarshaller aMarshaller = new BDXR2ServiceGroupMarshaller(isXMLSchemaValidation());
    customizeMarshaller(aMarshaller);
    final ServiceGroupType ret = executeGenericRequest(aRequest, new SMPHttpResponseHandlerUnsigned<>(aMarshaller));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Received response: " + ret);
    return ret;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BDXR2ServiceGroupMarshaller(com.helger.smpclient.bdxr2.marshal.BDXR2ServiceGroupMarshaller) ServiceGroupType(com.helger.xsds.bdxr.smp2.ServiceGroupType) Nonnull(javax.annotation.Nonnull)

Aggregations

ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)18 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)17 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)14 Test (org.junit.Test)13 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)12 Nonnull (javax.annotation.Nonnull)12 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 Response (javax.ws.rs.core.Response)9 WebTarget (javax.ws.rs.client.WebTarget)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)6 SMPClient (com.helger.smpclient.peppol.SMPClient)5 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)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 MockSMPClient (com.helger.phoss.smp.mock.MockSMPClient)4 ServiceGroupType (com.helger.xsds.bdxr.smp1.ServiceGroupType)4 CompleteServiceGroupType (com.helger.xsds.peppol.smp1.CompleteServiceGroupType)4