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