use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class LegacyEventDispatcherTest method testLegacyDocumentDeleteEventGetsDispatched.
@Test
public void testLegacyDocumentDeleteEventGetsDispatched() throws Exception {
this.registerListenerWithLegacyEvent(new DocumentDeleteEvent());
this.om.notify(new DocumentDeletedEvent(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.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class LegacyEventDispatcher method getEvents.
@Override
public List<Event> getEvents() {
return new ArrayList<Event>() {
{
add(new DocumentDeletedEvent());
add(new DocumentCreatedEvent());
add(new DocumentUpdatedEvent());
add(new ActionExecutedEvent());
}
};
}
use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class DocumentEventConverter method fromRemote.
@Override
public boolean fromRemote(RemoteEventData remoteEvent, LocalEventData localEvent) {
if (EVENTS.contains(remoteEvent.getEvent().getClass())) {
// fill the local event
XWikiContext xcontext = unserializeXWikiContext(remoteEvent.getData());
try {
if (xcontext != null) {
localEvent.setData(xcontext);
localEvent.setEvent((Event) remoteEvent.getEvent());
if (remoteEvent.getEvent() instanceof DocumentDeletedEvent) {
localEvent.setSource(unserializeDeletdDocument(remoteEvent.getSource(), xcontext));
} else {
localEvent.setSource(unserializeDocument(remoteEvent.getSource()));
}
}
} catch (XWikiException e) {
this.logger.error("Failed to convert remote event [{}]", remoteEvent, e);
}
return true;
}
return false;
}
use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class WikiDescriptorListenerTest method onDocumentDeletedEvent.
@Test
public void onDocumentDeletedEvent() throws Exception {
XWikiDocument document = mock(XWikiDocument.class);
XWikiDocument originalDocument = mock(XWikiDocument.class);
when(document.getOriginalDocument()).thenReturn(originalDocument);
Event event = new DocumentDeletedEvent();
List<BaseObject> objects = new ArrayList<>();
BaseObject object = mock(BaseObject.class);
objects.add(object);
when(originalDocument.getXObjects(WikiDescriptorListener.SERVER_CLASS)).thenReturn(objects);
DocumentReference documentReference = new DocumentReference("mainWiki", "XWiki", "XWikiServerSubwikiA");
when(originalDocument.getDocumentReference()).thenReturn(documentReference);
when(wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(documentReference)).thenReturn("subwikia");
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("subwikia", "alias");
when(cache.getFromId("subwikia")).thenReturn(descriptor);
// Test
mocker.getComponentUnderTest().onEvent(event, document, null);
// Verify
verify(cache).remove(descriptor.getId(), descriptor.getAliases());
verify(cache, never()).add(any(DefaultWikiDescriptor.class));
}
use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class LegacyNotificationDispatcher method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XWikiDocument document = (XWikiDocument) source;
XWikiDocument originalDocument = document.getOriginalDocument();
XWikiContext context = (XWikiContext) data;
XWikiNotificationManager manager = getNotificationManager((XWikiContext) data);
if (manager != null) {
if (event instanceof DocumentCreatedEvent) {
manager.verify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_NEW, context);
} else if (event instanceof DocumentUpdatedEvent) {
manager.verify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_CHANGE, context);
} else if (event instanceof DocumentCreatingEvent) {
manager.preverify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_NEW, context);
} else if (event instanceof DocumentUpdatingEvent) {
manager.preverify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_CHANGE, context);
} else if (event instanceof DocumentDeletedEvent) {
manager.verify(new XWikiDocument(document.getDocumentReference()), document, XWikiDocChangeNotificationInterface.EVENT_DELETE, context);
} else if (event instanceof DocumentDeletingEvent) {
manager.preverify(document, new XWikiDocument(document.getDocumentReference()), XWikiDocChangeNotificationInterface.EVENT_DELETE, context);
} else if (event instanceof ActionExecutedEvent) {
manager.verify(document, ((ActionExecutedEvent) event).getActionName(), context);
} else if (event instanceof ActionExecutingEvent) {
manager.preverify(document, ((ActionExecutingEvent) event).getActionName(), context);
}
} else {
this.logger.error("Can't find old [XWikiNotificationManager] system");
}
}
Aggregations