use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class XWikiMockitoTest method rollbackFiresEvents.
/**
* Verify that {@link XWiki#rollback(XWikiDocument, String, XWikiContext)} fires the right events.
*/
@Test
public void rollbackFiresEvents() throws Exception {
ObservationManager observationManager = mocker.getInstance(ObservationManager.class);
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
XWikiDocument document = mock(XWikiDocument.class);
when(document.getDocumentReference()).thenReturn(documentReference);
XWikiDocument originalDocument = mock(XWikiDocument.class);
// Mark the document as existing so that the roll-back method will fire an update event.
when(originalDocument.isNew()).thenReturn(false);
XWikiDocument result = mock(XWikiDocument.class);
when(result.clone()).thenReturn(result);
when(result.getDocumentReference()).thenReturn(documentReference);
when(result.getOriginalDocument()).thenReturn(originalDocument);
String revision = "3.5";
when(this.documentRevisionProvider.getRevision(document, revision)).thenReturn(result);
this.mocker.registerMockComponent(ContextualLocalizationManager.class);
xwiki.rollback(document, revision, context);
verify(observationManager).notify(new DocumentRollingBackEvent(documentReference, revision), result, context);
verify(observationManager).notify(new DocumentUpdatingEvent(documentReference), result, context);
verify(observationManager).notify(new DocumentUpdatedEvent(documentReference), result, context);
verify(observationManager).notify(new DocumentRolledBackEvent(documentReference, revision), result, context);
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent 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.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class SolrIndexEventListenerTest method onDocumentDefaultTranslationUpdated.
@Test
public void onDocumentDefaultTranslationUpdated() throws Exception {
XWikiContext xcontext = mock(XWikiContext.class);
XWikiDocument document = mock(XWikiDocument.class);
when(document.getLocale()).thenReturn(Locale.ROOT);
when(document.getTranslationLocales(xcontext)).thenReturn(Arrays.asList(Locale.FRENCH, Locale.GERMAN));
DocumentReference documentReference = new DocumentReference("wiki", "Path", "Page");
when(document.getDocumentReference()).thenReturn(documentReference);
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), document, xcontext);
verify(this.indexer, times(3)).index(any(EntityReference.class), any(Boolean.class));
verify(this.indexer).index(documentReference, false);
verify(this.indexer).index(new DocumentReference(documentReference, Locale.FRENCH), false);
verify(this.indexer).index(new DocumentReference(documentReference, Locale.GERMAN), false);
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class XClassPropertyEventGeneratorListenerTest method testModifiedDocumentXClassPropertyAdded.
@Test
public void testModifiedDocumentXClassPropertyAdded() throws ComponentLookupException {
this.xclass.addTextField("property", "Property", 30);
final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference());
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(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.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class XClassPropertyEventGeneratorListenerTest method testModifiedDocumentXClassPropertyModified.
@Test
public void testModifiedDocumentXClassPropertyModified() throws ComponentLookupException {
this.xclassOrigin.addTextField("property", "Property", 30);
this.xclass.addTextField("property", "New Property", 30);
final Event event = new XClassPropertyUpdatedEvent(this.xclassOrigin.getField("property").getReference());
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(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()));
}
Aggregations