use of org.xwiki.observation.ObservationManager in project xwiki-platform by xwiki.
the class XWikiServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
SHUTDOWN_LOGGER.debug("Stopping XWiki...");
// It's possible that the Component Manager failed to initialize some of the required components.
if (this.componentManager != null) {
// to do something on stop to do it.
try {
ObservationManager observationManager = this.componentManager.getInstance(ObservationManager.class);
observationManager.notify(new ApplicationStoppedEvent(), this);
} catch (ComponentLookupException e) {
// Nothing to do here.
// TODO: Log a warning
}
// below in an Event Listener and move it to the legacy module.
try {
ApplicationContextListenerManager applicationContextListenerManager = this.componentManager.getInstance(ApplicationContextListenerManager.class);
Container container = this.componentManager.getInstance(Container.class);
applicationContextListenerManager.destroyApplicationContext(container.getApplicationContext());
} catch (ComponentLookupException ex) {
// Nothing to do here.
// TODO: Log a warning
}
// Make sure to dispose all components before leaving
this.componentManager.dispose();
}
SHUTDOWN_LOGGER.debug("XWiki has been stopped!");
}
use of org.xwiki.observation.ObservationManager in project xwiki-platform by xwiki.
the class AttachmentEventGeneratorListener method onDocumentUpdatedEvent.
/**
* @param originalDoc the previous version of the document
* @param doc the new version of the document
* @param context the XWiki context
*/
private void onDocumentUpdatedEvent(XWikiDocument originalDoc, XWikiDocument doc, XWikiContext context) {
ObservationManager observation = Utils.getComponent(ObservationManager.class);
String reference = this.defaultEntityReferenceSerializer.serialize(doc.getDocumentReference());
for (AttachmentDiff diff : doc.getAttachmentDiff(originalDoc, doc, context)) {
if (StringUtils.isEmpty(diff.getOrigVersion())) {
observation.notify(new AttachmentAddedEvent(reference, diff.getFileName()), doc, context);
} else if (StringUtils.isEmpty(diff.getNewVersion())) {
observation.notify(new AttachmentDeletedEvent(reference, diff.getFileName()), doc, context);
} else {
observation.notify(new AttachmentUpdatedEvent(reference, diff.getFileName()), doc, context);
}
}
}
use of org.xwiki.observation.ObservationManager in project xwiki-platform by xwiki.
the class DefaultDocumentCacheTest method testEventBasedCleanup.
@Test
public void testEventBasedCleanup() throws Exception {
this.cache.set("data", this.document.getDocumentReference());
this.cache.set("data", this.document.getDocumentReference(), "ext1", "ext2");
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
observationManager.notify(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, getContext());
Assert.assertNull(this.cache.get(this.document.getDocumentReference()));
Assert.assertNull(this.cache.get(this.document.getDocumentReference(), "ext1", "ext2"));
}
use of org.xwiki.observation.ObservationManager in project xwiki-platform by xwiki.
the class DefaultRenderingCacheTest method testGetSetRenderedContent.
@Test
public void testGetSetRenderedContent() throws Exception {
MockConfigurationSource source = getConfigurationSource();
source.setProperty("core.renderingcache.documents", Collections.singletonList(this.document.getPrefixedFullName()));
this.renderingCache.setRenderedContent(this.document.getDocumentReference(), "source", "renderedContent", getContext());
Assert.assertEquals("renderedContent", this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
this.parameters.put("param", new String[] { "value1", "value2" });
Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
this.parameters.remove("param");
Assert.assertEquals("renderedContent", this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
observationManager.notify(new DocumentUpdatedEvent(this.document.getDocumentReference()), this.document, getContext());
Assert.assertNull(this.renderingCache.getRenderedContent(this.document.getDocumentReference(), "source", getContext()));
}
use of org.xwiki.observation.ObservationManager in project xwiki-platform by xwiki.
the class XWikiMockitoTest method rollbackFiresEvents.
/**
* Verify that {@link XWiki#rollback(XWikiDocument, String, XWikiContext)} fires the right events.
*/
@Test
public void rollbackFiresEvents() throws Exception {
ObservationManager observationManager = mocker.getInstance(ObservationManager.class);
DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
XWikiDocument document = mock(XWikiDocument.class);
when(document.getDocumentReference()).thenReturn(documentReference);
XWikiDocument originalDocument = mock(XWikiDocument.class);
// Mark the document as existing so that the roll-back method will fire an update event.
when(originalDocument.isNew()).thenReturn(false);
XWikiDocument result = mock(XWikiDocument.class);
when(result.clone()).thenReturn(result);
when(result.getDocumentReference()).thenReturn(documentReference);
when(result.getOriginalDocument()).thenReturn(originalDocument);
String revision = "3.5";
when(this.documentRevisionProvider.getRevision(document, revision)).thenReturn(result);
this.mocker.registerMockComponent(ContextualLocalizationManager.class);
xwiki.rollback(document, revision, context);
verify(observationManager).notify(new DocumentRollingBackEvent(documentReference, revision), result, context);
verify(observationManager).notify(new DocumentUpdatingEvent(documentReference), result, context);
verify(observationManager).notify(new DocumentUpdatedEvent(documentReference), result, context);
verify(observationManager).notify(new DocumentRolledBackEvent(documentReference, revision), result, context);
}
Aggregations