Search in sources :

Example 1 with PDExtendedBusinessCard

use of com.helger.pd.indexer.businesscard.PDExtendedBusinessCard in project phoss-directory by phax.

the class PDIndexExecutor method executeWorkItem.

/**
 * This method is responsible for executing the specified work item depending
 * on its type.
 *
 * @param aStorageMgr
 *        Storage manager.
 * @param aWorkItem
 *        The work item to be executed. May not be <code>null</code>.
 * @param nRetryCount
 *        The retry count. For the initial indexing it is 0, for the first
 *        retry 1 etc.
 * @param aSuccessHandler
 *        A callback that is invoked upon success only.
 * @param aFailureHandler
 *        A callback that is invoked upon failure only.
 * @return {@link ESuccess}
 */
@Nonnull
public static ESuccess executeWorkItem(@Nonnull final IPDStorageManager aStorageMgr, @Nonnull final IIndexerWorkItem aWorkItem, @Nonnegative final int nRetryCount, @Nonnull final Consumer<? super IIndexerWorkItem> aSuccessHandler, @Nonnull final Consumer<? super IIndexerWorkItem> aFailureHandler) {
    LOGGER.info("Execute work item " + aWorkItem.getLogText() + " - " + (nRetryCount > 0 ? "retry #" + nRetryCount : "initial try"));
    final IPDBusinessCardProvider aBCProvider = PDMetaManager.getBusinessCardProviderOrNull();
    if (aBCProvider == null) {
        // Maybe null upon shutdown - in that case ignore it and don't reindex
        return ESuccess.FAILURE;
    }
    try {
        final IParticipantIdentifier aParticipantID = aWorkItem.getParticipantID();
        ESuccess eSuccess;
        switch(aWorkItem.getType()) {
            case CREATE_UPDATE:
                {
                    // Get BI from participant (e.g. from SMP)
                    final PDExtendedBusinessCard aBI = aBCProvider.getBusinessCard(aParticipantID);
                    if (aBI == null) {
                        // No/invalid extension present - no need to try again
                        eSuccess = ESuccess.FAILURE;
                    } else {
                        // Got data - put in storage
                        eSuccess = aStorageMgr.createOrUpdateEntry(aParticipantID, aBI, aWorkItem.getAsMetaData());
                    }
                    break;
                }
            case DELETE:
                {
                    // Really delete it
                    eSuccess = ESuccess.valueOf(aStorageMgr.deleteEntry(aParticipantID, aWorkItem.getAsMetaData(), true) >= 0);
                    break;
                }
            case SYNC:
                {
                    // Get BI from participant (e.g. from SMP)
                    final PDExtendedBusinessCard aBI = aBCProvider.getBusinessCard(aParticipantID);
                    if (aBI == null) {
                        // No/invalid extension present - delete from index
                        eSuccess = ESuccess.valueOf(aStorageMgr.deleteEntry(aParticipantID, aWorkItem.getAsMetaData(), true) >= 0);
                    } else {
                        // Got data - put in storage
                        eSuccess = aStorageMgr.createOrUpdateEntry(aParticipantID, aBI, aWorkItem.getAsMetaData());
                    }
                    break;
                }
            default:
                throw new IllegalStateException("Unsupported work item type: " + aWorkItem);
        }
        if (eSuccess.isSuccess()) {
            // Item handled - remove from overall list
            aSuccessHandler.accept(aWorkItem);
            // And we're done
            return ESuccess.SUCCESS;
        }
    // else error storing data
    } catch (final Exception ex) {
        LOGGER.error("Error in executing work item " + aWorkItem.getLogText(), ex);
    // Fall through
    }
    // Invoke failure handler
    aFailureHandler.accept(aWorkItem);
    return ESuccess.FAILURE;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) IPDBusinessCardProvider(com.helger.pd.indexer.businesscard.IPDBusinessCardProvider) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 2 with PDExtendedBusinessCard

use of com.helger.pd.indexer.businesscard.PDExtendedBusinessCard in project phoss-directory by phax.

the class IndexerResourceTest method _createMockBC.

@Nonnull
private static PDExtendedBusinessCard _createMockBC(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9915:mock"));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setCountryCode("AT");
        aEntity.identifiers().add(new PDIdentifier("mock", "12345678"));
        aEntity.identifiers().add(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver 2"));
        aEntity.setCountryCode("NO");
        aEntity.identifiers().add(new PDIdentifier("mock", "abcdefgh"));
        aEntity.setAdditionalInfo("This is another mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier()));
}
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) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 3 with PDExtendedBusinessCard

use of com.helger.pd.indexer.businesscard.PDExtendedBusinessCard in project phoss-directory by phax.

the class LocalHost8080FuncTest method _createMockBC.

@Nonnull
private static PDExtendedBusinessCard _createMockBC(@Nonnull final IParticipantIdentifier aParticipantID) {
    final PDBusinessCard aBI = new PDBusinessCard();
    aBI.setParticipantIdentifier(new PDIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "9915:mock"));
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver"));
        aEntity.setCountryCode("AT");
        aEntity.identifiers().add(new PDIdentifier("mock", "12345678"));
        aEntity.identifiers().add(new PDIdentifier(aParticipantID.getScheme(), aParticipantID.getValue()));
        aEntity.setAdditionalInfo("This is a mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    {
        final PDBusinessEntity aEntity = new PDBusinessEntity();
        aEntity.names().add(new PDName("Philip's mock Peppol receiver 2"));
        aEntity.setCountryCode("NO");
        aEntity.identifiers().add(new PDIdentifier("mock", "abcdefgh"));
        aEntity.setAdditionalInfo("This is another mock entry for testing purposes only");
        aBI.businessEntities().add(aEntity);
    }
    return new PDExtendedBusinessCard(aBI, new CommonsArrayList<>(EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier()));
}
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) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) Nonnull(javax.annotation.Nonnull)

Example 4 with PDExtendedBusinessCard

use of com.helger.pd.indexer.businesscard.PDExtendedBusinessCard 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)

Aggregations

PDExtendedBusinessCard (com.helger.pd.indexer.businesscard.PDExtendedBusinessCard)4 Nonnull (javax.annotation.Nonnull)4 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)3 PDBusinessEntity (com.helger.pd.businesscard.generic.PDBusinessEntity)3 PDIdentifier (com.helger.pd.businesscard.generic.PDIdentifier)3 PDName (com.helger.pd.businesscard.generic.PDName)3 ESuccess (com.helger.commons.state.ESuccess)1 PDContact (com.helger.pd.businesscard.generic.PDContact)1 IPDBusinessCardProvider (com.helger.pd.indexer.businesscard.IPDBusinessCardProvider)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1