use of org.xwiki.notifications.CompositeEvent 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;
}
use of org.xwiki.notifications.CompositeEvent in project xwiki-platform by xwiki.
the class DefaultNotificationRSSRendererTest method mockEvent.
private void mockEvent(CompositeEvent testCompositeEvent) throws Exception {
Event testEvent1 = mock(Event.class);
Date testEventDate = mock(Date.class);
when(testEvent1.getTitle()).thenReturn("EventTitle");
when(testEvent1.getDocumentTitle()).thenReturn("EventDocumentTitle");
when(this.contextualLocalizationManager.getTranslationPlain("EventTitle", "EventDocumentTitle")).thenReturn("TranslatedEventTitle");
DocumentReference testEventAuthor1 = new DocumentReference("xwiki", "XWiki", "AuthorName");
when(this.templateManager.getTemplate(ArgumentMatchers.any())).thenReturn(Mockito.mock(Template.class));
when(testCompositeEvent.getEvents()).thenReturn(Arrays.asList(testEvent1));
when(testCompositeEvent.getUsers()).thenReturn(new HashSet<>(Arrays.asList(testEventAuthor1)));
when(testCompositeEvent.getEventIds()).thenReturn(Arrays.asList("id1"));
when(testCompositeEvent.getType()).thenReturn("eventType");
when(testCompositeEvent.getDates()).thenReturn(Arrays.asList(testEventDate));
}
use of org.xwiki.notifications.CompositeEvent in project xwiki-platform by xwiki.
the class LiveNotificationEmailSenderTest method testSendMail.
@Test
public void testSendMail() throws Exception {
CompositeEvent event1 = mock(CompositeEvent.class);
when(this.wikiDescriptorManager.getCurrentWikiId()).thenReturn("xwiki");
when(this.notificationUserIteratorProvider.get()).thenReturn(Mockito.mock(NotificationUserIterator.class));
when(this.liveMimeMessageIteratorProvider.get()).thenReturn(Mockito.mock(LiveMimeMessageIterator.class));
when(this.sessionFactory.create(ArgumentMatchers.any())).thenReturn(null);
when(this.mailListenerProvider.get()).thenReturn(Mockito.mock(MailListener.class));
this.mocker.getComponentUnderTest().sendEmails(event1);
verify(this.mailSender, times(1)).sendAsynchronously(any(LiveMimeMessageIterator.class), any(), any(MailListener.class));
}
Aggregations