Search in sources :

Example 6 with DefaultEvent

use of org.xwiki.eventstream.internal.DefaultEvent in project xwiki-platform by xwiki.

the class NotificationScriptEventHelper method saveEventStatus.

/**
 * Save a status for the current user.
 * See {@link NotificationScriptService#saveEventStatus(String, boolean)} for more details.
 *
 * @param eventId id of the event
 * @param isRead either or not the current user has read the given event
 * @throws Exception if an error occurs
 */
public void saveEventStatus(String eventId, boolean isRead) throws Exception {
    DefaultEvent event = new DefaultEvent();
    event.setId(eventId);
    String userId = entityReferenceSerializer.serialize(documentAccessBridge.getCurrentUserReference());
    eventStatusManager.saveEventStatus(new DefaultEventStatus(event, userId, isRead));
}
Also used : DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) DefaultEventStatus(org.xwiki.eventstream.internal.DefaultEventStatus)

Example 7 with DefaultEvent

use of org.xwiki.eventstream.internal.DefaultEvent in project xwiki-platform by xwiki.

the class DefaultRecordableEventConverter method convert.

@Override
public Event convert(RecordableEvent recordableEvent, String source, Object data) throws Exception {
    XWikiContext context = contextProvider.get();
    org.xwiki.eventstream.Event convertedEvent = new DefaultEvent();
    convertedEvent.setType(recordableEvent.getClass().getCanonicalName());
    convertedEvent.setApplication(source);
    convertedEvent.setDate(new Date());
    convertedEvent.setUser(context.getUserReference());
    convertedEvent.setWiki(context.getWikiReference());
    if (recordableEvent instanceof TargetableEvent) {
        convertedEvent.setTarget(((TargetableEvent) recordableEvent).getTarget());
    }
    if (data instanceof String) {
        convertedEvent.setBody((String) data);
    } else if (data instanceof XWikiDocument) {
        XWikiDocument document = (XWikiDocument) data;
        convertedEvent.setDocument(document.getDocumentReference());
        convertedEvent.setDocumentVersion(document.getVersion());
        convertedEvent.setDocumentTitle(document.getRenderedTitle(context));
    }
    return convertedEvent;
}
Also used : DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) TargetableEvent(org.xwiki.eventstream.TargetableEvent) Event(org.xwiki.eventstream.Event) XWikiContext(com.xpn.xwiki.XWikiContext) Date(java.util.Date)

Example 8 with DefaultEvent

use of org.xwiki.eventstream.internal.DefaultEvent in project xwiki-platform by xwiki.

the class MessageStreamTest method setupForNewMessage.

private Event setupForNewMessage() throws ComponentLookupException, Exception {
    final EventFactory mockEventFactory = getComponentManager().getInstance(EventFactory.class);
    final Event e = new DefaultEvent();
    e.setId(UUID.randomUUID().toString());
    final ModelContext mockContext = getComponentManager().getInstance(ModelContext.class);
    final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
    getMockery().checking(new Expectations() {

        {
            exactly(1).of(mockEventFactory).createEvent();
            will(returnValue(e));
            exactly(1).of(mockContext).getCurrentEntityReference();
            will(returnValue(new DocumentReference("wiki", "Space", "Page")));
            exactly(1).of(mockEventStream).addEvent(e);
        }
    });
    return e;
}
Also used : ModelContext(org.xwiki.model.ModelContext) Expectations(org.jmock.Expectations) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) EventStream(org.xwiki.eventstream.EventStream) EventFactory(org.xwiki.eventstream.EventFactory) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 9 with DefaultEvent

use of org.xwiki.eventstream.internal.DefaultEvent in project xwiki-platform by xwiki.

the class EventGroupTest method testAddEvents.

@Test
public void testAddEvents() {
    Assert.assertTrue(this.g.getEvents().isEmpty());
    Event e1 = new DefaultEvent();
    Assert.assertTrue(this.g.getEvents().isEmpty());
    this.g.addEvents(e1);
    Assert.assertFalse(this.g.getEvents().isEmpty());
    Assert.assertEquals(1, this.g.getEvents().size());
    this.g.addEvents(e1);
    Assert.assertEquals(1, this.g.getEvents().size());
    Event e2 = new DefaultEvent();
    this.g.addEvents(e2, e2, e2);
    Assert.assertEquals(2, this.g.getEvents().size());
    this.g.addEvents(e1, e2);
    Assert.assertEquals(2, this.g.getEvents().size());
    Event e3 = new DefaultEvent();
    this.g.addEvents(e1, e2, e3);
    Assert.assertEquals(3, this.g.getEvents().size());
    this.g.clearEvents();
    Assert.assertEquals(0, this.g.getEvents().size());
    Assert.assertTrue(this.g.getEvents().isEmpty());
    this.g.addEvents(e1, e2, e3);
    Assert.assertEquals(3, this.g.getEvents().size());
}
Also used : DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 10 with DefaultEvent

use of org.xwiki.eventstream.internal.DefaultEvent in project xwiki-platform by xwiki.

the class EventGroupTest method testAddEventsWithNull.

@Test
public void testAddEventsWithNull() {
    this.g.addEvents((Event) null);
    Assert.assertTrue(this.g.getEvents().isEmpty());
    this.g.addEvents(new DefaultEvent());
    Assert.assertEquals(1, this.g.getEvents().size());
    this.g.addEvents((Event) null);
    Assert.assertEquals(1, this.g.getEvents().size());
}
Also used : DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Aggregations

DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Event (org.xwiki.eventstream.Event)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Date (java.util.Date)1 Expectations (org.jmock.Expectations)1 EventFactory (org.xwiki.eventstream.EventFactory)1 EventStream (org.xwiki.eventstream.EventStream)1 TargetableEvent (org.xwiki.eventstream.TargetableEvent)1 DefaultEventStatus (org.xwiki.eventstream.internal.DefaultEventStatus)1 ModelContext (org.xwiki.model.ModelContext)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1