Search in sources :

Example 51 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultNotificationManagerTest method getEventsCount.

@Test
public void getEventsCount() throws Exception {
    // Mocks
    Event event1 = createMockedEvent();
    Event event2 = createMockedEvent();
    Event event3 = createMockedEvent();
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event1, event2, event1, event2, event2, event2, event1, event2, event2, event2), Arrays.asList(event1, event2, event2, event1, event3));
    // Test
    long result = mocker.getComponentUnderTest().getEventsCount("xwiki:XWiki.UserA", 5);
    // Verify
    assertEquals(5, result);
    verifyZeroInteractions(event3);
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) Test(org.junit.Test)

Example 52 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultNotificationManagerTest method getEventsUC5.

@Test
public void getEventsUC5() throws Exception {
    // Facts:
    // * Bob updates the page "Bike"
    // * Then Bob updates the page "Bike" again
    // Expected:
    // * Bob has updated the page "Bike"
    // Comment: we don't show 2 events, only one is interesting
    // Mocks
    Event event1 = createMockedEvent();
    Event event2 = createMockedEvent();
    DocumentReference doc = new DocumentReference("xwiki", "Main", "Bike");
    when(event1.getDocument()).thenReturn(doc);
    when(event2.getDocument()).thenReturn(doc);
    when(authorizationManager.hasAccess(Right.VIEW, userReference, doc)).thenReturn(true);
    when(event1.getType()).thenReturn("update");
    when(event2.getType()).thenReturn("update");
    when(event1.getGroupId()).thenReturn("g1");
    when(event2.getGroupId()).thenReturn("g2");
    when(eventStream.searchEvents(query)).thenReturn(Arrays.asList(event1, event2));
    // Test
    List<CompositeEvent> results = mocker.getComponentUnderTest().getEvents("xwiki:XWiki.UserA", 5);
    // Verify
    assertEquals(1, results.size());
    assertEquals(event1, results.get(0).getEvents().get(0));
    assertEquals(event2, results.get(0).getEvents().get(1));
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 53 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultNotificationManagerTest method createMockedEvent.

private Event createMockedEvent() {
    Event event = mock(Event.class);
    when(event.getDate()).thenReturn(new Date(1L));
    return event;
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) Date(java.util.Date)

Example 54 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultNotificationManager method getBestSimilarity.

private BestSimilarity getBestSimilarity(List<CompositeEvent> results, Event event) {
    BestSimilarity bestSimilarity = new BestSimilarity();
    // Looking for the most similar event inside the existing composite events
    for (CompositeEvent existingCompositeEvent : results) {
        for (Event existingEvent : existingCompositeEvent.getEvents()) {
            int similarity = similarityCalculator.computeSimilarity(event, existingEvent);
            if (similarity < existingCompositeEvent.getSimilarityBetweenEvents()) {
                // Penality
                similarity -= 5;
            }
            if (similarity > bestSimilarity.value) {
                bestSimilarity.value = similarity;
                bestSimilarity.event = existingEvent;
                bestSimilarity.compositeEvent = existingCompositeEvent;
            }
        }
    }
    return bestSimilarity;
}
Also used : CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent)

Example 55 with Event

use of org.xwiki.eventstream.Event in project xwiki-platform by xwiki.

the class DefaultCompositeEventStatusManager method getCompositeEventStatuses.

@Override
public List<CompositeEventStatus> getCompositeEventStatuses(List<CompositeEvent> compositeEvents, String entityId) throws Exception {
    // Creating a list of all events to avoid multiple calls to getEventStatuses() and so multiple calls to the
    // database.
    List<Event> allEvents = new ArrayList<>();
    // But maintain a mapping between eventId and their composite event status
    Map<String, CompositeEventStatus> map = new HashMap<>();
    for (CompositeEvent compositeEvent : compositeEvents) {
        CompositeEventStatus compositeEventStatus = new CompositeEventStatus(compositeEvent);
        for (Event event : compositeEvent.getEvents()) {
            map.put(event.getId(), compositeEventStatus);
        }
        allEvents.addAll(compositeEvent.getEvents());
    }
    // Put the event statuses into the composite events statuses
    for (EventStatus eventStatus : getEventStatuses(allEvents, entityId)) {
        map.get(eventStatus.getEvent().getId()).add(eventStatus);
    }
    List<CompositeEventStatus> results = new ArrayList<>();
    // Keep the same order than inputs
    for (CompositeEvent event : compositeEvents) {
        results.add(map.get(event.getEvents().get(0).getId()));
    }
    return results;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus) EventStatus(org.xwiki.eventstream.EventStatus) CompositeEvent(org.xwiki.notifications.CompositeEvent) Event(org.xwiki.eventstream.Event) CompositeEvent(org.xwiki.notifications.CompositeEvent) CompositeEventStatus(org.xwiki.notifications.CompositeEventStatus)

Aggregations

Event (org.xwiki.eventstream.Event)60 Test (org.junit.Test)31 DocumentReference (org.xwiki.model.reference.DocumentReference)21 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)20 CompositeEvent (org.xwiki.notifications.CompositeEvent)17 ArrayList (java.util.ArrayList)7 Query (org.xwiki.query.Query)7 Date (java.util.Date)6 Expectations (org.jmock.Expectations)6 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)5 QueryException (org.xwiki.query.QueryException)5 ObjectReference (org.xwiki.model.reference.ObjectReference)4 HashMap (java.util.HashMap)3 WikiReference (org.xwiki.model.reference.WikiReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)2 EventStatus (org.xwiki.eventstream.EventStatus)2 EventStream (org.xwiki.eventstream.EventStream)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2