Search in sources :

Example 1 with RecordableEventDescriptor

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);
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) ArrayList(java.util.ArrayList) EventStreamException(org.xwiki.eventstream.EventStreamException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) HashSet(java.util.HashSet)

Example 2 with RecordableEventDescriptor

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;
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) UntypedRecordableEventDescriptor(org.xwiki.eventstream.UntypedRecordableEventDescriptor) WikiNamespace(org.xwiki.model.namespace.WikiNamespace) ComponentManager(org.xwiki.component.manager.ComponentManager) ArrayList(java.util.ArrayList) WikiNamespace(org.xwiki.model.namespace.WikiNamespace) Namespace(org.xwiki.component.namespace.Namespace)

Example 3 with RecordableEventDescriptor

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);
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) Event(org.xwiki.eventstream.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) Test(org.junit.Test)

Example 4 with RecordableEventDescriptor

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);
        }
    }
}
Also used : RecordableEventDescriptor(org.xwiki.eventstream.RecordableEventDescriptor) Event(org.xwiki.observation.event.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) EventStreamException(org.xwiki.eventstream.EventStreamException)

Aggregations

RecordableEventDescriptor (org.xwiki.eventstream.RecordableEventDescriptor)4 ArrayList (java.util.ArrayList)2 EventStreamException (org.xwiki.eventstream.EventStreamException)2 UntypedRecordableEventDescriptor (org.xwiki.eventstream.UntypedRecordableEventDescriptor)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 Namespace (org.xwiki.component.namespace.Namespace)1 Event (org.xwiki.eventstream.Event)1 WikiNamespace (org.xwiki.model.namespace.WikiNamespace)1 Event (org.xwiki.observation.event.Event)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1