Search in sources :

Example 1 with ICommonsSortedSet

use of com.helger.commons.collection.impl.ICommonsSortedSet 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 ICommonsSortedSet

use of com.helger.commons.collection.impl.ICommonsSortedSet in project phoss-directory by phax.

the class PageSecureParticipantActions method _showDuplicateIDs.

private void _showDuplicateIDs(@Nonnull final WebPageExecutionContext aWPEC) {
    // This method can take a couple of minutes
    LOGGER.info("Showing all duplicate participant identifiers");
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> aDupMap = _getDuplicateSourceMap();
    final HCNodeList aNL = new HCNodeList();
    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();
        final HCDiv aDiv = div("Found " + aSet.size() + " duplicate IDs for ").addChild(code(sDesiredVersion)).addChild(":");
        final HCOL aOL = aDiv.addAndReturnChild(new HCOL());
        for (final String sVersion : aSet.getSorted(IComparator.getComparatorCollating(aDisplayLocale))) {
            final boolean bIsDesired = sDesiredVersion.equals(sVersion);
            final IHCLI<?> aLI = aOL.addAndReturnItem(code(sVersion));
            if (bIsDesired)
                aLI.addChild(" ").addChild(badgeSuccess("desired version"));
        }
        aNL.addChild(aDiv);
    }
    if (aNL.hasChildren()) {
        final String sMsg = "Found duplicate entries for " + aDupMap.size() + " " + (aDupMap.size() == 1 ? "participant" : "participants");
        LOGGER.info(sMsg);
        aNL.addChildAt(0, h2(sMsg));
        aWPEC.postRedirectGetInternal(aNL);
    } else
        aWPEC.postRedirectGetInternal(success("Found no duplicate entries"));
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCNodeList(com.helger.html.hc.impl.HCNodeList) 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) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 3 with ICommonsSortedSet

use of com.helger.commons.collection.impl.ICommonsSortedSet in project phoss-directory by phax.

the class PageSecureParticipantActions method _getDuplicateSourceMap.

