Search in sources :

Example 1 with TargetableEvent

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

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Date (java.util.Date)1 Event (org.xwiki.eventstream.Event)1 TargetableEvent (org.xwiki.eventstream.TargetableEvent)1 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)1