use of org.xwiki.bridge.event.DocumentCreatedEvent in project xwiki-platform by xwiki.
the class LegacyEventDispatcherTest method testLegacyDocumentSaveEventGetsDispatched.
@Test
public void testLegacyDocumentSaveEventGetsDispatched() throws Exception {
this.registerListenerWithLegacyEvent(new DocumentSaveEvent());
this.om.notify(new DocumentCreatedEvent(new DocumentReference("wiki", "space", "name")), null);
// The notification is synchronous, so the following assertion will only be tested
// once all matching event listeners have been notified.
Assert.assertNotNull("Should have been notified by legacy event dispatcher", this.receivedEvent);
Assert.assertEquals("Wrong event filter", "wiki:space.name", ((FilterableEvent) this.receivedEvent).getEventFilter().getFilter());
}
use of org.xwiki.bridge.event.DocumentCreatedEvent in project xwiki-platform by xwiki.
the class SolrIndexEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
try {
if (event instanceof DocumentUpdatedEvent) {
XWikiDocument document = (XWikiDocument) source;
if (Locale.ROOT.equals(document.getLocale())) {
// Index all the translations of a document when its default translation has been updated because
// the default translation holds meta data shared by all translations (attachments, objects).
indexTranslations(document, (XWikiContext) data);
} else {
// Index only the updated translation.
this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false);
}
} else if (event instanceof DocumentCreatedEvent) {
XWikiDocument document = (XWikiDocument) source;
if (!Locale.ROOT.equals(document.getLocale())) {
// If a new translation is added to a document reindex the whole document (could be optimized a bit
// by reindexing only the parent locales but that would always include objects and attachments
// anyway)
indexTranslations(document, (XWikiContext) data);
} else {
this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false);
}
} else if (event instanceof DocumentDeletedEvent) {
XWikiDocument document = ((XWikiDocument) source).getOriginalDocument();
// We must pass the document reference with the REAL locale because when the indexer is going to delete
// the document from the Solr index (later, on a different thread) the real locale won't be accessible
// anymore since the XWiki document has been already deleted from the database. The real locale (taken
// from the XWiki document) is used to compute the id of the Solr document when the document reference
// locale is ROOT (i.e. for default document translations).
// Otherwise the document won't be deleted from the Solr index (because the computed id won't match any
// document from the Solr index) and we're going to have deleted documents that are still in the Solr
// index. These documents will be filtered from the search results but not from the facet counts.
// See XWIKI-10003: Cache problem with Solr facet filter results count
this.solrIndexer.get().delete(new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false);
} else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) {
XWikiDocument document = (XWikiDocument) source;
String fileName = ((AbstractAttachmentEvent) event).getName();
XWikiAttachment attachment = document.getAttachment(fileName);
this.solrIndexer.get().index(attachment.getReference(), false);
} else if (event instanceof AttachmentDeletedEvent) {
XWikiDocument document = ((XWikiDocument) source).getOriginalDocument();
String fileName = ((AbstractAttachmentEvent) event).getName();
XWikiAttachment attachment = document.getAttachment(fileName);
this.solrIndexer.get().delete(attachment.getReference(), false);
} else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) {
EntityEvent entityEvent = (EntityEvent) event;
this.solrIndexer.get().index(entityEvent.getReference(), false);
} else if (event instanceof XObjectDeletedEvent) {
EntityEvent entityEvent = (EntityEvent) event;
this.solrIndexer.get().delete(entityEvent.getReference(), false);
} else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) {
EntityEvent entityEvent = (EntityEvent) event;
this.solrIndexer.get().index(entityEvent.getReference(), false);
} else if (event instanceof XObjectPropertyDeletedEvent) {
EntityEvent entityEvent = (EntityEvent) event;
this.solrIndexer.get().delete(entityEvent.getReference(), false);
} else if (event instanceof WikiDeletedEvent) {
String wikiName = (String) source;
WikiReference wikiReference = new WikiReference(wikiName);
this.solrIndexer.get().delete(wikiReference, false);
}
} catch (Exception e) {
this.logger.error("Failed to handle event [{}] with source [{}]", event, source, e);
}
}
use of org.xwiki.bridge.event.DocumentCreatedEvent in project xwiki-platform by xwiki.
the class XClassPropertyEventGeneratorListenerTest method testAddDocument.
@Test
public void testAddDocument() throws ComponentLookupException {
this.xclass.addTextField("property", "Property", 30);
final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference());
this.mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(this.document.getDocumentReference()), this.document, this.oldcore.getXWikiContext());
// Make sure the listener generated a xobject added event
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
}
use of org.xwiki.bridge.event.DocumentCreatedEvent in project xwiki-platform by xwiki.
the class XObjectEventGeneratorListenerTest method testAddDocument.
@Test
public void testAddDocument() throws ComponentLookupException {
this.document.addXObject(this.xobject);
final Event event = new XObjectAddedEvent(this.xobject.getReference());
this.mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(this.document.getDocumentReference()), this.document, this.oldcore.getXWikiContext());
// Make sure the listener generated a xobject added event
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
}
use of org.xwiki.bridge.event.DocumentCreatedEvent 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