use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.
the class PD1APIHelper method createBusinessEntity.
@Nonnull
public static PDBusinessEntity createBusinessEntity(@Nonnull final PD1BusinessEntityType aBE) {
ValueEnforcer.notNull(aBE, "BusinessEntity");
final PDBusinessEntity ret = new PDBusinessEntity();
// No language available
ret.names().add(new PDName(aBE.getName()));
ret.setCountryCode(aBE.getCountryCode());
ret.setGeoInfo(aBE.getGeographicalInformation());
ret.identifiers().setAllMapped(aBE.getIdentifier(), PD1APIHelper::createIdentifier);
ret.websiteURIs().setAll(aBE.getWebsiteURI());
ret.contacts().setAllMapped(aBE.getContact(), PD1APIHelper::createContact);
ret.setAdditionalInfo(aBE.getAdditionalInformation());
ret.setRegistrationDate(aBE.getRegistrationDate());
return ret;
}
use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.
the class PD2APIHelper method createBusinessEntity.
@Nonnull
public static PDBusinessEntity createBusinessEntity(@Nonnull final PD2BusinessEntityType aBE) {
ValueEnforcer.notNull(aBE, "BusinessEntity");
final PDBusinessEntity ret = new PDBusinessEntity();
// No language available
ret.names().add(new PDName(aBE.getName()));
ret.setCountryCode(aBE.getCountryCode());
ret.setGeoInfo(aBE.getGeographicalInformation());
ret.identifiers().setAllMapped(aBE.getIdentifier(), PD2APIHelper::createIdentifier);
ret.setRegistrationDate(aBE.getRegistrationDate());
return ret;
}
use of com.helger.pd.businesscard.generic.PDBusinessEntity 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);
});
}
use of com.helger.pd.businesscard.generic.PDBusinessEntity in project phoss-directory by phax.
the class PDStoredBusinessEntity method getAsBusinessEntity.
/**
* @return Parts of this {@link PDStoredBusinessEntity} as a
* {@link PDBusinessEntity}.
*/
@Nonnull
@ReturnsMutableCopy
public PDBusinessEntity getAsBusinessEntity() {
// We have a single entity
final PDBusinessEntity ret = new PDBusinessEntity();
ret.names().setAllMapped(m_aNames, PDStoredMLName::getAsGenericObject);
ret.setCountryCode(m_sCountryCode);
ret.setGeoInfo(m_sGeoInfo);
ret.identifiers().setAllMapped(m_aIdentifiers, PDStoredIdentifier::getAsGenericObject);
ret.websiteURIs().setAll(m_aWebsiteURIs);
ret.contacts().setAllMapped(m_aContacts, PDStoredContact::getAsGenericObject);
ret.setAdditionalInfo(m_sAdditionalInformation);
ret.setRegistrationDate(m_aRegistrationDate);
return ret;
}
Aggregations