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