Search in sources :

Example 1 with DocumentCreatedEvent

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

the class LegacyEventDispatcher method getEvents.

@Override
public List<Event> getEvents() {
    return new ArrayList<Event>() {

        {
            add(new DocumentDeletedEvent());
            add(new DocumentCreatedEvent());
            add(new DocumentUpdatedEvent());
            add(new ActionExecutedEvent());
        }
    };
}
Also used : DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent)

Example 2 with DocumentCreatedEvent

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

the class LegacyNotificationDispatcher method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    XWikiDocument document = (XWikiDocument) source;
    XWikiDocument originalDocument = document.getOriginalDocument();
    XWikiContext context = (XWikiContext) data;
    XWikiNotificationManager manager = getNotificationManager((XWikiContext) data);
    if (manager != null) {
        if (event instanceof DocumentCreatedEvent) {
            manager.verify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_NEW, context);
        } else if (event instanceof DocumentUpdatedEvent) {
            manager.verify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_CHANGE, context);
        } else if (event instanceof DocumentCreatingEvent) {
            manager.preverify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_NEW, context);
        } else if (event instanceof DocumentUpdatingEvent) {
            manager.preverify(document, originalDocument, XWikiDocChangeNotificationInterface.EVENT_CHANGE, context);
        } else if (event instanceof DocumentDeletedEvent) {
            manager.verify(new XWikiDocument(document.getDocumentReference()), document, XWikiDocChangeNotificationInterface.EVENT_DELETE, context);
        } else if (event instanceof DocumentDeletingEvent) {
            manager.preverify(document, new XWikiDocument(document.getDocumentReference()), XWikiDocChangeNotificationInterface.EVENT_DELETE, context);
        } else if (event instanceof ActionExecutedEvent) {
            manager.verify(document, ((ActionExecutedEvent) event).getActionName(), context);
        } else if (event instanceof ActionExecutingEvent) {
            manager.preverify(document, ((ActionExecutingEvent) event).getActionName(), context);
        }
    } else {
        this.logger.error("Can't find old [XWikiNotificationManager] system");
    }
}
Also used : DocumentUpdatingEvent(org.xwiki.bridge.event.DocumentUpdatingEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentDeletingEvent(org.xwiki.bridge.event.DocumentDeletingEvent) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiNotificationManager(com.xpn.xwiki.notify.XWikiNotificationManager) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) DocumentCreatingEvent(org.xwiki.bridge.event.DocumentCreatingEvent)

Example 3 with DocumentCreatedEvent

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

the class ActivityStreamImpl method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    // Do not record some ignored events
    ObservationContext observationContext = Utils.getComponent(ObservationContext.class);
    if (observationContext.isIn(IGNORED_EVENTS)) {
        return;
    }
    XWikiDocument currentDoc = (XWikiDocument) source;
    XWikiDocument originalDoc = currentDoc.getOriginalDocument();
    XWikiContext context = (XWikiContext) data;
    String wiki = context.getWikiId();
    String msgPrefix = "activitystream.event.";
    String streamName = getStreamName(currentDoc.getSpace(), context);
    // If we haven't found a stream to store the event or if both currentDoc and originalDoc are null: exit
    if (streamName == null) {
        return;
    }
    Execution executionContext = Utils.getComponent(Execution.class);
    // Take events into account only once in a cluster
    if (!Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState() && !executionContext.getContext().hasProperty(AbstractEventStreamEvent.EVENT_LOOP_CONTEXT_LOCK_PROPERTY)) {
        executionContext.getContext().setProperty(AbstractEventStreamEvent.EVENT_LOOP_CONTEXT_LOCK_PROPERTY, true);
        String eventType;
        String displayTitle;
        String additionalIdentifier = null;
        if (event instanceof DocumentCreatedEvent) {
            eventType = ActivityEventType.CREATE;
            displayTitle = currentDoc.getRenderedTitle(context);
        } else if (event instanceof DocumentUpdatedEvent) {
            eventType = ActivityEventType.UPDATE;
            displayTitle = originalDoc.getRenderedTitle(context);
        } else if (event instanceof DocumentDeletedEvent) {
            eventType = ActivityEventType.DELETE;
            displayTitle = originalDoc.getRenderedTitle(context);
            // When we receive a DELETE event, the given document is blank and does not have version & hidden tag
            // properly set.
            currentDoc.setVersion(originalDoc.getVersion());
            currentDoc.setHidden(originalDoc.isHidden());
        } else if (event instanceof CommentAddedEvent) {
            eventType = ActivityEventType.ADD_COMMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((CommentAddedEvent) event).getIdentifier();
        } else if (event instanceof CommentDeletedEvent) {
            eventType = ActivityEventType.DELETE_COMMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((CommentDeletedEvent) event).getIdentifier();
        } else if (event instanceof CommentUpdatedEvent) {
            eventType = ActivityEventType.UPDATE_COMMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((CommentUpdatedEvent) event).getIdentifier();
        } else if (event instanceof AttachmentAddedEvent) {
            eventType = ActivityEventType.ADD_ATTACHMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AttachmentAddedEvent) event).getName();
        } else if (event instanceof AttachmentDeletedEvent) {
            eventType = ActivityEventType.DELETE_ATTACHMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AttachmentDeletedEvent) event).getName();
        } else if (event instanceof AttachmentUpdatedEvent) {
            eventType = ActivityEventType.UPDATE_ATTACHMENT;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AttachmentUpdatedEvent) event).getName();
        } else if (event instanceof AnnotationAddedEvent) {
            eventType = ActivityEventType.ADD_ANNOTATION;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AnnotationAddedEvent) event).getIdentifier();
        } else if (event instanceof AnnotationDeletedEvent) {
            eventType = ActivityEventType.DELETE_ANNOTATION;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AnnotationDeletedEvent) event).getIdentifier();
        } else {
            // update annotation
            eventType = ActivityEventType.UPDATE_ANNOTATION;
            displayTitle = currentDoc.getRenderedTitle(context);
            additionalIdentifier = ((AnnotationUpdatedEvent) event).getIdentifier();
        }
        List<String> params = new ArrayList<String>();
        params.add(displayTitle);
        if (additionalIdentifier != null) {
            params.add(additionalIdentifier);
        }
        try {
            addDocumentActivityEvent(streamName, currentDoc, eventType, msgPrefix + eventType, params, context);
        } catch (ActivityStreamException e) {
            LOGGER.error("Exception while trying to add a document activity event, updated document: [" + wiki + ":" + currentDoc + "]");
        }
        executionContext.getContext().removeProperty(AbstractEventStreamEvent.EVENT_LOOP_CONTEXT_LOCK_PROPERTY);
    }
}
Also used : AttachmentAddedEvent(com.xpn.xwiki.internal.event.AttachmentAddedEvent) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) CommentUpdatedEvent(com.xpn.xwiki.internal.event.CommentUpdatedEvent) RemoteObservationManagerContext(org.xwiki.observation.remote.RemoteObservationManagerContext) CommentDeletedEvent(com.xpn.xwiki.internal.event.CommentDeletedEvent) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) CommentAddedEvent(com.xpn.xwiki.internal.event.CommentAddedEvent) Execution(org.xwiki.context.Execution) AnnotationAddedEvent(org.xwiki.annotation.event.AnnotationAddedEvent) AttachmentUpdatedEvent(com.xpn.xwiki.internal.event.AttachmentUpdatedEvent) ObservationContext(org.xwiki.observation.ObservationContext) AnnotationDeletedEvent(org.xwiki.annotation.event.AnnotationDeletedEvent) AttachmentDeletedEvent(com.xpn.xwiki.internal.event.AttachmentDeletedEvent)

