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);
}
}
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);
}
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"));
}
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();
}
}
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());
}
Aggregations