Search in sources :

Example 36 with Event

use of org.xwiki.observation.event.Event in project xwiki-platform by xwiki.

the class LiveNotificationEmailListener method onEvent.

@Override
public void onEvent(Event event, Object o, Object o1) {
    // notifications is enabled.
    if (this.notificationConfiguration.isEnabled() && this.notificationConfiguration.areEmailsEnabled()) {
        try {
            org.xwiki.eventstream.Event eventStreamEvent = (org.xwiki.eventstream.Event) o;
            // We can’t directly store a list of RecordableEventDescriptors as some of them can be
            // dynamically defined at runtime.
            List<RecordableEventDescriptor> descriptorList = this.recordableEventDescriptorManager.getRecordableEventDescriptors(true);
            // Try to match one of the given descriptors with the current event.
            for (RecordableEventDescriptor descriptor : descriptorList) {
                // Find a descriptor that corresponds to the given event
                if (descriptor.getEventType().equals(eventStreamEvent.getType())) {
                    // Add the event to the live notification email queue
                    this.liveNotificationEmailManager.addEvent(eventStreamEvent);
                    this.startNotificationThread();
                }
            }
        } catch (EventStreamException e) {
            logger.warn("Unable to retrieve a full list of RecordableEventDescriptor.", e);
        }
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) Event(org.xwiki.observation.event.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) EventStreamException(org.xwiki.eventstream.EventStreamException)

Example 37 with Event

use of org.xwiki.observation.event.Event in project xwiki-platform by xwiki.

the class ColorThemeListenerTest method onEventWhenColorThemeChanged.

@Test
public void onEventWhenColorThemeChanged() throws Exception {
    // Mocks
    Event event = mock(Event.class);
    XWikiDocument doc = mock(XWikiDocument.class);
    Object data = new Object();
    EntityReference classReference = new LocalDocumentReference("ColorThemes", "ColorThemeClass");
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(doc.getXObjects(classReference)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    when(doc.getDocumentReference()).thenReturn(documentReference);
    ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
    when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
    // Test
    mocker.getComponentUnderTest().onEvent(event, doc, data);
    // Verify
    verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
    verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) ColorThemeReference(org.xwiki.lesscss.internal.colortheme.ColorThemeReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 38 with Event

use of org.xwiki.observation.event.Event in project xwiki-platform by xwiki.

the class ColorThemeListenerTest method onEventWhenNoObject.

@Test
public void onEventWhenNoObject() throws Exception {
    // Mocks
    Event event = mock(Event.class);
    XWikiDocument doc = mock(XWikiDocument.class);
    Object data = new Object();
    EntityReference classReference = new EntityReference("ColorThemeClass", EntityType.DOCUMENT, new EntityReference("ColorThemes", EntityType.SPACE));
    List<BaseObject> objects = new ArrayList<>();
    when(doc.getXObjects(classReference)).thenReturn(objects);
    // Test
    mocker.getComponentUnderTest().onEvent(event, doc, data);
    // Verify
    verifyZeroInteractions(lessResourcesCache);
    verifyZeroInteractions(colorThemeCache);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 39 with Event

use of org.xwiki.observation.event.Event in project xwiki-platform by xwiki.

the class ColorThemeListenerTest method getEvents.

@Test
public void getEvents() throws Exception {
    List<Event> eventsToObserve = Arrays.<Event>asList(new DocumentCreatedEvent(), new DocumentUpdatedEvent(), new DocumentDeletedEvent());
    assertEquals(eventsToObserve, mocker.getComponentUnderTest().getEvents());
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 40 with Event

use of org.xwiki.observation.event.Event in project xwiki-platform by xwiki.

the class ColorThemeListenerTest method onEventWhenFlamingoThemeChanged.

@Test
public void onEventWhenFlamingoThemeChanged() throws Exception {
    // Mocks
    Event event = mock(Event.class);
    XWikiDocument doc = mock(XWikiDocument.class);
    Object data = new Object();
    EntityReference classReference = new LocalDocumentReference("FlamingoThemesCode", "ThemeClass");
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object = mock(BaseObject.class);
    objects.add(object);
    when(doc.getXObjects(classReference)).thenReturn(objects);
    DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
    when(doc.getDocumentReference()).thenReturn(documentReference);
    ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null);
    when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference);
    // Test
    mocker.getComponentUnderTest().onEvent(event, doc, data);
    // Verify
    verify(lessResourcesCache).clearFromColorTheme(colorThemeReference);
    verify(colorThemeCache).clearFromColorTheme(colorThemeReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) ColorThemeReference(org.xwiki.lesscss.internal.colortheme.ColorThemeReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentColorThemeReference(org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Aggregations

Event (org.xwiki.observation.event.Event)54 Test (org.junit.Test)48 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)23 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)23 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)21 ArticleCreatingEvent (com.celements.blog.observation.event.ArticleCreatingEvent)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ArticleCreatedEvent (com.celements.blog.observation.event.ArticleCreatedEvent)8 ArticleDeletedEvent (com.celements.blog.observation.event.ArticleDeletedEvent)8 ArticleDeletingEvent (com.celements.blog.observation.event.ArticleDeletingEvent)8 BlogCreatedEvent (com.celements.blog.observation.event.BlogCreatedEvent)8 BlogCreatingEvent (com.celements.blog.observation.event.BlogCreatingEvent)8 BlogDeletedEvent (com.celements.blog.observation.event.BlogDeletedEvent)8 BlogDeletingEvent (com.celements.blog.observation.event.BlogDeletingEvent)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 ArticleUpdatingEvent (com.celements.blog.observation.event.ArticleUpdatingEvent)7 ArrayList (java.util.ArrayList)7 ArticleUpdatedEvent (com.celements.blog.observation.event.ArticleUpdatedEvent)6 BlogUpdatedEvent (com.celements.blog.observation.event.BlogUpdatedEvent)6 BlogUpdatingEvent (com.celements.blog.observation.event.BlogUpdatingEvent)6