Search in sources :

Example 41 with IDocumentTypeIdentifier

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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) MicroElement(com.helger.xml.microdom.MicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Nonnull(javax.annotation.Nonnull)

Example 42 with IDocumentTypeIdentifier

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);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 43 with IDocumentTypeIdentifier

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();
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact)

Example 44 with IDocumentTypeIdentifier

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;
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PDTFactory(com.helger.commons.datetime.PDTFactory) IMicroElement(com.helger.xml.microdom.IMicroElement) PDStoredBusinessEntity(com.helger.pd.indexer.storage.PDStoredBusinessEntity) PDField(com.helger.pd.indexer.storage.field.PDField) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) CSVWriter(com.helger.commons.csv.CSVWriter) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Writer(java.io.Writer) WebFileIO(com.helger.photon.app.io.WebFileIO) ESuccess(com.helger.commons.state.ESuccess) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) IJsonObject(com.helger.json.IJsonObject) MicroDocument(com.helger.xml.microdom.MicroDocument) CHttpHeader(com.helger.commons.http.CHttpHeader) JsonArray(com.helger.json.JsonArray) FileHelper(com.helger.commons.io.file.FileHelper) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) WillNotClose(javax.annotation.WillNotClose) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) StringHelper(com.helger.commons.string.StringHelper) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) File(java.io.File) JsonWriter(com.helger.json.serialize.JsonWriter) SimpleReadWriteLock(com.helger.commons.concurrent.SimpleReadWriteLock) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) Consumer(java.util.function.Consumer) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) Comparator(java.util.Comparator) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ExcelStyle(com.helger.poi.excel.style.ExcelStyle) PDStoredIdentifier(com.helger.pd.indexer.storage.PDStoredIdentifier) PDStoredMLName(com.helger.pd.indexer.storage.PDStoredMLName) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WillNotClose(javax.annotation.WillNotClose) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) PDStoredContact(com.helger.pd.indexer.storage.PDStoredContact) Nonnull(javax.annotation.Nonnull)

Example 45 with IDocumentTypeIdentifier

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);
    });
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) Document(org.apache.lucene.document.Document) PDContact(com.helger.pd.businesscard.generic.PDContact) PDField(com.helger.pd.indexer.storage.field.PDField) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) PDName(com.helger.pd.businesscard.generic.PDName) TextField(org.apache.lucene.document.TextField) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nonnull(javax.annotation.Nonnull)

Aggregations

IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)89 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)62 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)36 Nonnull (javax.annotation.Nonnull)36 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)32 Test (org.junit.Test)30 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)27 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)20 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)19 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)18 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)18 ICommonsList (com.helger.commons.collection.impl.ICommonsList)16 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)16 Nullable (javax.annotation.Nullable)13 ESuccess (com.helger.commons.state.ESuccess)11 StringHelper (com.helger.commons.string.StringHelper)11 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)11 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)11 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)11 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)10