Search in sources :

Example 1 with EventStreamAddedEvent

use of org.xwiki.eventstream.events.EventStreamAddedEvent in project xwiki-platform by xwiki.

the class ActivityStreamImpl method addActivityEvent.

/**
 * @param event event to add to the stream
 * @param doc which fired the event
 * @param context the XWiki context
 * @throws ActivityStreamException if the addition to the stream fails
 */
public void addActivityEvent(ActivityEvent event, XWikiDocument doc, XWikiContext context) throws ActivityStreamException {
    prepareEvent(event, doc, context);
    if (useLocalStore()) {
        // store event in the local database
        XWikiHibernateStore localHibernateStore = context.getWiki().getHibernateStore();
        try {
            localHibernateStore.beginTransaction(context);
            Session session = localHibernateStore.getSession(context);
            session.save(event);
            localHibernateStore.endTransaction(context, true);
        } catch (XWikiException e) {
            localHibernateStore.endTransaction(context, false);
        }
    }
    if (useMainStore()) {
        // store event in the main database
        String oriDatabase = context.getWikiId();
        context.setWikiId(context.getMainXWiki());
        XWikiHibernateStore mainHibernateStore = context.getWiki().getHibernateStore();
        try {
            mainHibernateStore.beginTransaction(context);
            Session session = mainHibernateStore.getSession(context);
            session.save(event);
            mainHibernateStore.endTransaction(context, true);
        } catch (XWikiException e) {
            mainHibernateStore.endTransaction(context, false);
        } finally {
            context.setWikiId(oriDatabase);
        }
    }
    this.sendEventStreamEvent(new EventStreamAddedEvent(), event);
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Example 2 with EventStreamAddedEvent

use of org.xwiki.eventstream.events.EventStreamAddedEvent in project xwiki-platform by xwiki.

the class BridgeEventStream method addEvent.

@Override
public void addEvent(Event e) {
    try {
        XWikiContext context = getXWikiContext();
        ActivityStreamPlugin plugin = getPlugin(context);
        plugin.getActivityStream().addActivityEvent(eventConverter.convertEventToActivity(e), context);
        this.observationManager.notify(new EventStreamAddedEvent(), e);
    } catch (ActivityStreamException ex) {
    // Unlikely; nothing we can do
    }
}
Also used : EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 3 with EventStreamAddedEvent

use of org.xwiki.eventstream.events.EventStreamAddedEvent 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)

Aggregations

EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)3 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)1 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)1 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)1 Session (org.hibernate.Session)1 Test (org.junit.Test)1 Event (org.xwiki.eventstream.Event)1 RecordableEventDescriptor (org.xwiki.eventstream.RecordableEventDescriptor)1