Search in sources :

Example 21 with DocumentDeletedEvent

use of org.xwiki.bridge.event.DocumentDeletedEvent 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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Example 22 with DocumentDeletedEvent

use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.

the class DefaultWikiObjectComponentManagerEventListenerTest method testOnDocumentDeletedEvent.

@Test
public void testOnDocumentDeletedEvent() throws Exception {
    DocumentDeletedEvent event = mock(DocumentDeletedEvent.class);
    XWikiDocument source = mock(XWikiDocument.class);
    XWikiDocument oldXObjectDocument = mock(XWikiDocument.class);
    BaseObject xObject = mock(BaseObject.class);
    BaseObjectReference xObjectReference = mock(BaseObjectReference.class);
    when(source.getOriginalDocument()).thenReturn(oldXObjectDocument);
    when(xObject.getReference()).thenReturn(xObjectReference);
    DocumentReference xObjectClassReference = (DocumentReference) this.xClassReferences.get(0);
    Map<DocumentReference, List<BaseObject>> fakeDocumentXObjects = new HashMap<>();
    fakeDocumentXObjects.put(xObjectClassReference, Collections.singletonList(xObject));
    when(oldXObjectDocument.getXObjects()).thenReturn(fakeDocumentXObjects);
    mockAssociatedComponentBuilderMethod(xObject);
    this.mocker.getComponentUnderTest().onEvent(event, source, null);
    verify(this.wikiObjectComponentManagerEventListenerProxy, times(1)).unregisterObjectComponents(xObjectReference);
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) HashMap(java.util.HashMap) List(java.util.List) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 23 with DocumentDeletedEvent

use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.

the class ContextComponentManagerTest method testDeleteDocument.

@Test
public void testDeleteDocument() throws Exception {
    getMockery().checking(new Expectations() {

        {
            allowing(mockWikiDescriptorManager).getCurrentWikiId();
            will(returnValue("wiki"));
            allowing(mockCurrentSpaceReferenceProvider).get();
            will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
            allowing(mockCurrentDocumentReferenceProvider).get();
            will(returnValue(new DocumentReference("wiki", "space", "document")));
            allowing(mockDocumentAccessBridge).getCurrentUserReference();
            will(returnValue(new DocumentReference("wiki", "XWiki", "user")));
        }
    });
    ComponentManager documentCM = getComponentManager().getInstance(ComponentManager.class, "document");
    DefaultComponentDescriptor<Role> cd = new DefaultComponentDescriptor<Role>();
    cd.setRoleType(Role.class);
    cd.setImplementation(RoleImpl.class);
    // Register component for the current user
    documentCM.registerComponent(cd);
    // Verify we can lookup the component from the Context CM
    ComponentManager contextCM = getComponentManager().getInstance(ComponentManager.class, "context");
    Assert.assertNotNull(contextCM.getComponentDescriptor(Role.class, "default"));
    ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
    observationManager.notify(new DocumentDeletedEvent(new DocumentReference("wiki", "space", "document")), null, null);
    Assert.assertNull(contextCM.getComponentDescriptor(Role.class, "default"));
}
Also used : Expectations(org.jmock.Expectations) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) SpaceReference(org.xwiki.model.reference.SpaceReference) ComponentManager(org.xwiki.component.manager.ComponentManager) NamespacedComponentManager(org.xwiki.component.manager.NamespacedComponentManager) ObservationManager(org.xwiki.observation.ObservationManager) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 24 with DocumentDeletedEvent

use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    if (source instanceof DocumentModelBridge) {
        // Get the document reference
        DocumentModelBridge document = (DocumentModelBridge) source;
        DocumentReference documentReference = document.getDocumentReference();
        if (event instanceof DocumentCreatedEvent || event instanceof DocumentUpdatedEvent) {
            registerDocumentComponents(document.getDocumentReference());
        } else if (event instanceof DocumentDeletedEvent) {
            // Unregister components from the deleted document, if any
            this.wikiComponentManagerEventListenerHelper.unregisterComponents(documentReference);
        }
    /* If we are at application startup time, we have to instanciate every document or object that we can find
         * in the wiki */
    } else if (event instanceof ApplicationReadyEvent || event instanceof WikiReadyEvent) {
        // These 2 events are created when the database is ready. We register all wiki components.
        registerAllDocumentComponents();
    }
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) WikiReadyEvent(org.xwiki.bridge.event.WikiReadyEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 25 with DocumentDeletedEvent

use of org.xwiki.bridge.event.DocumentDeletedEvent in project xwiki-platform by xwiki.

the class ColorThemeListenerTest 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)

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