Search in sources :

Example 1 with DocumentDeletedEvent

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());
}
Also used : DocumentDeleteEvent(org.xwiki.observation.event.DocumentDeleteEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) FilterableEvent(org.xwiki.observation.event.FilterableEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with DocumentDeletedEvent

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());
        }
    };
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Example 3 with DocumentDeletedEvent

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;
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 4 with DocumentDeletedEvent

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));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) ArrayList(java.util.ArrayList) Event(org.xwiki.observation.event.Event) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 5 with DocumentDeletedEvent

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");
    }
}
Also used : DocumentUpdatingEvent(org.xwiki.bridge.event.DocumentUpdatingEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentDeletingEvent(org.xwiki.bridge.event.DocumentDeletingEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiNotificationManager(com.xpn.xwiki.notify.XWikiNotificationManager) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) DocumentCreatingEvent(org.xwiki.bridge.event.DocumentCreatingEvent)

Aggregations

DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)28 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)19 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)17 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)14 Test (org.junit.Test)12 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)8 Event (org.xwiki.observation.event.Event)6 ArrayList (java.util.ArrayList)5 DocumentDeletingEvent (org.xwiki.bridge.event.DocumentDeletingEvent)5 BaseObject (com.xpn.xwiki.objects.BaseObject)3 Date (java.util.Date)3 ObservationManager (org.xwiki.observation.ObservationManager)3 XWikiException (com.xpn.xwiki.XWikiException)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)2 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)2 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)2 List (java.util.List)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2