use of org.xwiki.bridge.event.AbstractDocumentEvent in project xwiki-platform by xwiki.
the class SolrIndexAvailableLocalesListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XWikiContext xcontext = (XWikiContext) data;
String wiki = xcontext.getWikiId();
Set<Locale> oldLocales = this.localesCache.get(wiki);
List<Locale> availableLocales = xcontext.getWiki().getAvailableLocales(xcontext);
// Update the cache
this.localesCache.put(wiki, new HashSet<Locale>(availableLocales));
try {
// initialization
if (oldLocales != null && event instanceof AbstractDocumentEvent) {
Collection<Locale> newLocales = CollectionUtils.subtract(availableLocales, oldLocales);
if (!newLocales.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Locale newLocale : newLocales) {
for (Locale locale : getParentLocales(newLocale)) {
if (builder.length() > 0) {
builder.append(" OR ");
}
builder.append(FieldUtils.DOCUMENT_LOCALE);
builder.append(':');
builder.append('"');
builder.append(locale.toString());
builder.append('"');
}
}
SolrQuery solrQuery = new SolrQuery(builder.toString());
solrQuery.setFields(FieldUtils.WIKI, FieldUtils.SPACES, FieldUtils.NAME, FieldUtils.DOCUMENT_LOCALE);
solrQuery.addFilterQuery(FieldUtils.TYPE + ':' + EntityType.DOCUMENT.name());
StreamingResponseCallback callback = new StreamingResponseCallback() {
@Override
public void streamSolrDocument(SolrDocument doc) {
solrIndexer.get().index(solrDocumentReferenceResolver.resolve(doc), true);
}
@Override
public void streamDocListInfo(long numFound, long start, Float maxScore) {
// Do nothing.
}
};
this.solrInstanceProvider.get().queryAndStreamResponse(solrQuery, callback);
}
}
} catch (Exception e) {
this.logger.error("Failed to handle event [{}] with source [{}]", event, source, e);
}
}
use of org.xwiki.bridge.event.AbstractDocumentEvent in project xwiki-platform by xwiki.
the class WikiMacroEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (event instanceof AbstractDocumentEvent) {
DocumentModelBridge document = (DocumentModelBridge) source;
DocumentReference documentReference = document.getDocumentReference();
if (event instanceof DocumentCreatedEvent || event instanceof DocumentUpdatedEvent) {
registerMacro(documentReference);
} else if (event instanceof DocumentDeletedEvent) {
unregisterMacro(documentReference);
}
}
}
Aggregations