Example 4 with DocumentCreatedEvent

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

the class XWikiTest method testSaveDocumentSendsObservationEvents.

/**
 * We only verify here that the saveDocument API calls the Observation component.
 */
public void testSaveDocumentSendsObservationEvents() throws Exception {
    Mock mockListener = mock(EventListener.class);
    mockListener.stubs().method("getName").will(returnValue("testlistener"));
    DocumentReference ref = new DocumentReference("xwikitest", "Some", "Document");
    mockListener.expects(once()).method("getEvents").will(returnValue(Arrays.asList(new DocumentCreatedEvent(ref), new DocumentCreatingEvent(ref))));
    ObservationManager om = getComponentManager().getInstance(ObservationManager.class);
    om.addListener((EventListener) mockListener.proxy());
    XWikiDocument document = new XWikiDocument(new DocumentReference("xwikitest", "Some", "Document"));
    document.setContent("the content");
    // Ensure that the onEvent method has been called before and after the save
    mockListener.expects(once()).method("onEvent").with(isA(DocumentCreatingEvent.class), same(document), isA(XWikiContext.class));
    mockListener.expects(once()).method("onEvent").with(isA(DocumentCreatedEvent.class), same(document), isA(XWikiContext.class));
    this.xwiki.saveDocument(document, getContext());
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) ObservationManager(org.xwiki.observation.ObservationManager) DocumentCreatingEvent(org.xwiki.bridge.event.DocumentCreatingEvent) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with DocumentCreatedEvent

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

the class AutomaticWatchModeListenerTest method onEventWhenInContextOXARImportingEvent.

/**
 * Verify that we don't do anything when the current event is inside a XARImportingEvent.
 */
@Test
public void onEventWhenInContextOXARImportingEvent() throws Exception {
    // We simulate a XARImportingEvent in the Execution Context
    this.observationContextListener.onEvent(new XARImportingEvent(), null, null);
    mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null);
    verify(mockStore, never()).getAutomaticWatchMode(any());
    verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class));
}
Also used : XARImportingEvent(com.xpn.xwiki.internal.event.XARImportingEvent) WatchedElementType(org.xwiki.watchlist.internal.api.WatchedElementType) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) Test(org.junit.Test)

Aggregations

DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)26 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)18 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)17 Test (org.junit.Test)11 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)10 DocumentReference (org.xwiki.model.reference.DocumentReference)10 XWikiContext (com.xpn.xwiki.XWikiContext)8 Event (org.xwiki.observation.event.Event)5 ArrayList (java.util.ArrayList)4 DocumentCreatingEvent (org.xwiki.bridge.event.DocumentCreatingEvent)4 Date (java.util.Date)3 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)3 XWiki (com.xpn.xwiki.XWiki)2 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 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)2