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;
}
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));
}
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));
}
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);
}
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);
}
}
Aggregations