Search in sources :

Example 16 with DocumentCreatedEvent

use of org.xwiki.bridge.event.DocumentCreatedEvent 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 17 with DocumentCreatedEvent

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

the class AutomaticWatchModeListenerTest method onEventWhenWatchListDisabled.

/**
 * Verify that we don't do anything when the watchlist is disabled.
 */
@Test
public void onEventWhenWatchListDisabled() throws Exception {
    when(this.configuration.isEnabled()).thenReturn(false);
    mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null);
    verify(mockStore, never()).getAutomaticWatchMode(any());
    verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class));
}
Also used : WatchedElementType(org.xwiki.watchlist.internal.api.WatchedElementType) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Test(org.junit.Test)

Example 18 with DocumentCreatedEvent

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

the class AutomaticWatchModeListenerTest method onEventWhenInContextOfWikiCreatingEvent.

/**
 * Verify that we don't do anything when the current event is inside a WikiCreatingEvent.
 */
@Test
public void onEventWhenInContextOfWikiCreatingEvent() throws Exception {
    // We simulate a WikiCreatingEvent in the Execution Context
    this.observationContextListener.onEvent(new WikiCreatingEvent(), null, null);
    mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null);
    verify(mockStore, never()).getAutomaticWatchMode(any());
    verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class));
}
Also used : WatchedElementType(org.xwiki.watchlist.internal.api.WatchedElementType) WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Test(org.junit.Test)

Example 19 with DocumentCreatedEvent

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

the class AutomaticWatchModeListenerTest method onEventWhenDocumentCreatedEvent.

@Test
public void onEventWhenDocumentCreatedEvent() throws Exception {
    XWikiContext context = mock(XWikiContext.class);
    XWikiDocument document = mock(XWikiDocument.class);
    DocumentReference documentReference = new DocumentReference("authorWiki", "authorSpace", "authorPage");
    when(document.getContentAuthor()).thenReturn("content author");
    when(document.getContentAuthorReference()).thenReturn(documentReference);
    when(document.getPrefixedFullName()).thenReturn("authorSpace.authorPage");
    when(this.mockStore.getAutomaticWatchMode("content author")).thenReturn(AutomaticWatchMode.ALL);
    XWiki xwiki = mock(XWiki.class);
    when(xwiki.exists(documentReference, context)).thenReturn(true);
    when(context.getWiki()).thenReturn(xwiki);
    mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), document, context);
    // Verify that the document is added to the watchlist
    verify(this.mockStore).addWatchedElement("content author", "authorSpace.authorPage", org.xwiki.watchlist.internal.api.WatchedElementType.DOCUMENT);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 20 with DocumentCreatedEvent

use of org.xwiki.bridge.event.DocumentCreatedEvent 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

DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)26 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)18 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)17 Test (org.junit.Test)11 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)10 DocumentReference (org.xwiki.model.reference.DocumentReference)10 XWikiContext (com.xpn.xwiki.XWikiContext)8 Event (org.xwiki.observation.event.Event)5 ArrayList (java.util.ArrayList)4 DocumentCreatingEvent (org.xwiki.bridge.event.DocumentCreatingEvent)4 Date (java.util.Date)3 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)3 XWiki (com.xpn.xwiki.XWiki)2 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 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)2