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 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 ExportAllManager method queryAllContainedBusinessCardsAsCSV.
public static void queryAllContainedBusinessCardsAsCSV(@Nonnull @WillNotClose final CSVWriter aCSVWriter) throws IOException {
_unify(aCSVWriter);
final Query aQuery = new MatchAllDocsQuery();
aCSVWriter.writeNext("Participant ID", "Names (per-row)", "Country code", "Geo info", "Identifier schemes", "Identifier values", "Websites", "Contact type", "Contact name", "Contact phone", "Contact email", "Additional info", "Registration date", "Document types");
final Consumer<? super PDStoredBusinessEntity> aConsumer = aEntity -> {
aCSVWriter.writeNext(aEntity.getParticipantID().getURIEncoded(), StringHelper.getImplodedMapped("\n", aEntity.names(), PDStoredMLName::getNameAndLanguageCode), aEntity.getCountryCode(), aEntity.getGeoInfo(), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getScheme), StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getValue), StringHelper.getImploded("\n", aEntity.websiteURIs()), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getType), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getName), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getPhone), StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getEmail), aEntity.getAdditionalInformation(), aEntity.getRegistrationDate() == null ? "" : aEntity.getRegistrationDate().toString(), StringHelper.getImplodedMapped("\n", aEntity.documentTypeIDs(), IDocumentTypeIdentifier::getURIEncoded));
};
PDMetaManager.getStorageMgr().searchAllDocuments(aQuery, -1, aConsumer);
aCSVWriter.flush();
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class ExportAllManager method queryAllContainedBusinessCardsAsExcel.
@Nonnull
public static WorkbookCreationHelper queryAllContainedBusinessCardsAsExcel(final boolean bIncludeDocTypes) throws IOException {
final Query aQuery = new MatchAllDocsQuery();
final ExcelStyle ES_DATE = new ExcelStyle().setDataFormat("yyyy-mm-dd");
final ExcelStyle ES_WRAP = new ExcelStyle().setWrapText(true);
@WillNotClose final WorkbookCreationHelper aWBCH = new WorkbookCreationHelper(EExcelVersion.XLSX);
aWBCH.createNewSheet();
aWBCH.addRow();
aWBCH.addCell("Participant ID");
aWBCH.addCell("Names (per-row)");
aWBCH.addCell("Country code");
aWBCH.addCell("Geo info");
aWBCH.addCell("Identifier schemes");
aWBCH.addCell("Identifier values");
aWBCH.addCell("Websites");
aWBCH.addCell("Contact type");
aWBCH.addCell("Contact name");
aWBCH.addCell("Contact phone");
aWBCH.addCell("Contact email");
aWBCH.addCell("Additional info");
aWBCH.addCell("Registration date");
if (bIncludeDocTypes)
aWBCH.addCell("Document types");
final Consumer<? super PDStoredBusinessEntity> aConsumer = aEntity -> {
aWBCH.addRow();
aWBCH.addCell(aEntity.getParticipantID().getURIEncoded());
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.names(), PDStoredMLName::getNameAndLanguageCode));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(aEntity.getCountryCode());
aWBCH.addCell(aEntity.getGeoInfo());
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getScheme));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.identifiers(), PDStoredIdentifier::getValue));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImploded("\n", aEntity.websiteURIs()));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getType));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getName));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getPhone));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.contacts(), PDStoredContact::getEmail));
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(aEntity.getAdditionalInformation());
aWBCH.addCellStyle(ES_WRAP);
aWBCH.addCell(aEntity.getRegistrationDate());
aWBCH.addCellStyle(ES_DATE);
if (bIncludeDocTypes) {
aWBCH.addCell(StringHelper.getImplodedMapped("\n", aEntity.documentTypeIDs(), IDocumentTypeIdentifier::getURIEncoded));
aWBCH.addCellStyle(ES_WRAP);
}
};
// Query all and group by participant ID
PDMetaManager.getStorageMgr().searchAllDocuments(aQuery, -1, aConsumer);
aWBCH.autoSizeAllColumns();
aWBCH.autoFilterAllColumns();
return aWBCH;
}
use of com.helger.peppolid.IDocumentTypeIdentifier in project phoss-directory by phax.
the class PDStorageManager method createOrUpdateEntry.
@Nonnull
public ESuccess createOrUpdateEntry(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final PDExtendedBusinessCard aExtBI, @Nonnull final PDStoredMetaData aMetaData) throws IOException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aExtBI, "ExtBI");
ValueEnforcer.notNull(aMetaData, "MetaData");
LOGGER.info("Trying to create or update entry with participant ID '" + aParticipantID.getURIEncoded() + "' and " + aExtBI.getBusinessCard().businessEntities().size() + " entities");
return m_aLucene.writeLockedAtomic(() -> {
final ICommonsList<Document> aDocs = new CommonsArrayList<>();
final PDBusinessCard aBI = aExtBI.getBusinessCard();
for (final PDBusinessEntity aBusinessEntity : aBI.businessEntities()) {
// Convert entity to Lucene document
final Document aDoc = new Document();
final StringBuilder aSBAllFields = new StringBuilder();
aDoc.add(PDField.PARTICIPANT_ID.getAsField(aParticipantID));
aSBAllFields.append(PDField.PARTICIPANT_ID.getAsStorageValue(aParticipantID)).append(' ');
if (aBusinessEntity.names().size() == 1 && aBusinessEntity.names().getFirst().hasNoLanguageCode()) {
// Single name without a language - legacy case
final String sName = aBusinessEntity.names().getFirst().getName();
aDoc.add(PDField.NAME.getAsField(sName));
aSBAllFields.append(sName).append(' ');
} else {
// More than one name or language
for (final PDName aName : aBusinessEntity.names()) {
final String sName = aName.getName();
aDoc.add(PDField.ML_NAME.getAsField(sName));
aSBAllFields.append(sName).append(' ');
final String sLanguage = StringHelper.getNotNull(aName.getLanguageCode());
aDoc.add(PDField.ML_LANGUAGE.getAsField(sLanguage));
aSBAllFields.append(sLanguage).append(' ');
}
}
if (aBusinessEntity.hasCountryCode()) {
// Index all country codes in upper case (since 2017-09-20)
final String sCountryCode = aBusinessEntity.getCountryCode().toUpperCase(Locale.US);
aDoc.add(PDField.COUNTRY_CODE.getAsField(sCountryCode));
aSBAllFields.append(sCountryCode).append(' ');
}
// Add all document types to all documents
for (final IDocumentTypeIdentifier aDocTypeID : aExtBI.getAllDocumentTypeIDs()) {
aDoc.add(PDField.DOCTYPE_ID.getAsField(aDocTypeID));
aSBAllFields.append(PDField.DOCTYPE_ID.getAsStorageValue(aDocTypeID)).append(' ');
}
if (aBusinessEntity.hasGeoInfo()) {
aDoc.add(PDField.GEO_INFO.getAsField(aBusinessEntity.getGeoInfo()));
aSBAllFields.append(aBusinessEntity.getGeoInfo()).append(' ');
}
for (final PDIdentifier aIdentifier : aBusinessEntity.identifiers()) {
aDoc.add(PDField.IDENTIFIER_SCHEME.getAsField(aIdentifier.getScheme()));
aSBAllFields.append(aIdentifier.getScheme()).append(' ');
aDoc.add(PDField.IDENTIFIER_VALUE.getAsField(aIdentifier.getValue()));
aSBAllFields.append(aIdentifier.getValue()).append(' ');
}
for (final String sWebSite : aBusinessEntity.websiteURIs()) {
aDoc.add(PDField.WEBSITE_URI.getAsField(sWebSite));
aSBAllFields.append(sWebSite).append(' ');
}
for (final PDContact aContact : aBusinessEntity.contacts()) {
final String sType = StringHelper.getNotNull(aContact.getType());
aDoc.add(PDField.CONTACT_TYPE.getAsField(sType));
aSBAllFields.append(sType).append(' ');
final String sName = StringHelper.getNotNull(aContact.getName());
aDoc.add(PDField.CONTACT_NAME.getAsField(sName));
aSBAllFields.append(sName).append(' ');
final String sPhone = StringHelper.getNotNull(aContact.getPhoneNumber());
aDoc.add(PDField.CONTACT_PHONE.getAsField(sPhone));
aSBAllFields.append(sPhone).append(' ');
final String sEmail = StringHelper.getNotNull(aContact.getEmail());
aDoc.add(PDField.CONTACT_EMAIL.getAsField(sEmail));
aSBAllFields.append(sEmail).append(' ');
}
if (aBusinessEntity.hasAdditionalInfo()) {
aDoc.add(PDField.ADDITIONAL_INFO.getAsField(aBusinessEntity.getAdditionalInfo()));
aSBAllFields.append(aBusinessEntity.getAdditionalInfo()).append(' ');
}
if (aBusinessEntity.hasRegistrationDate()) {
final String sDate = PDTWebDateHelper.getAsStringXSD(aBusinessEntity.getRegistrationDate());
aDoc.add(PDField.REGISTRATION_DATE.getAsField(sDate));
aSBAllFields.append(sDate).append(' ');
}
// Add the "all" field - no need to store
aDoc.add(new TextField(CPDStorage.FIELD_ALL_FIELDS, aSBAllFields.toString(), Store.NO));
// Add meta data (not part of the "all field" field!)
// Lucene6: cannot yet use a LongPoint because it has no way to create a
// stored one
aDoc.add(PDField.METADATA_CREATIONDT.getAsField(aMetaData.getCreationDT()));
aDoc.add(PDField.METADATA_OWNERID.getAsField(aMetaData.getOwnerID()));
aDoc.add(PDField.METADATA_REQUESTING_HOST.getAsField(aMetaData.getRequestingHost()));
aDocs.add(aDoc);
}
if (aDocs.isNotEmpty()) {
// Add "group end" marker
CollectionHelper.getLastElement(aDocs).add(new Field(FIELD_GROUP_END, VALUE_GROUP_END, TYPE_GROUP_END));
}
// Delete all existing documents of the participant ID
// and add the new ones to the index
m_aLucene.updateDocuments(PDField.PARTICIPANT_ID.getExactMatchTerm(aParticipantID), aDocs);
LOGGER.info("Added " + aDocs.size() + " Lucene documents");
AuditHelper.onAuditExecuteSuccess("pd-indexer-create", aParticipantID.getURIEncoded(), Integer.valueOf(aDocs.size()), aMetaData);
});
}
Aggregations