Search in sources :

Example 6 with PDBusinessCard

use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.

the class PDStoredBusinessEntity method getAsBusinessCard.

/**
 * @return This {@link PDStoredBusinessEntity} as a {@link PDBusinessCard}.
 */
@Nonnull
@ReturnsMutableCopy
public PDBusinessCard getAsBusinessCard() {
    final PDBusinessCard ret = new PDBusinessCard();
    ret.setParticipantIdentifier(new PDIdentifier(m_aParticipantID.getScheme(), m_aParticipantID.getValue()));
    // We have a single entity
    ret.businessEntities().add(getAsBusinessEntity());
    return ret;
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 7 with PDBusinessCard

use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.

the class PDSMPHttpResponseHandlerBusinessCard method handleEntity.

@Override
@Nullable
public PDBusinessCard handleEntity(@Nonnull final HttpEntity aEntity) throws IOException {
    // Read the payload and remember it!
    final ContentType aContentType = ContentType.getOrDefault(aEntity);
    final Charset aCharset = aContentType.getCharset();
    final byte[] aData = StreamHelper.getAllBytes(aEntity.getContent());
    if (aData == null)
        return null;
    final PDBusinessCard aBC = PDBusinessCardHelper.parseBusinessCard(aData, aCharset);
    if (aBC != null)
        return aBC;
    // Unsupported
    throw new ClientProtocolException("Malformed XML document returned from SMP server:\n" + new String(aData, StandardCharsets.UTF_8));
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) ContentType(org.apache.http.entity.ContentType) Charset(java.nio.charset.Charset) ClientProtocolException(org.apache.http.client.ClientProtocolException) Nullable(javax.annotation.Nullable)

Example 8 with PDBusinessCard

use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCardPeppolSMP.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardPeppolSMP(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final SMPClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from Peppol SMP '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup;
    try {
        aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
    } catch (final SMPClientException ex) {
        LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    // If the service group is present, try querying the business card
    final PDBusinessCard aBusinessCard;
    try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
        // Use the optional business card API
        final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
        aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
    } catch (final IOException ex) {
        if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
            LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
        } else
            LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    if (aBusinessCard == null) {
        // No extension present - no need to try again
        LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
        return null;
    }
    // Query all document types
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = SMPClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
    return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 9 with PDBusinessCard

use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.

the class PD2APIHelper method createBusinessCard.

@Nonnull
public static PDBusinessCard createBusinessCard(@Nonnull final PD2BusinessCardType aBC) {
    ValueEnforcer.notNull(aBC, "BusinessCard");
    final PDBusinessCard ret = new PDBusinessCard();
    ret.setParticipantIdentifier(createIdentifier(aBC.getParticipantIdentifier()));
    ret.businessEntities().setAllMapped(aBC.getBusinessEntity(), PD2APIHelper::createBusinessEntity);
    return ret;
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 10 with PDBusinessCard

use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.

the class PD3APIHelper method createBusinessCard.

@Nonnull
public static PDBusinessCard createBusinessCard(@Nonnull final PD3BusinessCardType aBC) {
    ValueEnforcer.notNull(aBC, "BusinessCard");
    final PDBusinessCard ret = new PDBusinessCard();
    ret.setParticipantIdentifier(createIdentifier(aBC.getParticipantIdentifier()));
    ret.businessEntities().setAllMapped(aBC.getBusinessEntity(), PD3APIHelper::createBusinessEntity);
    return ret;
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) Nonnull(javax.annotation.Nonnull)

Aggregations

PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)20 Nonnull (javax.annotation.Nonnull)11 HttpClientManager (com.helger.httpclient.HttpClientManager)8 HttpGet (org.apache.http.client.methods.HttpGet)8 PDIdentifier (com.helger.pd.businesscard.generic.PDIdentifier)7 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)7 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)6 UnknownHostException (java.net.UnknownHostException)6 StopWatch (com.helger.commons.timing.StopWatch)5 ResponseHandlerByteArray (com.helger.httpclient.response.ResponseHandlerByteArray)5 PDBusinessEntity (com.helger.pd.businesscard.generic.PDBusinessEntity)5 PDName (com.helger.pd.businesscard.generic.PDName)5 Nullable (javax.annotation.Nullable)5 HttpResponseException (org.apache.http.client.HttpResponseException)5 IJsonObject (com.helger.json.IJsonObject)4 JsonWriter (com.helger.json.serialize.JsonWriter)4 SMPClientException (com.helger.smpclient.exception.SMPClientException)4 ZonedDateTime (java.time.ZonedDateTime)4 VisibleForTesting (com.helger.commons.annotation.VisibleForTesting)3