Search in sources :

Example 31 with ActionExecutedEvent

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

the class ActionExecutedEventTest method testEqualsSameAction.

@Test
public void testEqualsSameAction() {
    ActionExecutedEvent event = new ActionExecutedEvent("something");
    Assert.assertTrue("Same action wasn't equal!", event.equals(new ActionExecutedEvent("something")));
}
Also used : ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) Test(org.junit.Test)

Example 32 with ActionExecutedEvent

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

the class XWikiStatsServiceImpl method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    if (Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) {
        // take care of this
        return;
    }
    ActionExecutedEvent actionEvent = (ActionExecutedEvent) event;
    XWikiDocument document = (XWikiDocument) source;
    XWikiContext context = (XWikiContext) data;
    // anything in the database)
    if (context.getWiki().isReadOnly()) {
        return;
    }
    // Initialize cookie used as unique identifier of a user visit and put it in the context
    StatsUtil.findCookie(context);
    String action = actionEvent.getActionName();
    // Let's save in the session the last elements view, saved
    synchronized (this) {
        if (!action.equals(DownloadAction.ACTION_NAME)) {
            Collection actions = StatsUtil.getRecentActionFromSessions(context, action);
            if (actions == null) {
                actions = new CircularFifoQueue(StatsUtil.getRecentVisitSize(context));
                StatsUtil.setRecentActionsFromSession(context, action, actions);
            }
            String element = document.getPrefixedFullName();
            if (actions.contains(element)) {
                actions.remove(element);
            }
            actions.add(element);
        }
    }
    try {
        if (StatsUtil.isWikiStatsEnabled(context) && !StatsUtil.getStorageFilteredUsers(context).contains(this.currentDocumentReferenceResolver.resolve(context.getUser()))) {
            this.statsRegister.addStats(document, action, context);
        }
    } catch (Exception e) {
        LOGGER.error("Faild to get filter users list", e);
    }
}
Also used : CircularFifoQueue(org.apache.commons.collections4.queue.CircularFifoQueue) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) Collection(java.util.Collection) XWikiException(com.xpn.xwiki.XWikiException) RemoteObservationManagerContext(org.xwiki.observation.remote.RemoteObservationManagerContext)

Aggregations

ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)32 Test (org.junit.Test)25 ActionExecutingEvent (org.xwiki.bridge.event.ActionExecutingEvent)9 XWikiContext (com.xpn.xwiki.XWikiContext)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 XWikiException (com.xpn.xwiki.XWikiException)3 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)3 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)3 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)3 ArrayList (java.util.ArrayList)2 DocumentCreatingEvent (org.xwiki.bridge.event.DocumentCreatingEvent)2 DocumentDeletingEvent (org.xwiki.bridge.event.DocumentDeletingEvent)2 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)2 XWiki (com.xpn.xwiki.XWiki)1 MonitorPlugin (com.xpn.xwiki.monitor.api.MonitorPlugin)1 XWikiNotificationManager (com.xpn.xwiki.notify.XWikiNotificationManager)1 FileUploadPlugin (com.xpn.xwiki.plugin.fileupload.FileUploadPlugin)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 ServletException (javax.servlet.ServletException)1