use of com.helger.peppolid.IDocumentTypeIdentifier 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.peppolid.IDocumentTypeIdentifier 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;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDStoredBusinessEntity method create.
/**
* Convert a stored Lucene {@link Document} to a
* {@link PDStoredBusinessEntity}. This method resolves all Lucene fields to
* Java fields.
*
* @param aDoc
* Source Lucene document. May not be <code>null</code>.
* @return The new {@link PDStoredBusinessEntity}.
*/
@Nonnull
@ReturnsMutableCopy
public static PDStoredBusinessEntity create(@Nonnull final Document aDoc) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Creating PDStoredDocument from " + aDoc);
final PDStoredBusinessEntity ret = new PDStoredBusinessEntity();
ret.setParticipantID(PDField.PARTICIPANT_ID.getDocValue(aDoc));
for (final IDocumentTypeIdentifier aDocTypeID : PDField.DOCTYPE_ID.getDocValues(aDoc)) if (aDocTypeID != null)
ret.documentTypeIDs().add(aDocTypeID);
ret.setCountryCode(PDField.COUNTRY_CODE.getDocValue(aDoc));
ret.setRegistrationDate(PDTWebDateHelper.getLocalDateFromXSD(PDField.REGISTRATION_DATE.getDocValue(aDoc)));
{
final String sSingleName = PDField.NAME.getDocValue(aDoc);
if (sSingleName != null) {
// No language
ret.names().add(new PDStoredMLName(sSingleName));
} else {
// Multilingual name
final ICommonsList<String> aMLNames = PDField.ML_NAME.getDocValues(aDoc);
final ICommonsList<String> aMLLanguages = PDField.ML_LANGUAGE.getDocValues(aDoc);
if (aMLNames.size() != aMLLanguages.size())
throw new IllegalStateException("Different number of ML names and languages");
for (int i = 0; i < aMLNames.size(); ++i) {
String sLang = aMLLanguages.get(i);
if ("".equals(sLang)) {
// Work around internal error
sLang = null;
}
ret.names().add(new PDStoredMLName(aMLNames.get(i), sLang));
}
}
}
ret.setGeoInfo(PDField.GEO_INFO.getDocValue(aDoc));
{
final ICommonsList<String> aIDTypes = PDField.IDENTIFIER_SCHEME.getDocValues(aDoc);
final ICommonsList<String> aIDValues = PDField.IDENTIFIER_VALUE.getDocValues(aDoc);
if (aIDTypes.size() != aIDValues.size())
throw new IllegalStateException("Different number of identifier types and values");
for (int i = 0; i < aIDTypes.size(); ++i) ret.identifiers().add(new PDStoredIdentifier(aIDTypes.get(i), aIDValues.get(i)));
}
for (final String sWebSite : PDField.WEBSITE_URI.getDocValues(aDoc)) ret.websiteURIs().add(sWebSite);
{
final ICommonsList<String> aBCTypes = PDField.CONTACT_TYPE.getDocValues(aDoc);
final ICommonsList<String> aBCName = PDField.CONTACT_NAME.getDocValues(aDoc);
final ICommonsList<String> aBCPhone = PDField.CONTACT_PHONE.getDocValues(aDoc);
final ICommonsList<String> aBCEmail = PDField.CONTACT_EMAIL.getDocValues(aDoc);
if (aBCTypes.size() != aBCName.size())
throw new IllegalStateException("Different number of business contact types and names");
if (aBCTypes.size() != aBCPhone.size())
throw new IllegalStateException("Different number of business contact types and phones");
if (aBCTypes.size() != aBCEmail.size())
throw new IllegalStateException("Different number of business contact types and emails");
for (int i = 0; i < aBCTypes.size(); ++i) ret.contacts().add(new PDStoredContact(aBCTypes.get(i), aBCName.get(i), aBCPhone.get(i), aBCEmail.get(i)));
}
{
final PDStoredMetaData aMetaData = new PDStoredMetaData(PDField.METADATA_CREATIONDT.getDocValue(aDoc), PDField.METADATA_OWNERID.getDocValue(aDoc), PDField.METADATA_REQUESTING_HOST.getDocValue(aDoc));
ret.setMetaData(aMetaData);
}
ret.setAdditionalInformation(PDField.ADDITIONAL_INFO.getDocValue(aDoc));
return ret;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDStoredBusinessEntity method getAsSearchResultMicroElement.
/**
* Create the REST search response XML element.
*
* @param aDocs
* All the documents that have the same participant ID. May neither be
* <code>null</code> nor empty.
* @return The micro element
*/
@Nonnull
public static IMicroElement getAsSearchResultMicroElement(@Nonnull @Nonempty final ICommonsList<PDStoredBusinessEntity> aDocs) {
ValueEnforcer.notEmptyNoNullValue(aDocs, "Docs");
final PDStoredBusinessEntity aFirst = aDocs.getFirst();
final IMicroElement aMatch = new MicroElement("match");
aMatch.appendElement("participantID").setAttribute("scheme", aFirst.m_aParticipantID.getScheme()).appendText(aFirst.m_aParticipantID.getValue());
// Add all document type IDs
for (final IDocumentTypeIdentifier aDocTypeID : aFirst.m_aDocumentTypeIDs) {
aMatch.appendElement("docTypeID").setAttribute("scheme", aDocTypeID.getScheme()).appendText(aDocTypeID.getValue());
}
// Add all entities
for (final PDStoredBusinessEntity aDoc : aDocs) {
final IMicroElement aEntity = aMatch.appendElement("entity");
for (final PDStoredMLName aName : aDoc.m_aNames) aEntity.appendElement("name").setAttribute("language", aName.getLanguageCode()).appendText(aName.getName());
aEntity.appendElement("countryCode").appendText(aDoc.m_sCountryCode);
if (StringHelper.hasText(aDoc.m_sGeoInfo))
aEntity.appendElement("geoInfo").appendText(aDoc.m_sGeoInfo);
for (final PDStoredIdentifier aID : aDoc.m_aIdentifiers) aEntity.appendElement("identifier").setAttribute("scheme", aID.getScheme()).appendText(aID.getValue());
for (final String sWebsite : aDoc.m_aWebsiteURIs) aEntity.appendElement("website").appendText(sWebsite);
for (final PDStoredContact aContact : aDoc.m_aContacts) aEntity.appendElement("contact").setAttribute("type", aContact.getType()).setAttribute("name", aContact.getName()).setAttribute("phone", aContact.getPhone()).setAttribute("email", aContact.getEmail());
if (StringHelper.hasText(aDoc.m_sAdditionalInformation))
aEntity.appendElement("additionalInfo").appendText(aDoc.m_sAdditionalInformation);
if (aDoc.m_aRegistrationDate != null)
aEntity.appendElement("regDate").appendText(PDTWebDateHelper.getAsStringXSD(aDoc.m_aRegistrationDate));
}
return aMatch;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class AbstractPagePublicSearch method createParticipantDetails.
@Nonnull
protected HCNodeList createParticipantDetails(@Nonnull final Locale aDisplayLocale, @Nonnull final String sParticipantID, @Nonnull final IParticipantIdentifier aParticipantID, final boolean bIsLoggedInUserAdministrator) {
final HCNodeList aDetails = new HCNodeList();
// Search document matching participant ID
final ICommonsList<PDStoredBusinessEntity> aResultDocs = PDMetaManager.getStorageMgr().getAllDocumentsOfParticipant(aParticipantID);
// Group by participant ID
final ICommonsMap<IParticipantIdentifier, ICommonsList<PDStoredBusinessEntity>> aGroupedDocs = PDStorageManager.getGroupedByParticipantID(aResultDocs);
if (aGroupedDocs.isEmpty())
LOGGER.error("No stored document matches participant identifier '" + sParticipantID + "' - cannot show details");
else {
if (aGroupedDocs.size() > 1)
LOGGER.warn("Found " + aGroupedDocs.size() + " entries for participant identifier '" + sParticipantID + "' - weird");
// Get the first one
final ICommonsList<PDStoredBusinessEntity> aStoredEntities = aGroupedDocs.getFirstValue();
// Details header
{
IHCNode aDetailsHeader = null;
final boolean bIsPeppolDefault = aParticipantID.hasScheme(PeppolIdentifierFactory.INSTANCE.getDefaultParticipantIdentifierScheme());
if (bIsPeppolDefault) {
final IParticipantIdentifierScheme aIIA = ParticipantIdentifierSchemeManager.getSchemeOfIdentifier(aParticipantID);
if (aIIA != null) {
final HCH1 aH1 = h1("Details for: " + aParticipantID.getValue());
if (StringHelper.hasText(aIIA.getSchemeAgency()))
aH1.addChild(small(" (" + aIIA.getSchemeAgency() + ")"));
aDetailsHeader = new BootstrapPageHeader().addChild(aH1);
}
}
if (aDetailsHeader == null) {
// Fallback
aDetailsHeader = BootstrapWebPageUIHandler.INSTANCE.createPageHeader("Details for " + sParticipantID);
}
aDetails.addChild(aDetailsHeader);
}
final BootstrapTabBox aTabBox = new BootstrapTabBox();
// Business information
{
final HCNodeList aOL = new HCNodeList();
int nIndex = 1;
for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) {
final BootstrapCard aCard = aOL.addAndReturnChild(new BootstrapCard());
aCard.addClass(CSS_CLASS_RESULT_PANEL);
if (aStoredEntities.size() > 1)
aCard.createAndAddHeader().addChild("Business information entity " + nIndex);
final BootstrapViewForm aViewForm = PDCommonUI.showBusinessInfoDetails(aStoredEntity, aDisplayLocale);
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Full Peppol participant ID").setCtrl(code(sParticipantID)));
if (GlobalDebug.isDebugMode() || bIsLoggedInUserAdministrator) {
aViewForm.addChild(new HCHR());
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Creation DT").setCtrl(PDTToString.getAsString(aStoredEntity.getMetaData().getCreationDT(), aDisplayLocale)));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Owner ID").setCtrl(code(aStoredEntity.getMetaData().getOwnerID())));
aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("[Debug] Requesting Host").setCtrl(code(aStoredEntity.getMetaData().getRequestingHost())));
}
aCard.createAndAddBody().addChild(aViewForm);
++nIndex;
}
// Add whole list or just the first item?
final IHCNode aTabLabel = span("Business information ").addChild(badgePrimary(aStoredEntities.size()));
aTabBox.addTab("businessinfo", aTabLabel, aOL, true);
}
// Document types
{
final HCNodeList aDocTypeCtrl = new HCNodeList();
final ICommonsList<String> aNames = new CommonsArrayList<>();
for (final PDStoredBusinessEntity aStoredEntity : aStoredEntities) aNames.addAllMapped(aStoredEntity.names(), PDStoredMLName::getName);
aDocTypeCtrl.addChild(info("The following document types are supported by " + _getImplodedMapped(", ", " and ", aNames, x -> "'" + x + "'") + ":"));
HCOL aDocTypeOL = null;
final ICommonsList<IDocumentTypeIdentifier> aDocTypeIDs = aResultDocs.getFirst().documentTypeIDs().getSorted(IDocumentTypeIdentifier.comparator());
for (final IDocumentTypeIdentifier aDocTypeID : aDocTypeIDs) {
if (aDocTypeOL == null)
aDocTypeOL = aDocTypeCtrl.addAndReturnChild(new HCOL());
final HCLI aLI = aDocTypeOL.addItem();
aLI.addChild(NiceNameUI.getDocumentTypeID(aDocTypeID));
}
if (aDocTypeOL == null)
aDocTypeCtrl.addChild(warn("This participant does not support any document types!"));
aTabBox.addTab("doctypes", span("Supported document types ").addChild(badgePrimary(aDocTypeIDs.size())), aDocTypeCtrl, false);
}
aDetails.addChild(aTabBox);
}
return aDetails;
}
Aggregations