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