use of javax.annotation.CheckForSigned in project phoss-directory by phax.
the class PDStorageManager method getCount.
@CheckForSigned
public int getCount(@Nonnull final Query aQuery) {
ValueEnforcer.notNull(aQuery, "Query");
try {
final TotalHitCountCollector aCollector = new TotalHitCountCollector();
searchAtomic(aQuery, aCollector);
return aCollector.getTotalHits();
} catch (final IOException ex) {
LOGGER.error("Error counting documents with query " + aQuery, ex);
return -1;
}
}
use of javax.annotation.CheckForSigned in project phoss-directory by phax.
the class PDStorageManager method searchAll.
public void searchAll(@Nonnull final Query aQuery, @CheckForSigned final int nMaxResultCount, @Nonnull final Consumer<Document> aConsumer) throws IOException {
ValueEnforcer.notNull(aQuery, "Query");
ValueEnforcer.notNull(aConsumer, "Consumer");
if (nMaxResultCount <= 0) {
// Search all
final ObjIntConsumer<Document> aConverter = (aDoc, nDocID) -> aConsumer.accept(aDoc);
final Collector aCollector = new AllDocumentsCollector(m_aLucene, aConverter);
searchAtomic(aQuery, aCollector);
} else {
// Search top docs only
// Lucene 8
// final TopScoreDocCollector aCollector = TopScoreDocCollector.create
// (nMaxResultCount, Integer.MAX_VALUE);
final TopScoreDocCollector aCollector = TopScoreDocCollector.create(nMaxResultCount);
searchAtomic(aQuery, aCollector);
for (final ScoreDoc aScoreDoc : aCollector.topDocs().scoreDocs) {
final Document aDoc = m_aLucene.getDocument(aScoreDoc.doc);
if (aDoc == null)
throw new IllegalStateException("Failed to resolve Lucene Document with ID " + aScoreDoc.doc);
// Pass to Consumer
aConsumer.accept(aDoc);
}
}
}
use of javax.annotation.CheckForSigned in project phoss-directory by phax.
the class PDStorageManager method deleteEntry.
@CheckForSigned
public int deleteEntry(@Nonnull final IParticipantIdentifier aParticipantID, @Nullable final PDStoredMetaData aMetaData, final boolean bVerifyOwner) throws IOException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
LOGGER.info("Trying to delete entry with participant ID '" + aParticipantID.getURIEncoded() + "'" + (bVerifyOwner && aMetaData != null ? " with owner ID '" + aMetaData.getOwnerID() + "'" : ""));
Query aParticipantQuery = new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aParticipantID));
if (getCount(aParticipantQuery) == 0) {
// Hack e.g. for 9925:everbinding
final String sOrigValue = aParticipantID.getValue();
final String sUpperCaseValue = sOrigValue.toUpperCase(Locale.ROOT);
if (!sUpperCaseValue.equals(sOrigValue)) {
// Something changed - try again
// Force case sensitivity
final IParticipantIdentifier aNewPID = new SimpleParticipantIdentifier(aParticipantID.getScheme(), sUpperCaseValue);
final Query aOtherQuery = new TermQuery(PDField.PARTICIPANT_ID.getExactMatchTerm(aNewPID));
if (getCount(aOtherQuery) > 0) {
LOGGER.info("Found something with '" + sUpperCaseValue + "' instead of '" + sOrigValue + "'");
aParticipantQuery = aOtherQuery;
}
}
}
final Query aDeleteQuery;
if (bVerifyOwner && aMetaData != null) {
aDeleteQuery = new BooleanQuery.Builder().add(aParticipantQuery, Occur.MUST).add(new TermQuery(PDField.METADATA_OWNERID.getExactMatchTerm(aMetaData.getOwnerID())), Occur.MUST).build();
} else
aDeleteQuery = aParticipantQuery;
final int nCount = getCount(aDeleteQuery);
if (m_aLucene.writeLockedAtomic(() -> {
// Delete
m_aLucene.deleteDocuments(aDeleteQuery);
}).isFailure()) {
LOGGER.error("Failed to delete docs from the index using the query '" + aDeleteQuery + "'");
return -1;
}
LOGGER.info("Deleted " + nCount + " docs from the index using the query '" + aDeleteQuery + "'");
AuditHelper.onAuditExecuteSuccess("pd-indexer-delete", aParticipantID.getURIEncoded(), Integer.valueOf(nCount), aMetaData, Boolean.toString(bVerifyOwner));
return nCount;
}
use of javax.annotation.CheckForSigned in project phoss-directory by phax.
the class PDStorageManager method deleteAllEntriesMarkedAsDeleted.
@CheckForSigned
public int deleteAllEntriesMarkedAsDeleted() throws IOException {
LOGGER.info("Trying to delete all entries marked as deleted");
final Query aDeleteQuery = IntPoint.newExactQuery(CPDStorage.FIELD_DELETED, 1);
final int nCount = getCount(aDeleteQuery);
if (m_aLucene.writeLockedAtomic(() -> {
// Delete
m_aLucene.deleteDocuments(aDeleteQuery);
}).isFailure()) {
LOGGER.error("Failed to delete docs from the index using the query '" + aDeleteQuery + "'");
return -1;
}
LOGGER.info("Deleted " + nCount + " docs from the index using the query '" + aDeleteQuery + "'");
AuditHelper.onAuditExecuteSuccess("pd-indexer-delete-deleted", Integer.valueOf(nCount));
return nCount;
}
Aggregations