use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDStoredBusinessEntity method getAsSearchResultJsonObject.
@Nonnull
public static IJsonObject getAsSearchResultJsonObject(@Nonnull @Nonempty final ICommonsList<PDStoredBusinessEntity> aDocs) {
ValueEnforcer.notEmptyNoNullValue(aDocs, "Docs");
final PDStoredBusinessEntity aFirst = aDocs.getFirst();
final IJsonObject ret = new JsonObject();
ret.addJson("participantID", _getIDAsJson(aFirst.m_aParticipantID.getScheme(), aFirst.m_aParticipantID.getValue()));
// Add the items retrieved from SMP as well
final IJsonArray aDocTypes = new JsonArray();
for (final IDocumentTypeIdentifier aDocTypeID : aFirst.m_aDocumentTypeIDs) aDocTypes.add(_getIDAsJson(aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (aDocTypes.isNotEmpty())
ret.addJson("docTypes", aDocTypes);
final IJsonArray aEntities = new JsonArray();
for (final PDStoredBusinessEntity aDoc : aDocs) {
final IJsonObject aEntity = new JsonObject();
// Multilingual names
final IJsonArray aMLNames = new JsonArray();
for (final PDStoredMLName aName : aDoc.m_aNames) aMLNames.add(_getMLNameAsJson(aName.getName(), aName.getLanguageCode()));
if (aMLNames.isNotEmpty())
aEntity.addJson("name", aMLNames);
aEntity.add("countryCode", aDoc.m_sCountryCode);
if (StringHelper.hasText(aDoc.m_sGeoInfo))
aEntity.add("geoInfo", aDoc.m_sGeoInfo);
final IJsonArray aIDs = new JsonArray();
for (final PDStoredIdentifier aID : aDoc.m_aIdentifiers) aIDs.add(_getIDAsJson(aID.getScheme(), aID.getValue()));
if (aIDs.isNotEmpty())
aEntity.addJson("identifiers", aIDs);
final IJsonArray aWebsites = new JsonArray();
for (final String sWebsite : aDoc.m_aWebsiteURIs) aWebsites.add(sWebsite);
if (aWebsites.isNotEmpty())
aEntity.addJson("websites", aWebsites);
final IJsonArray aContacts = new JsonArray();
for (final PDStoredContact aContact : aDoc.m_aContacts) aContacts.add(new JsonObject().addIfNotNull("type", aContact.getType()).addIfNotNull("name", aContact.getName()).addIfNotNull("phone", aContact.getPhone()).addIfNotNull("email", aContact.getEmail()));
if (aContacts.isNotEmpty())
aEntity.addJson("contacts", aContacts);
if (StringHelper.hasText(aDoc.m_sAdditionalInformation))
aEntity.add("additionalInfo", aDoc.m_sAdditionalInformation);
if (aDoc.m_aRegistrationDate != null)
aEntity.add("regDate", PDTWebDateHelper.getAsStringXSD(aDoc.m_aRegistrationDate));
aEntities.add(aEntity);
}
ret.addJson("entities", aEntities);
return ret;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDExtendedBusinessCard method of.
@Nonnull
public static PDExtendedBusinessCard of(@Nonnull final IJsonObject aJson) {
final PDBusinessCard aBC = PDBusinessCard.of(aJson.getAsObject("businesscard"));
final ICommonsList<IDocumentTypeIdentifier> aDocTypes = CommonsArrayList.createFiltered(aJson.getAsArray("doctypes"), (Predicate<IJson>) IJson::isObject, x -> new SimpleDocumentTypeIdentifier(x.getAsObject().getAsString("scheme"), x.getAsObject().getAsString("value")));
return new PDExtendedBusinessCard(aBC, aDocTypes);
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class SMPBusinessCardProvider method getBusinessCardBDXR2.
@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR2(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXR2ClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v2 '" + aSMPClient.getSMPHostURI() + "'");
// First query the service group
com.helger.xsds.bdxr.smp2.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
// TODO is the path "bdxr-smp-2" needed? Well, the PD is not yet
// specified for this SMP type....
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 = BDXR2ClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory);
return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class SMPBusinessCardProvider method getBusinessCardBDXR1.
@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR1(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXRClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v1 '" + aSMPClient.getSMPHostURI() + "'");
// First query the service group
com.helger.xsds.bdxr.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 = BDXRClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDQueryManager method getDocumentTypeIDLuceneQuery.
@Nullable
public static Query getDocumentTypeIDLuceneQuery(@Nonnull @Nonempty final String sQueryString) {
ValueEnforcer.notEmpty(sQueryString, "QueryString");
ValueEnforcer.notEmpty(sQueryString.trim(), "QueryString trimmed");
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
// No casing here!
final IDocumentTypeIdentifier aDTI = aIdentifierFactory.parseDocumentTypeIdentifier(sQueryString);
if (aDTI == null) {
LOGGER.warn("Failed to convert '" + sQueryString + "' to document type ID!");
return null;
}
final Query aQuery = new TermQuery(PDField.DOCTYPE_ID.getExactMatchTerm(aDTI));
return aQuery;
}
Aggregations