use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class SSXListenerTest method getEvents.
@Test
public void getEvents() throws Exception {
List<Event> eventsToObserve = Arrays.<Event>asList(new DocumentCreatedEvent(), new DocumentUpdatedEvent(), new DocumentDeletedEvent());
assertEquals(eventsToObserve, mocker.getComponentUnderTest().getEvents());
}
use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class SkinListenerTest method getEvents.
@Test
public void getEvents() throws Exception {
List<Event> eventsToObserve = Arrays.<Event>asList(new DocumentCreatedEvent(), new DocumentUpdatedEvent(), new DocumentDeletedEvent());
assertEquals(eventsToObserve, mocker.getComponentUnderTest().getEvents());
}
use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.
the class XWiki method deleteDocument.
public void deleteDocument(XWikiDocument doc, boolean totrash, XWikiContext context) throws XWikiException {
String currentWiki = null;
currentWiki = context.getWikiId();
try {
context.setWikiId(doc.getDocumentReference().getWikiReference().getName());
// The source document is a new empty XWikiDocument to follow
// DocumentUpdatedEvent policy: source document in new document and the old version is available using
// doc.getOriginalDocument()
XWikiDocument blankDoc = new XWikiDocument(doc.getDocumentReference());
// Again to follow general event policy, new document author is the user who modified the document
// (here the modification is delete)
blankDoc.setOriginalDocument(doc.getOriginalDocument());
blankDoc.setAuthorReference(context.getUserReference());
blankDoc.setContentAuthorReference(context.getUserReference());
ObservationManager om = getObservationManager();
// an XWikiDocument as source and an XWikiContext as data.
if (om != null) {
om.notify(new DocumentDeletingEvent(doc.getDocumentReference()), blankDoc, context);
}
if (hasRecycleBin(context) && totrash) {
// Extract any existing batchId from the context.
String batchId = Utils.getComponent(BatchOperationExecutor.class).getCurrentBatchId();
// Save to recycle bin together with any determined batch ID.
getRecycleBinStore().saveToRecycleBin(doc, context.getUser(), new Date(), batchId, context, true);
}
getStore().deleteXWikiDoc(doc, context);
try {
// an XWikiDocument as source and an XWikiContext as data.
if (om != null) {
om.notify(new DocumentDeletedEvent(doc.getDocumentReference()), blankDoc, context);
}
} catch (Exception ex) {
LOGGER.error("Failed to send document delete notifications for document [{}]", doc.getDocumentReference(), ex);
}
} finally {
context.setWikiId(currentWiki);
}
}
Aggregations