Search in sources :

Example 1 with PDIndexerManager

use of com.helger.pd.indexer.mgr.PDIndexerManager in project phoss-directory by phax.

the class PageSecureParticipantActions method _deleteDuplicateIDs.

private void _deleteDuplicateIDs(@Nonnull final WebPageExecutionContext aWPEC) {
    LOGGER.info("Deleting all duplicate participant identifiers");
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> aDupMap = _getDuplicateSourceMap();
    final ICommonsSortedSet<String> aPIsToDelete = new CommonsTreeSet<>();
    final ICommonsSortedSet<String> aPIsToAdd = new CommonsTreeSet<>();
    for (final Map.Entry<IParticipantIdentifier, ICommonsSortedSet<String>> aEntry : aDupMap.entrySet()) {
        final ICommonsSortedSet<String> aSet = aEntry.getValue();
        final IParticipantIdentifier aPI = aEntry.getKey();
        final String sDesiredVersion = aPI.getURIEncoded();
        if (aSet.contains(sDesiredVersion)) {
            // Simple kill the other ones
            aPIsToDelete.addAll(aSet, x -> !x.equals(sDesiredVersion));
        } else {
            // Remove all and index the correct version
            aPIsToDelete.addAll(aSet);
            aPIsToAdd.add(sDesiredVersion);
        }
    }
    if (aPIsToDelete.isNotEmpty()) {
        final HCNodeList aNL = new HCNodeList();
        // Important to use this identifier factory so that the correct key is
        // created
        final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
        final PDIndexerManager aIndexerMgr = PDMetaManager.getIndexerMgr();
        String sMsg = "Deleting " + aPIsToDelete.size() + " participant ID(s):";
        LOGGER.info(sMsg);
        aNL.addChild(h2(sMsg));
        HCOL aOL = aNL.addAndReturnChild(new HCOL());
        for (final String s : aPIsToDelete.getSorted(IComparator.getComparatorCollating(aDisplayLocale))) {
            aOL.addItem(s);
            aIndexerMgr.queueWorkItem(aIF.parseParticipantIdentifier(s), EIndexerWorkItemType.DELETE, "duplicate-elimination", PDIndexerManager.HOST_LOCALHOST);
        }
        if (aPIsToAdd.isNotEmpty()) {
            sMsg = "Adding " + aPIsToAdd.size() + " participant ID(s) instead:";
            LOGGER.info(sMsg);
            aNL.addChild(h2(sMsg));
            aOL = aNL.addAndReturnChild(new HCOL());
            for (final String s : aPIsToAdd.getSorted(IComparator.getComparatorCollating(aDisplayLocale))) {
                aOL.addItem(s);
                aIndexerMgr.queueWorkItem(aIF.parseParticipantIdentifier(s), EIndexerWorkItemType.CREATE_UPDATE, "duplicate-elimination", PDIndexerManager.HOST_LOCALHOST);
            }
        }
        aWPEC.postRedirectGetInternal(aNL);
    } else {
        final String sMsg = "Found no duplicate entries to remove";
        LOGGER.info(sMsg);
        aWPEC.postRedirectGetInternal(success(sMsg));
    }
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) PDTToString(com.helger.commons.datetime.PDTToString) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) HCOL(com.helger.html.hc.html.grouping.HCOL) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) PDIndexerManager(com.helger.pd.indexer.mgr.PDIndexerManager) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 2 with PDIndexerManager

use of com.helger.pd.indexer.mgr.PDIndexerManager in project phoss-directory by phax.

the class SyncAllBusinessCardsJob method syncAllBusinessCards.

@Nonnull
public static EChange syncAllBusinessCards(final boolean bForceSync) {
    final LocalDateTime aNow = PDTFactory.getCurrentLocalDateTime();
    if (!bForceSync) {
        // Only sync every 2 weeks
        if (aNow.isBefore(getLastSync().plusWeeks(2))) {
            return EChange.UNCHANGED;
        }
    }
    LOGGER.info("Start synchronizing business cards" + (bForceSync ? " (forced)" : ""));
    final PDIndexerManager aIndexerMgr = PDMetaManager.getIndexerMgr();
    // Queue a work item to re-scan all
    final Set<IParticipantIdentifier> aAll = PDMetaManager.getStorageMgr().getAllContainedParticipantIDs(EQueryMode.NON_DELETED_ONLY).keySet();
    for (final IParticipantIdentifier aParticipantID : aAll) {
        aIndexerMgr.queueWorkItem(aParticipantID, EIndexerWorkItemType.SYNC, "sync-job", PDIndexerManager.HOST_LOCALHOST);
    }
    LOGGER.info("Finished synchronizing of " + aAll.size() + " business cards");
    AuditHelper.onAuditExecuteSuccess("sync-bc-started", Integer.valueOf(aAll.size()), aNow, Boolean.valueOf(bForceSync));
    _setLastSync(aNow);
    return EChange.CHANGED;
}
Also used : LocalDateTime(java.time.LocalDateTime) PDIndexerManager(com.helger.pd.indexer.mgr.PDIndexerManager) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 3 with PDIndexerManager

use of com.helger.pd.indexer.mgr.PDIndexerManager in project phoss-directory by phax.

the class ReIndexJob method onExecute.

@Override
protected void onExecute(@Nonnull final JobDataMap aJobDataMap, @Nonnull final IJobExecutionContext aContext) throws JobExecutionException {
    final PDIndexerManager aIndexerMgr = PDMetaManager.getIndexerMgr();
    // First expire all old entries
    aIndexerMgr.expireOldEntries();
    // Re-index all items now
    aIndexerMgr.reIndexParticipantData();
}
Also used : PDIndexerManager(com.helger.pd.indexer.mgr.PDIndexerManager)

Aggregations

PDIndexerManager (com.helger.pd.indexer.mgr.PDIndexerManager)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)1 CommonsTreeSet (com.helger.commons.collection.impl.CommonsTreeSet)1 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)1 ICommonsSortedSet (com.helger.commons.collection.impl.ICommonsSortedSet)1 PDTToString (com.helger.commons.datetime.PDTToString)1 HCOL (com.helger.html.hc.html.grouping.HCOL)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)1 LocalDateTime (java.time.LocalDateTime)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1