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));
}
}
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"));
}
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;
}
Aggregations