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);
}
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));
}
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;
}
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;
}
use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class ExportHelper method getAsXML.
@Nonnull
public static IMicroDocument getAsXML(@Nonnull final ICommonsOrderedMap<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aMap, final boolean bIncludeDocTypes) {
// XML root
final IMicroDocument aDoc = new MicroDocument();
final IMicroElement aRoot = aDoc.appendElement(XML_EXPORT_NS_URI, "root");
aRoot.setAttribute("version", "2");
aRoot.setAttribute("creationdt", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentZonedDateTimeUTC()));
// For all BCs
for (final Map.Entry<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aEntry : aMap.entrySet()) {
final IParticipantIdentifier aParticipantID = aEntry.getKey();
final PDBusinessCard aBC = new PDBusinessCard();
aBC.setParticipantIdentifier(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
for (final PDStoredBusinessEntity aSBE : aEntry.getValue()) aBC.businessEntities().add(aSBE.getAsBusinessEntity());
final IMicroElement eBC = aBC.getAsMicroXML(XML_EXPORT_NS_URI, "businesscard");
// New in v2 - add all Document types
if (bIncludeDocTypes && aEntry.getValue().isNotEmpty())
for (final IDocumentTypeIdentifier aDocTypeID : aEntry.getValue().getFirst().documentTypeIDs()) eBC.appendChild(_createMicroElement(aDocTypeID));
aRoot.appendChild(eBC);
}
return aDoc;
}
Aggregations