Search in sources :

Example 26 with DocumentDeletedEvent

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());
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 27 with DocumentDeletedEvent

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());
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Test(org.junit.Test)

Example 28 with DocumentDeletedEvent

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentDeletingEvent(org.xwiki.bridge.event.DocumentDeletingEvent) ObservationManager(org.xwiki.observation.ObservationManager) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) Date(java.util.Date) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) BatchOperationExecutor(org.xwiki.refactoring.batch.BatchOperationExecutor)

Aggregations

DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)28 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)19 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)17 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)14 Test (org.junit.Test)12 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)8 Event (org.xwiki.observation.event.Event)6 ArrayList (java.util.ArrayList)5 DocumentDeletingEvent (org.xwiki.bridge.event.DocumentDeletingEvent)5 BaseObject (com.xpn.xwiki.objects.BaseObject)3 Date (java.util.Date)3 ObservationManager (org.xwiki.observation.ObservationManager)3 XWikiException (com.xpn.xwiki.XWikiException)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)2 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)2 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)2 List (java.util.List)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2