Search in sources :

Example 1 with PDContact

use of com.helger.pd.businesscard.generic.PDContact in project phoss-directory by phax.

the class PDStorageManagerTest method _createMockBI.

@Nonnull
private static PDExtendedBusinessCard _createMockBI(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.setCountryCode("AT");
        aEntity.setRegistrationDate(PDTFactory.createLocalDate(2015, Month.JULY, 6));
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setGeoInfo("Vienna");
        for (int i = 0; i < 10; ++i) aEntity.identifiers().add(new PDIdentifier("scheme" + i, "value" + i));
        aEntity.websiteURIs().add("http://www.peppol.eu");
        aEntity.contacts().add(new PDContact("support", "BC name", "12345", "test@example.org"));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.setCountryCode("NO");
        aEntity.names().add(new PDName("Entity2a", "no"));
        aEntity.names().add(new PDName("Entity2b", "de"));
        aEntity.names().add(new PDName("Entity2c", "en"));
        aEntity.setAdditionalInfo("Mock");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30));
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDName(com.helger.pd.businesscard.generic.PDName) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) PDContact(com.helger.pd.businesscard.generic.PDContact) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 2 with PDContact

use of com.helger.pd.businesscard.generic.PDContact in project phoss-smp by phax.

the class SMPBusinessCardEntity method createFromGenericObject.

@Nonnull
public static SMPBusinessCardEntity createFromGenericObject(final PDBusinessEntity aEntity) {
    final SMPBusinessCardEntity ret = new SMPBusinessCardEntity();
    for (final PDName aItem : aEntity.names()) ret.names().add(new SMPBusinessCardName(aItem.getName(), aItem.getLanguageCode()));
    ret.setCountryCode(aEntity.getCountryCode());
    ret.setGeographicalInformation(aEntity.getGeoInfo());
    for (final PDIdentifier aItem : aEntity.identifiers()) ret.identifiers().add(SMPBusinessCardIdentifier.createFromGenericObject(aItem));
    for (final String sItem : aEntity.websiteURIs()) ret.websiteURIs().add(sItem);
    for (final PDContact aItem : aEntity.contacts()) ret.contacts().add(SMPBusinessCardContact.createFromGenericObject(aItem));
    ret.setAdditionalInformation(aEntity.getAdditionalInfo());
    ret.setRegistrationDate(aEntity.getRegistrationDate());
    return ret;
}
Also used : PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) PDName(com.helger.pd.businesscard.generic.PDName) PDContact(com.helger.pd.businesscard.generic.PDContact) Nonnull(javax.annotation.Nonnull)

Example 3 with PDContact

use of com.helger.pd.businesscard.generic.PDContact 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

PDContact (com.helger.pd.businesscard.generic.PDContact)3 PDIdentifier (com.helger.pd.businesscard.generic.PDIdentifier)3 PDName (com.helger.pd.businesscard.generic.PDName)3 Nonnull (javax.annotation.Nonnull)3 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)2 PDBusinessEntity (com.helger.pd.businesscard.generic.PDBusinessEntity)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 PDExtendedBusinessCard (com.helger.pd.indexer.businesscard.PDExtendedBusinessCard)1 PDField (com.helger.pd.indexer.storage.field.PDField)1 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)1 Document (org.apache.lucene.document.Document)1 Field (org.apache.lucene.document.Field)1 TextField (org.apache.lucene.document.TextField)1