use of org.xwiki.eventstream.RecordableEventDescriptor in project xwiki-platform by xwiki.
the class DefaultRecordableEventDescriptorManager method getRecordableEventDescriptors.
@Override
public List<RecordableEventDescriptor> getRecordableEventDescriptors(boolean allWikis) throws EventStreamException {
try {
// We use an hashSet to be sure we won't store the same descriptor twice (in case the same application
// is installed on several wikis).
Set<RecordableEventDescriptor> recordableEventDescriptors = new HashSet<>();
// Load the component from the context component manager (root + wiki + user component managers, etc...)
recordableEventDescriptors.addAll(contextComponentManager.getInstanceList(RecordableEventDescriptor.class));
// Maybe add components of the other wikis too
if (allWikis) {
for (String wikiId : wikiDescriptorManager.getAllIds()) {
recordableEventDescriptors.addAll(getDescriptorsFromWiki(wikiId));
}
}
return new ArrayList<>(recordableEventDescriptors);
} catch (WikiManagerException | ComponentLookupException e) {
throw new EventStreamException("Failed to get the list of all Recordable Event Descriptors.", e);
}
}
use of org.xwiki.eventstream.RecordableEventDescriptor in project xwiki-platform by xwiki.
the class DefaultRecordableEventDescriptorManager method getDescriptorsFromWiki.
private List<RecordableEventDescriptor> getDescriptorsFromWiki(String wikiId) throws ComponentLookupException {
Namespace namespace = new WikiNamespace(wikiId);
ComponentManager wikiComponentManager = componentManagerManager.getComponentManager(namespace.serialize(), false);
if (wikiComponentManager == null) {
return Collections.emptyList();
}
List<RecordableEventDescriptor> descriptors = new ArrayList<>();
descriptors.addAll(wikiComponentManager.getInstanceList(RecordableEventDescriptor.class));
descriptors.addAll(wikiComponentManager.getInstanceList(UntypedRecordableEventDescriptor.class));
return descriptors;
}
use of org.xwiki.eventstream.RecordableEventDescriptor in project xwiki-platform by xwiki.
the class LiveNotificationEmailListenerTest method testOnEvent.
@Test
public void testOnEvent() throws Exception {
Event eventStreamEvent = mock(Event.class);
EventStreamAddedEvent event = mock(EventStreamAddedEvent.class);
RecordableEventDescriptor eventDescriptor = mock(RecordableEventDescriptor.class);
when(eventDescriptor.getEventType()).thenReturn("eventType");
when(this.recordableEventDescriptorManager.getRecordableEventDescriptors(true)).thenReturn(Arrays.asList(eventDescriptor));
when(eventStreamEvent.getType()).thenReturn("eventType");
when(this.notificationConfiguration.areEmailsEnabled()).thenReturn(true);
when(this.notificationConfiguration.isEnabled()).thenReturn(true);
this.mocker.getComponentUnderTest().onEvent(event, eventStreamEvent, null);
verify(this.liveNotificationEmailManager, times(1)).addEvent(eventStreamEvent);
}
use of org.xwiki.eventstream.RecordableEventDescriptor 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);
}
}
}
Aggregations