@Nonnull
private static ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> _getDuplicateSourceMap() {
    LOGGER.info("_getDuplicateSourceMap () start");
    final ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> aMap = new CommonsHashMap<>();
    final Query aQuery = EQueryMode.NON_DELETED_ONLY.getEffectiveQuery(new MatchAllDocsQuery());
    try {
        final Consumer<Document> aConsumer = aDoc -> {
            final IParticipantIdentifier aResolvedParticipantID = PDField.PARTICIPANT_ID.getDocValue(aDoc);
            // Get the unparsed value
            final String sParticipantID = PDField.PARTICIPANT_ID.getDocField(aDoc).stringValue();
            aMap.computeIfAbsent(aResolvedParticipantID, k -> new CommonsTreeSet<>()).add(sParticipantID);
        };
        PDMetaManager.getStorageMgr().searchAll(aQuery, -1, aConsumer);
    } catch (final IOException ex) {
        LOGGER.error("Error searching for documents with query " + aQuery, ex);
    }
    // Take only the duplicate ones
    final ICommonsMap<IParticipantIdentifier, ICommonsSortedSet<String>> ret = new CommonsHashMap<>();
    for (final Map.Entry<IParticipantIdentifier, ICommonsSortedSet<String>> aEntry : aMap.entrySet()) if (aEntry.getValue().size() > 1) {
        ret.put(aEntry);
        LOGGER.info("  Potential duplicate in: " + aEntry.getKey().getURIEncoded());
    }
    LOGGER.info("_getDuplicateSourceMap () done");
    return ret;
}
Also used : Query(org.apache.lucene.search.Query) EExcelVersion(com.helger.poi.excel.EExcelVersion) CommonsTreeSet(com.helger.commons.collection.impl.CommonsTreeSet) StreamHelper(com.helger.commons.io.stream.StreamHelper) HCOL(com.helger.html.hc.html.grouping.HCOL) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) ExportAllManager(com.helger.pd.publisher.exportall.ExportAllManager) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) EIndexerWorkItemType(com.helger.pd.indexer.index.EIndexerWorkItemType) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) LoggerFactory(org.slf4j.LoggerFactory) IMicroDocument(com.helger.xml.microdom.IMicroDocument) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) SyncAllBusinessCardsJob(com.helger.pd.publisher.updater.SyncAllBusinessCardsJob) AjaxFunctionDeclaration(com.helger.photon.ajax.decl.AjaxFunctionDeclaration) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) Document(org.apache.lucene.document.Document) CMimeType(com.helger.commons.mime.CMimeType) CPDPublisher(com.helger.pd.publisher.CPDPublisher) Nonempty(com.helger.commons.annotation.Nonempty) EBootstrapButtonType(com.helger.photon.bootstrap4.button.EBootstrapButtonType) Locale(java.util.Locale) IMicroElement(com.helger.xml.microdom.IMicroElement) Map(java.util.Map) CPageParam(com.helger.photon.uicore.css.CPageParam) IComparator(com.helger.commons.compare.IComparator) PDTToString(com.helger.commons.datetime.PDTToString) HCDiv(com.helger.html.hc.html.grouping.HCDiv) PDField(com.helger.pd.indexer.storage.field.PDField) AbstractAppWebPage(com.helger.pd.publisher.ui.AbstractAppWebPage) Set(java.util.Set) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) StandardCharsets(java.nio.charset.StandardCharsets) WorkbookCreationHelper(com.helger.poi.excel.WorkbookCreationHelper) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) ExportServlet(com.helger.pd.publisher.servlet.ExportServlet) CSVWriter(com.helger.commons.csv.CSVWriter) PDIndexerManager(com.helger.pd.indexer.mgr.PDIndexerManager) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) BootstrapCardBody(com.helger.photon.bootstrap4.card.BootstrapCardBody) LinkHelper(com.helger.photon.app.url.LinkHelper) LocalDateTime(java.time.LocalDateTime) MicroDocument(com.helger.xml.microdom.MicroDocument) ExportDeliveryHttpHandler(com.helger.pd.publisher.servlet.ExportDeliveryHttpHandler) ExportAllDataJob(com.helger.pd.publisher.exportall.ExportAllDataJob) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) IHCLI(com.helger.html.hc.html.grouping.IHCLI) HCNodeList(com.helger.html.hc.impl.HCNodeList) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) Logger(org.slf4j.Logger) CBootstrapCSS(com.helger.photon.bootstrap4.CBootstrapCSS) IOException(java.io.IOException) SimpleIdentifierFactory(com.helger.peppolid.factory.SimpleIdentifierFactory) Consumer(java.util.function.Consumer) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) PDTToString(com.helger.commons.datetime.PDTToString) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Document(org.apache.lucene.document.Document) MicroDocument(com.helger.xml.microdom.MicroDocument) ICommonsSortedSet(com.helger.commons.collection.impl.ICommonsSortedSet) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)3 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 ICommonsSortedSet (com.helger.commons.collection.impl.ICommonsSortedSet)3 PDTToString (com.helger.commons.datetime.PDTToString)3 HCOL (com.helger.html.hc.html.grouping.HCOL)3 HCNodeList (com.helger.html.hc.impl.HCNodeList)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 CommonsTreeSet (com.helger.commons.collection.impl.CommonsTreeSet)2 HCDiv (com.helger.html.hc.html.grouping.HCDiv)2 PDIndexerManager (com.helger.pd.indexer.mgr.PDIndexerManager)2 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Nonempty (com.helger.commons.annotation.Nonempty)1 IComparator (com.helger.commons.compare.IComparator)1 CSVWriter (com.helger.commons.csv.CSVWriter)1 NonBlockingByteArrayOutputStream (com.helger.commons.io.stream.NonBlockingByteArrayOutputStream)1 StreamHelper (com.helger.commons.io.stream.StreamHelper)1 CMimeType (com.helger.commons.mime.CMimeType)1 IHCLI (com.helger.html.hc.html.grouping.IHCLI)1