use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class DocumentEventConverterTest method testConvertWithOriginalDocNull.
@Test
public void testConvertWithOriginalDocNull() throws Exception {
EventConverterManager eventConverterManager = getComponentManager().getInstance(EventConverterManager.class);
// local -> remote
LocalEventData localEvent = new LocalEventData();
localEvent.setEvent(new DocumentUpdatedEvent(new DocumentReference("wiki", "space", "page")));
localEvent.setSource(new XWikiDocument(new DocumentReference("wiki", "space", "page")));
localEvent.setData(getContext());
RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);
Assert.assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
Assert.assertFalse(remoteEvent.getData() instanceof XWikiContext);
// serialize/unserialize
ByteArrayOutputStream sos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(sos);
oos.writeObject(remoteEvent);
ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(sis);
remoteEvent = (RemoteEventData) ois.readObject();
// remote -> local
LocalEventData localEvent2 = eventConverterManager.createLocalEventData(remoteEvent);
Assert.assertTrue(localEvent2.getSource() instanceof XWikiDocument);
Assert.assertTrue(localEvent2.getData() instanceof XWikiContext);
Assert.assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
Assert.assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
Assert.assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
Assert.assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class WikiMacroEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (event instanceof AbstractDocumentEvent) {
DocumentModelBridge document = (DocumentModelBridge) source;
DocumentReference documentReference = document.getDocumentReference();
if (event instanceof DocumentCreatedEvent || event instanceof DocumentUpdatedEvent) {
registerMacro(documentReference);
} else if (event instanceof DocumentDeletedEvent) {
unregisterMacro(documentReference);
}
}
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class LegacyTestWiki method notifyDocumentModified.
public void notifyDocumentModified(DocumentReference documentReference) {
TestWiki wiki = wikis.get(documentReference.getWikiReference().getName());
XWikiDocument document = wiki.getDocument(documentReference);
// Send event
observationManager.notify(new DocumentUpdatedEvent(documentReference), document, context);
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class RealtimeNotificationGenerator method getWatchListEvent.
/**
* @param event the current event
* @param currentDoc the affected document
* @param context the context of the event
* @return the {@link WatchListEvent} to use to notify watchers of the current document
*/
private WatchListEvent getWatchListEvent(Event event, XWikiDocument currentDoc, XWikiContext context) {
String type = null;
DocumentReference documentReference = currentDoc.getDocumentReference();
DocumentReference userReference = context.getUserReference();
String version = currentDoc.getVersion();
Date date = currentDoc.getDate();
if (event instanceof DocumentCreatedEvent) {
type = WatchListEventType.CREATE;
} else if (event instanceof DocumentUpdatedEvent) {
type = WatchListEventType.UPDATE;
} else if (event instanceof DocumentDeletedEvent) {
version = currentDoc.getOriginalDocument().getVersion();
type = WatchListEventType.DELETE;
}
WatchListEvent watchListEvent = new WatchListEvent(documentReference, type, userReference, version, date);
return watchListEvent;
}
use of org.xwiki.bridge.event.DocumentUpdatedEvent in project xwiki-platform by xwiki.
the class AttachmentEventGeneratorListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XWikiDocument doc = (XWikiDocument) source;
XWikiDocument originalDoc = doc.getOriginalDocument();
XWikiContext context = (XWikiContext) data;
if (event instanceof DocumentUpdatedEvent) {
onDocumentUpdatedEvent(originalDoc, doc, context);
} else if (event instanceof DocumentDeletedEvent) {
onDocumentDeletedEvent(originalDoc, doc, context);
} else if (event instanceof DocumentCreatedEvent) {
onDocumentCreatedEvent(originalDoc, doc, context);
}
}
Aggregations