Search in sources :

Example 36 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class DocumentEventConverterTest method testConvertWithOriginalDocNull.

@Test
public void testConvertWithOriginalDocNull() throws Exception {
    EventConverterManager eventConverterManager = getComponentManager().getInstance(EventConverterManager.class);
    // local -> remote
    LocalEventData localEvent = new LocalEventData();
    localEvent.setEvent(new DocumentUpdatedEvent(new DocumentReference("wiki", "space", "page")));
    localEvent.setSource(new XWikiDocument(new DocumentReference("wiki", "space", "page")));
    localEvent.setData(getContext());
    RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);
    Assert.assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
    Assert.assertFalse(remoteEvent.getData() instanceof XWikiContext);
    // serialize/unserialize
    ByteArrayOutputStream sos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(sos);
    oos.writeObject(remoteEvent);
    ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(sis);
    remoteEvent = (RemoteEventData) ois.readObject();
    // remote -> local
    LocalEventData localEvent2 = eventConverterManager.createLocalEventData(remoteEvent);
    Assert.assertTrue(localEvent2.getSource() instanceof XWikiDocument);
    Assert.assertTrue(localEvent2.getData() instanceof XWikiContext);
    Assert.assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
    Assert.assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
    Assert.assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
    Assert.assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
}
Also used : LocalEventData(org.xwiki.observation.remote.LocalEventData) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) RemoteEventData(org.xwiki.observation.remote.RemoteEventData) ByteArrayInputStream(java.io.ByteArrayInputStream) EventConverterManager(org.xwiki.observation.remote.converter.EventConverterManager) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) DocumentReference(org.xwiki.model.reference.DocumentReference) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 37 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent 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);
        }
    }
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) AbstractDocumentEvent(org.xwiki.bridge.event.AbstractDocumentEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 38 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class LegacyTestWiki method notifyDocumentModified.

public void notifyDocumentModified(DocumentReference documentReference) {
    TestWiki wiki = wikis.get(documentReference.getWikiReference().getName());
    XWikiDocument document = wiki.getDocument(documentReference);
    // Send event
    observationManager.notify(new DocumentUpdatedEvent(documentReference), document, context);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Example 39 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class RealtimeNotificationGenerator method getWatchListEvent.

/**
 * @param event the current event
 * @param currentDoc the affected document
 * @param context the context of the event
 * @return the {@link WatchListEvent} to use to notify watchers of the current document
 */
private WatchListEvent getWatchListEvent(Event event, XWikiDocument currentDoc, XWikiContext context) {
    String type = null;
    DocumentReference documentReference = currentDoc.getDocumentReference();
    DocumentReference userReference = context.getUserReference();
    String version = currentDoc.getVersion();
    Date date = currentDoc.getDate();
    if (event instanceof DocumentCreatedEvent) {
        type = WatchListEventType.CREATE;
    } else if (event instanceof DocumentUpdatedEvent) {
        type = WatchListEventType.UPDATE;
    } else if (event instanceof DocumentDeletedEvent) {
        version = currentDoc.getOriginalDocument().getVersion();
        type = WatchListEventType.DELETE;
    }
    WatchListEvent watchListEvent = new WatchListEvent(documentReference, type, userReference, version, date);
    return watchListEvent;
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) WatchListEvent(org.xwiki.watchlist.internal.api.WatchListEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date)

Example 40 with DocumentUpdatedEvent

use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.

the class AttachmentEventGeneratorListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    XWikiDocument doc = (XWikiDocument) source;
    XWikiDocument originalDoc = doc.getOriginalDocument();
    XWikiContext context = (XWikiContext) data;
    if (event instanceof DocumentUpdatedEvent) {
        onDocumentUpdatedEvent(originalDoc, doc, context);
    } else if (event instanceof DocumentDeletedEvent) {
        onDocumentDeletedEvent(originalDoc, doc, context);
    } else if (event instanceof DocumentCreatedEvent) {
        onDocumentCreatedEvent(originalDoc, doc, context);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Aggregations

DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)45 Test (org.junit.Test)30 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)26 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)16 DocumentReference (org.xwiki.model.reference.DocumentReference)13 Event (org.xwiki.observation.event.Event)13 XWikiContext (com.xpn.xwiki.XWikiContext)9 ArrayList (java.util.ArrayList)6 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 ObservationManager (org.xwiki.observation.ObservationManager)4 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)3 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 Date (java.util.Date)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)2