use of com.helger.commons.collection.impl.CommonsTreeSet 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.CommonsTreeSet in project phoss-directory by phax.
the class ExportAllManager method queryAllContainedParticipantsAsXML.
@Nonnull
public static IMicroDocument queryAllContainedParticipantsAsXML(@Nonnull final EQueryMode eQueryMode) throws IOException {
final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
// Query all and group by participant ID
final ICommonsSortedSet<IParticipantIdentifier> aSet = new CommonsTreeSet<>(Comparator.comparing(IParticipantIdentifier::getURIEncoded));
PDMetaManager.getStorageMgr().searchAll(aQuery, -1, PDField.PARTICIPANT_ID::getDocValue, aSet::add);
// XML root
final IMicroDocument aDoc = new MicroDocument();
final String sNamespaceURI = "http://www.peppol.eu/schema/pd/participant-generic/201910/";
final IMicroElement aRoot = aDoc.appendElement(sNamespaceURI, "root");
aRoot.setAttribute("version", "1");
aRoot.setAttribute("creationdt", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentZonedDateTimeUTC()));
aRoot.setAttribute("count", aSet.size());
// For all participants
for (final IParticipantIdentifier aParticipantID : aSet) {
aRoot.appendElement(sNamespaceURI, "participantID").setAttribute("scheme", aParticipantID.getScheme()).setAttribute("value", aParticipantID.getValue());
}
return aDoc;
}
use of com.helger.commons.collection.impl.CommonsTreeSet 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;
}
use of com.helger.commons.collection.impl.CommonsTreeSet in project phoss-directory by phax.
the class ExportAllManager method queryAllContainedParticipantsAsJSON.
@Nonnull
public static IJsonObject queryAllContainedParticipantsAsJSON(@Nonnull final EQueryMode eQueryMode) throws IOException {
final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
// Query all and group by participant ID
final ICommonsSortedSet<IParticipantIdentifier> aSet = new CommonsTreeSet<>(Comparator.comparing(IParticipantIdentifier::getURIEncoded));
PDMetaManager.getStorageMgr().searchAll(aQuery, -1, PDField.PARTICIPANT_ID::getDocValue, aSet::add);
// XML root
final IJsonObject aObj = new JsonObject();
aObj.add("version", 1);
aObj.add("creationdt", PDTWebDateHelper.getAsStringXSD(PDTFactory.getCurrentZonedDateTimeUTC()));
aObj.add("count", aSet.size());
// For all participants
final IJsonArray aArray = new JsonArray();
for (final IParticipantIdentifier aParticipantID : aSet) aArray.add(aParticipantID.getURIEncoded());
aObj.addJson("participants", aArray);
return aObj;
}
Aggregations